fix: Only re-draw the screen if data/layout has changed

This commit is contained in:
Jack Wills
2025-02-21 16:40:34 +00:00
parent 53625e67cb
commit bfc295c50e
9 changed files with 184 additions and 49 deletions
+25
View File
@@ -0,0 +1,25 @@
use std::sync::atomic::{AtomicBool, Ordering};
#[derive(Debug)]
pub struct Redraw(AtomicBool);
impl Redraw {
pub const fn new() -> Self {
Self(AtomicBool::new(true))
}
pub fn set_true(&self) {
self.0.store(true, Ordering::SeqCst);
}
/// Return the value of the self, and set to false
pub fn swap(&self) -> bool {
match self
.0
.compare_exchange(true, false, Ordering::SeqCst, Ordering::SeqCst)
{
Ok(previous_value) => previous_value,
Err(current_value) => current_value,
}
}
}