Reject events for disabled views

This commit is contained in:
Alexandre Bury 2020-06-18 09:40:45 -07:00
parent bb98be1132
commit 55c4aa2716
6 changed files with 22 additions and 0 deletions

View File

@ -160,6 +160,10 @@ impl View for Button {
} }
fn on_event(&mut self, event: Event) -> EventResult { fn on_event(&mut self, event: Event) -> EventResult {
if !self.enabled {
return EventResult::Ignored;
}
// eprintln!("{:?}", event); // eprintln!("{:?}", event);
// eprintln!("{:?}", self.req_size()); // eprintln!("{:?}", self.req_size());
let width = self.label.width(); let width = self.label.width();

View File

@ -158,6 +158,9 @@ impl View for Checkbox {
} }
fn on_event(&mut self, event: Event) -> EventResult { fn on_event(&mut self, event: Event) -> EventResult {
if !self.enabled {
return EventResult::Ignored;
}
match event { match event {
Event::Key(Key::Enter) | Event::Char(' ') => self.toggle(), Event::Key(Key::Enter) | Event::Char(' ') => self.toggle(),
Event::Mouse { Event::Mouse {

View File

@ -598,6 +598,9 @@ impl View for EditView {
} }
fn on_event(&mut self, event: Event) -> EventResult { fn on_event(&mut self, event: Event) -> EventResult {
if !self.enabled {
return EventResult::Ignored;
}
match event { match event {
Event::Char(ch) => { Event::Char(ch) => {
return EventResult::Consumed(Some(self.insert(ch))); return EventResult::Consumed(Some(self.insert(ch)));

View File

@ -209,6 +209,10 @@ impl<T: 'static> View for RadioButton<T> {
} }
fn on_event(&mut self, event: Event) -> EventResult { fn on_event(&mut self, event: Event) -> EventResult {
if !self.enabled() {
return EventResult::Ignored;
}
match event { match event {
Event::Key(Key::Enter) | Event::Char(' ') => self.select(), Event::Key(Key::Enter) | Event::Char(' ') => self.select(),
Event::Mouse { Event::Mouse {

View File

@ -954,6 +954,10 @@ impl<T: 'static> View for SelectView<T> {
} }
fn on_event(&mut self, event: Event) -> EventResult { fn on_event(&mut self, event: Event) -> EventResult {
if !self.enabled {
return EventResult::Ignored;
}
if self.popup { if self.popup {
self.on_event_popup(event) self.on_event_popup(event)
} else { } else {

View File

@ -527,6 +527,10 @@ impl View for TextArea {
} }
fn on_event(&mut self, event: Event) -> EventResult { fn on_event(&mut self, event: Event) -> EventResult {
if !self.enabled {
return EventResult::Ignored;
}
let mut fix_scroll = true; let mut fix_scroll = true;
match event { match event {
Event::Char(ch) => self.insert(ch), Event::Char(ch) => self.insert(ch),