Skip to main content

ferroui_controls/
request_bring_into_view_event_args.rs

1use std::cell::Cell;
2use std::rc::Rc;
3
4use ferroui_base::interactivity::{RoutedEvent, RoutedEventArgs};
5use ferroui_base::{ferro_routed_event_args, Rect, Ref, Visual};
6
7/// Provides data for the `RequestBringIntoView` event.
8#[derive(Clone, Default)]
9pub struct RequestBringIntoViewEventArgs {
10    base: RoutedEventArgs,
11    /// The target object that should be brought into view.
12    pub target_object: Option<Ref<Visual>>,
13    target_rect: Rc<Cell<Rect>>,
14}
15
16ferro_routed_event_args!(RequestBringIntoViewEventArgs: RoutedEventArgs);
17
18impl RequestBringIntoViewEventArgs {
19    /// Creates args with no routed event.
20    pub fn new() -> Self {
21        Self::default()
22    }
23
24    /// Creates args for a routed event.
25    pub fn with_event<T: ?Sized>(routed_event: &RoutedEvent<T>) -> Self {
26        Self { base: RoutedEventArgs::with_event(routed_event), ..Self::default() }
27    }
28
29    /// The rectangle in the target object's coordinate space that should be
30    /// brought into view.
31    pub fn target_rect(&self) -> Rect {
32        self.target_rect.get()
33    }
34
35    /// Sets the rectangle in the target object's coordinate space that should
36    /// be brought into view. Handlers may adjust it while the event routes.
37    pub fn set_target_rect(&self, value: Rect) {
38        self.target_rect.set(value)
39    }
40}