diff --git a/src/ui/tab.rs b/src/ui/tab.rs index 3a9bf344..7437fff0 100644 --- a/src/ui/tab.rs +++ b/src/ui/tab.rs @@ -98,14 +98,14 @@ impl<'a> Tab<'a> { } pub fn activate_next_widget(&mut self) { - self.mouse_over_widget_index = None; + self.clear_mouse_over(); self.active_widget_index = (self.active_widget_index + 1) % self.activatable_widget_indices.len(); } pub fn activate_prev_widget(&mut self) { - self.mouse_over_widget_index = None; + self.clear_mouse_over(); let activatable_widget_len = self.activatable_widget_indices.len(); @@ -139,12 +139,16 @@ impl<'a> Tab<'a> { .enumerate() .find(|(_, w)| w.widget.id() == id) { - self.mouse_over_widget_index = None; + self.clear_mouse_over(); self.active_widget_index = index; } } + pub fn clear_mouse_over(&mut self) { + self.mouse_over_widget_index = None; + } + pub fn find_widget(&self, id: &str) -> Option<&Widget<'a>> { self.widgets.iter().find_map(|w| { if w.widget.id() == id { diff --git a/src/ui/widget/complex/multiple_select.rs b/src/ui/widget/complex/multiple_select.rs index daea1b1c..e4b648c8 100644 --- a/src/ui/widget/complex/multiple_select.rs +++ b/src/ui/widget/complex/multiple_select.rs @@ -375,7 +375,7 @@ impl<'a> SelectForm<'a> { } fn toggle_active_form(&mut self) { - self.mouse_over_widget_index = None; + self.clear_mouse_over(); if self.active_form_index == LIST_FORM_ID { self.active_form_index = SELECTED_FORM_ID @@ -385,7 +385,7 @@ impl<'a> SelectForm<'a> { } fn activate_form_by_index(&mut self, index: usize) { - self.mouse_over_widget_index = None; + self.clear_mouse_over(); self.active_form_index = index; } @@ -503,10 +503,14 @@ impl<'a> SelectForm<'a> { } fn on_key_event(&mut self, ev: KeyEvent) -> EventResult { - self.mouse_over_widget_index = None; + self.clear_mouse_over(); self.active_form_mut().on_key_event(ev) } + + fn clear_mouse_over(&mut self) { + self.mouse_over_widget_index = None; + } } type RenderBlockInjection = Rc Block<'static>>; @@ -722,6 +726,10 @@ impl<'a> MultipleSelect<'a> { pub fn select_all(&mut self) { self.selected_widget.select_all(); } + + pub fn clear_mouse_over(&mut self) { + self.selected_widget.clear_mouse_over(); + } } impl WidgetTrait for MultipleSelect<'_> { diff --git a/src/ui/window.rs b/src/ui/window.rs index 385d75df..d4d0e08b 100644 --- a/src/ui/window.rs +++ b/src/ui/window.rs @@ -347,6 +347,10 @@ impl<'a> Window<'a> { pub fn activate_widget_by_id(&mut self, id: &str) { self.active_tab_mut().activate_widget_by_id(id) } + + pub fn clear_mouse_over(&mut self) { + self.mouse_over_tab_index = None; + } } // Render @@ -416,18 +420,36 @@ impl Window<'_> { UserEvent::Key(ev) => self.on_key_event(ev), UserEvent::Mouse(ev) => self.on_mouse_event(ev), UserEvent::FocusLost => { - self.mouse_over_tab_index = None; + self.clear_mouse_over(); + self.active_tab_mut().clear_mouse_over(); + + if let Some(id) = &self.open_popup_id { + if let Some(Widget::MultipleSelect(w)) = + self.popups.iter_mut().find(|w| w.id() == id) + { + w.clear_mouse_over(); + } + } EventResult::Nop } UserEvent::FocusGained => { - self.mouse_over_tab_index = None; + self.clear_mouse_over(); + self.active_tab_mut().clear_mouse_over(); + if let Some(id) = &self.open_popup_id { + if let Some(Widget::MultipleSelect(w)) = + self.popups.iter_mut().find(|w| w.id() == id) + { + w.clear_mouse_over(); + } + } + EventResult::Nop } } } pub fn on_key_event(&mut self, ev: KeyEvent) -> EventResult { - self.mouse_over_tab_index = None; + self.clear_mouse_over(); if let Some(id) = &self.open_popup_id { if let Some(popup) = self.popups.iter_mut().find(|w| w.id() == id) { @@ -490,12 +512,12 @@ impl Window<'_> { EventResult::Nop } AreaKind::Widgets => { - self.mouse_over_tab_index = None; + self.clear_mouse_over(); self.active_tab_mut().on_mouse_event(ev) } AreaKind::OutSide => { - self.mouse_over_tab_index = None; + self.clear_mouse_over(); EventResult::Ignore }