summaryrefslogtreecommitdiffstats
path: root/src/components/utilities
diff options
context:
space:
mode:
authorManos Pitsidianakis <el13635@mail.ntua.gr>2020-10-10 17:53:53 +0300
committerManos Pitsidianakis <el13635@mail.ntua.gr>2020-10-11 16:53:04 +0300
commit0ca7b0042e158d5173b5fa26662fab6361c39955 (patch)
treee8227c912cfe0eaaaa38abaabc6102423ea32b69 /src/components/utilities
parent406af1848f01c2e5fe4ab3748ce934199190b827 (diff)
utilities: ensure Form/Button widgets are not always non-dirty
Diffstat (limited to 'src/components/utilities')
-rw-r--r--src/components/utilities/widgets.rs50
1 files changed, 37 insertions, 13 deletions
diff --git a/src/components/utilities/widgets.rs b/src/components/utilities/widgets.rs
index b9167c60..045e6d80 100644
--- a/src/components/utilities/widgets.rs
+++ b/src/components/utilities/widgets.rs
@@ -337,6 +337,7 @@ impl FormWidget {
pub fn hide_buttons(&mut self) {
self.hide_buttons = true;
+ self.buttons.set_dirty(false);
}
pub fn len(&self) -> usize {
@@ -499,9 +500,9 @@ impl Component for FormWidget {
),
theme_default,
);
- self.dirty = false;
+ self.set_dirty(false);
+ context.dirty_areas.push_back(area);
}
- context.dirty_areas.push_back(area);
}
fn process_event(&mut self, event: &mut UIEvent, context: &mut Context) -> bool {
if self.focus == FormFocus::Buttons && self.buttons.process_event(event, context) {
@@ -512,42 +513,59 @@ impl Component for FormWidget {
UIEvent::Input(Key::Up) if self.focus == FormFocus::Buttons => {
self.focus = FormFocus::Fields;
self.buttons.set_focus(false);
+ self.set_dirty(true);
+ return true;
}
UIEvent::InsertInput(Key::Up) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
field.process_event(event, context);
+ self.set_dirty(true);
+ return true;
}
UIEvent::Input(Key::Up) => {
self.cursor = self.cursor.saturating_sub(1);
+ self.set_dirty(true);
+ return true;
}
UIEvent::InsertInput(Key::Down) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
field.process_event(event, context);
+ self.set_dirty(true);
+ return true;
}
UIEvent::Input(Key::Down) if self.cursor < self.layout.len().saturating_sub(1) => {
self.cursor += 1;
+ self.set_dirty(true);
+ return true;
}
UIEvent::Input(Key::Down) if self.focus == FormFocus::Fields => {
self.focus = FormFocus::Buttons;
self.buttons.set_focus(true);
+ self.set_dirty(true);
if self.hide_buttons {
- self.set_dirty(true);
return false;
}
+ return true;
}
UIEvent::InsertInput(Key::Char('\t')) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
field.process_event(event, context);
+ self.set_dirty(true);
+ return true;
}
UIEvent::Input(Key::Char('\n')) if self.focus == FormFocus::Fields => {
self.focus = FormFocus::TextInput;
context
.replies
.push_back(UIEvent::ChangeMode(UIMode::Insert));
+ self.set_dirty(true);
+ return true;
}
UIEvent::InsertInput(Key::Right) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
field.process_event(event, context);
+ self.set_dirty(true);
+ return true;
}
UIEvent::InsertInput(Key::Left) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
@@ -557,6 +575,8 @@ impl Component for FormWidget {
.replies
.push_back(UIEvent::ChangeMode(UIMode::Normal));
}
+ self.set_dirty(true);
+ return true;
}
UIEvent::ChangeMode(UIMode::Normal) if self.focus == FormFocus::TextInput => {
self.focus = FormFocus::Fields;
@@ -565,17 +585,18 @@ impl Component for FormWidget {
UIEvent::InsertInput(Key::Backspace) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
field.process_event(event, context);
+ self.set_dirty(true);
+ return true;
}
UIEvent::InsertInput(_) if self.focus == FormFocus::TextInput => {
let field = self.fields.get_mut(&self.layout[self.cursor]).unwrap();
field.process_event(event, context);
+ self.set_dirty(true);
+ return true;
}
- _ => {
- return false;
- }
+ _ => {}
}
- self.set_dirty(true);
- true
+ false
}
fn is_dirty(&self) -> bool {
self.dirty || self.buttons.is_dirty()
@@ -690,19 +711,22 @@ where
.remove(&self.layout[self.cursor])
.unwrap_or_default(),
);
+ self.set_dirty(true);
+ return true;
}
UIEvent::Input(Key::Left) => {
self.cursor = self.cursor.saturating_sub(1);
+ self.set_dirty(true);
+ return true;
}
UIEvent::Input(Key::Right) if self.cursor < self.layout.len().saturating_sub(1) => {
self.cursor += 1;
+ self.set_dirty(true);
+ return true;
}
- _ => {
- return false;
- }
+ _ => {}
}
- self.set_dirty(true);
- true
+ false
}
fn is_dirty(&self) -> bool {
self.dirty