Skip to main content

ferroui_controls/
selection_changed_event_args.rs

1use ferroui_base::interactivity::{RoutedEvent, RoutedEventArgs};
2use ferroui_base::{ferro_routed_event_args, BoxedValue};
3
4/// Provides data for the `SelectionChanged` event.
5#[derive(Clone, Default)]
6pub struct SelectionChangedEventArgs {
7    base: RoutedEventArgs,
8    added_items: Vec<Option<BoxedValue>>,
9    removed_items: Vec<Option<BoxedValue>>,
10}
11
12ferro_routed_event_args!(SelectionChangedEventArgs: RoutedEventArgs);
13
14impl SelectionChangedEventArgs {
15    /// Initializes a new instance of the [`SelectionChangedEventArgs`]
16    /// class.
17    ///
18    /// `routed_event` is the event being raised, `removed_items` the items
19    /// removed from the selection and `added_items` the items added to the
20    /// selection.
21    pub fn new<T: ?Sized>(
22        routed_event: Option<&RoutedEvent<T>>,
23        removed_items: Vec<Option<BoxedValue>>,
24        added_items: Vec<Option<BoxedValue>>,
25    ) -> Self {
26        let base = match routed_event {
27            Some(routed_event) => RoutedEventArgs::with_event(routed_event),
28            None => RoutedEventArgs::new(),
29        };
30        Self { base, added_items, removed_items }
31    }
32
33    /// Gets the items that were added to the selection.
34    pub fn added_items(&self) -> &[Option<BoxedValue>] {
35        &self.added_items
36    }
37
38    /// Gets the items that were removed from the selection.
39    pub fn removed_items(&self) -> &[Option<BoxedValue>] {
40        &self.removed_items
41    }
42}