summaryrefslogtreecommitdiffstats
path: root/ui/src/components/utilities/widgets.rs
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-25 23:14:24 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2019-09-26 13:11:49 +0300
commit91ae539de1730d735f6137f36e2f5da57225cfce (patch)
tree01a385311fa33f18d63a27d9e599a10a3cab59db /ui/src/components/utilities/widgets.rs
parentf27b815aa79e234c299a4a1255c7f001ec68e1cd (diff)
Small fixes
Diffstat (limited to 'ui/src/components/utilities/widgets.rs')
-rw-r--r--ui/src/components/utilities/widgets.rs70
1 files changed, 38 insertions, 32 deletions
diff --git a/ui/src/components/utilities/widgets.rs b/ui/src/components/utilities/widgets.rs
index 387fd906..749e63fa 100644
--- a/ui/src/components/utilities/widgets.rs
+++ b/ui/src/components/utilities/widgets.rs
@@ -195,7 +195,7 @@ impl Component for Field {
true
}
fn is_dirty(&self) -> bool {
- true
+ false
}
fn set_dirty(&mut self) {}
@@ -477,6 +477,7 @@ where
result: Option<T>,
cursor: usize,
+ dirty: bool,
id: ComponentId,
}
@@ -499,6 +500,7 @@ where
buttons: vec![init_val].into_iter().collect(),
result: None,
cursor: 0,
+ dirty: true,
id: ComponentId::new_v4(),
}
}
@@ -518,28 +520,31 @@ where
T: std::fmt::Debug + Default + Send,
{
fn draw(&mut self, grid: &mut CellBuffer, area: Area, _context: &mut Context) {
- let upper_left = upper_left!(area);
-
- let mut len = 0;
- for (i, k) in self.layout.iter().enumerate() {
- let cur_len = k.len();
- write_string_to_grid(
- k.as_str(),
- grid,
- Color::Default,
- if i == self.cursor {
- Color::Byte(246)
- } else {
- Color::Default
- },
- Attr::Default,
- (
- pos_inc(upper_left, (len, 0)),
- pos_inc(upper_left, (cur_len + len, 0)),
- ),
- false,
- );
- len += cur_len + 3;
+ if self.dirty {
+ let upper_left = upper_left!(area);
+
+ let mut len = 0;
+ for (i, k) in self.layout.iter().enumerate() {
+ let cur_len = k.len();
+ write_string_to_grid(
+ k.as_str(),
+ grid,
+ Color::Default,
+ if i == self.cursor {
+ Color::Byte(246)
+ } else {
+ Color::Default
+ },
+ Attr::Default,
+ (
+ pos_inc(upper_left, (len, 0)),
+ pos_inc(upper_left, (cur_len + len, 0)),
+ ),
+ false,
+ );
+ len += cur_len + 3;
+ }
+ self.dirty = false;
}
}
fn process_event(&mut self, event: &mut UIEvent, _context: &mut Context) -> bool {
@@ -550,25 +555,26 @@ where
.remove(&self.layout[self.cursor])
.unwrap_or_default(),
);
- return true;
}
UIEvent::Input(Key::Left) => {
self.cursor = self.cursor.saturating_sub(1);
- return true;
}
UIEvent::Input(Key::Right) if self.cursor < self.layout.len().saturating_sub(1) => {
self.cursor += 1;
- return true;
}
- _ => {}
+ _ => {
+ return false;
+ }
}
-
- false
+ self.set_dirty();
+ true
}
fn is_dirty(&self) -> bool {
- true
+ self.dirty
+ }
+ fn set_dirty(&mut self) {
+ self.dirty = true;
}
- fn set_dirty(&mut self) {}
fn id(&self) -> ComponentId {
self.id
@@ -695,7 +701,7 @@ impl AutoComplete {
pub fn set_suggestions(&mut self, entries: Vec<AutoCompleteEntry>) -> bool {
if entries.len() == self.entries.len() && entries == self.entries {
- return false;;
+ return false;
}
let mut content = CellBuffer::new(