ferroui_base/input/i_focus_manager.rs
1use super::{FindNextElementOptions, InputElement, KeyModifiers, NavigationDirection, NavigationMethod};
2use crate::Ref;
3use std::any::Any;
4
5/// Manages focus for the application.
6pub trait IFocusManager {
7 /// Gets the currently focused element.
8 fn get_focused_element(&self) -> Option<Ref<InputElement>>;
9
10 /// Focuses a control.
11 ///
12 /// `element` is the control to focus; `None` clears the focus. `method`
13 /// is the method by which focus was changed and `key_modifiers` any key
14 /// modifiers active at the time of focus. Returns true if the focus
15 /// moved to a control.
16 fn focus(&self, element: Option<&Ref<InputElement>>, method: NavigationMethod, key_modifiers: KeyModifiers)
17 -> bool;
18
19 /// Attempts to change focus from the element with focus to the next
20 /// focusable element in the specified direction.
21 ///
22 /// `direction` must be one of next, previous, left, right, up and down.
23 /// `options` help identify the next element to receive focus. Returns
24 /// true if focus moved.
25 fn try_move_focus(&self, direction: NavigationDirection, options: Option<&FindNextElementOptions>) -> bool;
26
27 /// Retrieves the first element that can receive focus.
28 fn find_first_focusable_element(&self) -> Option<Ref<InputElement>>;
29
30 /// Retrieves the last element that can receive focus.
31 fn find_last_focusable_element(&self) -> Option<Ref<InputElement>>;
32
33 /// Retrieves the element that should receive focus based on the
34 /// specified navigation direction.
35 ///
36 /// `direction` must be one of next, previous, left, right, up and down.
37 /// `options` help identify the next element to receive focus.
38 fn find_next_element(
39 &self,
40 direction: NavigationDirection,
41 options: Option<&FindNextElementOptions>,
42 ) -> Option<Ref<InputElement>>;
43
44 /// The focus manager as [`Any`], for downcasting to the concrete type.
45 fn as_any(&self) -> &dyn Any;
46}