105 lines
2.6 KiB
Rust
105 lines
2.6 KiB
Rust
use std::time::{Duration, Instant};
|
|
|
|
use cagire_ratatui::Sparkles;
|
|
|
|
use crate::state::Modal;
|
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
pub enum FlashKind {
|
|
#[default]
|
|
Success,
|
|
Error,
|
|
Info,
|
|
}
|
|
|
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
|
pub enum DictFocus {
|
|
#[default]
|
|
Categories,
|
|
Words,
|
|
}
|
|
|
|
pub struct UiState {
|
|
pub sparkles: Sparkles,
|
|
pub status_message: Option<String>,
|
|
pub flash_until: Option<Instant>,
|
|
pub flash_kind: FlashKind,
|
|
pub modal: Modal,
|
|
pub help_topic: usize,
|
|
pub help_scrolls: Vec<usize>,
|
|
pub help_search_active: bool,
|
|
pub help_search_query: String,
|
|
pub dict_focus: DictFocus,
|
|
pub dict_category: usize,
|
|
pub dict_scroll: usize,
|
|
pub dict_search_query: String,
|
|
pub dict_search_active: bool,
|
|
pub show_title: bool,
|
|
pub runtime_highlight: bool,
|
|
pub show_completion: bool,
|
|
pub minimap_until: Option<Instant>,
|
|
}
|
|
|
|
impl Default for UiState {
|
|
fn default() -> Self {
|
|
Self {
|
|
sparkles: Sparkles::default(),
|
|
status_message: None,
|
|
flash_until: None,
|
|
flash_kind: FlashKind::Success,
|
|
modal: Modal::None,
|
|
help_topic: 0,
|
|
help_scrolls: vec![0; crate::views::help_view::topic_count()],
|
|
help_search_active: false,
|
|
help_search_query: String::new(),
|
|
dict_focus: DictFocus::default(),
|
|
dict_category: 0,
|
|
dict_scroll: 0,
|
|
dict_search_query: String::new(),
|
|
dict_search_active: false,
|
|
show_title: true,
|
|
runtime_highlight: false,
|
|
show_completion: true,
|
|
minimap_until: None,
|
|
}
|
|
}
|
|
}
|
|
|
|
impl UiState {
|
|
pub fn help_scroll(&self) -> usize {
|
|
self.help_scrolls[self.help_topic]
|
|
}
|
|
|
|
pub fn help_scroll_mut(&mut self) -> &mut usize {
|
|
&mut self.help_scrolls[self.help_topic]
|
|
}
|
|
|
|
pub fn flash(&mut self, msg: &str, duration_ms: u64, kind: FlashKind) {
|
|
self.status_message = Some(msg.to_string());
|
|
self.flash_until = Some(Instant::now() + Duration::from_millis(duration_ms));
|
|
self.flash_kind = kind;
|
|
}
|
|
|
|
pub fn flash_kind(&self) -> Option<FlashKind> {
|
|
if self.is_flashing() {
|
|
Some(self.flash_kind)
|
|
} else {
|
|
None
|
|
}
|
|
}
|
|
|
|
pub fn set_status(&mut self, msg: String) {
|
|
self.status_message = Some(msg);
|
|
}
|
|
|
|
pub fn clear_status(&mut self) {
|
|
self.status_message = None;
|
|
}
|
|
|
|
pub fn is_flashing(&self) -> bool {
|
|
self.flash_until
|
|
.map(|t| Instant::now() < t)
|
|
.unwrap_or(false)
|
|
}
|
|
}
|