94 lines
2.2 KiB
Rust
94 lines
2.2 KiB
Rust
use std::time::{Duration, Instant};
|
|
|
|
use crate::state::Modal;
|
|
|
|
#[derive(Debug, Clone, Copy, Default, PartialEq, Eq)]
|
|
pub enum FlashKind {
|
|
#[default]
|
|
Success,
|
|
Error,
|
|
Info,
|
|
}
|
|
|
|
pub struct Sparkle {
|
|
pub x: u16,
|
|
pub y: u16,
|
|
pub char_idx: usize,
|
|
pub life: u8,
|
|
}
|
|
|
|
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
|
|
pub enum DictFocus {
|
|
#[default]
|
|
Categories,
|
|
Words,
|
|
}
|
|
|
|
pub struct UiState {
|
|
pub sparkles: Vec<Sparkle>,
|
|
pub status_message: Option<String>,
|
|
pub flash_until: Option<Instant>,
|
|
pub flash_kind: FlashKind,
|
|
pub modal: Modal,
|
|
pub help_topic: usize,
|
|
pub help_scroll: usize,
|
|
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: Vec::new(),
|
|
status_message: None,
|
|
flash_until: None,
|
|
flash_kind: FlashKind::Success,
|
|
modal: Modal::None,
|
|
help_topic: 0,
|
|
help_scroll: 0,
|
|
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 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)
|
|
}
|
|
}
|