Init
This commit is contained in:
50
src/state/ui.rs
Normal file
50
src/state/ui.rs
Normal file
@@ -0,0 +1,50 @@
|
||||
use std::time::{Duration, Instant};
|
||||
|
||||
use crate::state::Modal;
|
||||
|
||||
pub struct UiState {
|
||||
pub status_message: Option<String>,
|
||||
pub flash_until: Option<Instant>,
|
||||
pub modal: Modal,
|
||||
pub doc_topic: usize,
|
||||
pub doc_scroll: usize,
|
||||
pub doc_category: usize,
|
||||
pub show_title: bool,
|
||||
pub runtime_highlight: bool,
|
||||
}
|
||||
|
||||
impl Default for UiState {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
status_message: None,
|
||||
flash_until: None,
|
||||
modal: Modal::None,
|
||||
doc_topic: 0,
|
||||
doc_scroll: 0,
|
||||
doc_category: 0,
|
||||
show_title: true,
|
||||
runtime_highlight: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl UiState {
|
||||
pub fn flash(&mut self, msg: &str, duration_ms: u64) {
|
||||
self.status_message = Some(msg.to_string());
|
||||
self.flash_until = Some(Instant::now() + Duration::from_millis(duration_ms));
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user