From 5166f6dbf06f911c5dcb21563274ca98285aca6c Mon Sep 17 00:00:00 2001 From: Joe Carstairs Date: Sun, 1 Feb 2026 21:01:48 +0000 Subject: Navigation::remove_options_where() --- .../src/gui/components/navigation.rs | 1 + .../navigation/navigation_remove_options.rs | 29 ++++++++++++++++++++++ 2 files changed, 30 insertions(+) create mode 100644 schist_desktop_gui/src/gui/components/navigation/navigation_remove_options.rs (limited to 'schist_desktop_gui/src/gui/components') 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 +where + TOption: Clone + PartialEq + 'a, + Element<'a, Message>: From<&'a TOption>, +{ + pub fn remove_options_where

(&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()); + } + } +} -- cgit v1.2.3