diff options
Diffstat (limited to 'schist_desktop_gui/src')
| -rw-r--r-- | schist_desktop_gui/src/gui/components/navigation.rs | 1 | ||||
| -rw-r--r-- | schist_desktop_gui/src/gui/components/navigation/navigation_remove_options.rs | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/schist_desktop_gui/src/gui/components/navigation.rs b/schist_desktop_gui/src/gui/components/navigation.rs index b7abda4..6fe100d 100644 --- a/schist_desktop_gui/src/gui/components/navigation.rs +++ b/schist_desktop_gui/src/gui/components/navigation.rs @@ -1,5 +1,6 @@ mod navigate_navigation; mod navigation_insert_options; +mod navigation_remove_options; mod navigation_replace_options; mod navigation_select_option; mod navigation_set_options; diff --git a/schist_desktop_gui/src/gui/components/navigation/navigation_remove_options.rs b/schist_desktop_gui/src/gui/components/navigation/navigation_remove_options.rs new file mode 100644 index 0000000..6320c99 --- /dev/null +++ b/schist_desktop_gui/src/gui/components/navigation/navigation_remove_options.rs @@ -0,0 +1,29 @@ +use iced::Element; + +use super::{Message, Navigation}; + +impl<'a, TOption> Navigation<TOption> +where + TOption: Clone + PartialEq + 'a, + Element<'a, Message<TOption>>: From<&'a TOption>, +{ + pub fn remove_options_where<P>(&mut self, pred: P) + where + P: Fn(&TOption) -> bool, + { + while let Some(index) = self.options_before_active.iter().position(&pred) { + self.options_before_active.remove(index); + } + + while let Some(index) = self.options_after_active.iter().position(&pred) { + self.options_after_active.remove(index); + } + + if self.active_option.as_ref().is_some_and(pred) { + self.active_option = self + .options_before_active + .pop() + .or_else(|| self.options_after_active.splice(0..1, Vec::new()).last()); + } + } +} |
