pub struct ModalFocusIntegration<'a> { /* private fields */ }Expand description
Helper for integrating ModalStack with FocusManager.
This struct provides a convenient API for:
- Pushing modals with automatic focus trap setup
- Popping modals with focus restoration
- Managing focus groups for nested modals
§Example
use ftui_widgets::modal::{ModalStack, ModalFocusIntegration};
use ftui_widgets::focus::FocusManager;
let mut stack = ModalStack::new();
let mut focus = FocusManager::new();
let mut integrator = ModalFocusIntegration::new(&mut stack, &mut focus);
// Push a modal with focus management
let modal_id = integrator.push_with_focus(dialog);
// ... handle events ...
// Pop modal and restore focus
integrator.pop_with_focus();Implementations§
Source§impl<'a> ModalFocusIntegration<'a>
impl<'a> ModalFocusIntegration<'a>
Sourcepub fn new(stack: &'a mut ModalStack, focus: &'a mut FocusManager) -> Self
pub fn new(stack: &'a mut ModalStack, focus: &'a mut FocusManager) -> Self
Create a new integration helper.
Sourcepub fn push_with_focus(&mut self, modal: Box<dyn StackModal>) -> ModalId
pub fn push_with_focus(&mut self, modal: Box<dyn StackModal>) -> ModalId
Push a modal with automatic focus management.
- Creates a focus group from
modal.focusable_ids()(if provided) - Pushes a focus trap to constrain Tab navigation
- Auto-focuses the first focusable widget
- Stores the previous focus for restoration on close
Returns the modal ID.
Sourcepub fn pop_with_focus(&mut self) -> Option<ModalResult>
pub fn pop_with_focus(&mut self) -> Option<ModalResult>
Pop the top modal with focus restoration.
If the modal had a focus group, the trap is popped and focus is restored to the element that was focused before the modal opened.
Returns the modal result.
Sourcepub fn handle_event(&mut self, event: &Event) -> Option<ModalResult>
pub fn handle_event(&mut self, event: &Event) -> Option<ModalResult>
Handle an event with automatic focus trap popping.
If the event causes the modal to close, the focus trap is popped.
Sourcepub fn is_focus_trapped(&self) -> bool
pub fn is_focus_trapped(&self) -> bool
Check if focus is currently trapped in a modal.
Sourcepub fn stack(&self) -> &ModalStack
pub fn stack(&self) -> &ModalStack
Get a reference to the underlying modal stack.
Sourcepub fn stack_mut(&mut self) -> &mut ModalStack
pub fn stack_mut(&mut self) -> &mut ModalStack
Get a mutable reference to the underlying modal stack.
Sourcepub fn focus(&self) -> &FocusManager
pub fn focus(&self) -> &FocusManager
Get a reference to the underlying focus manager.
Sourcepub fn focus_mut(&mut self) -> &mut FocusManager
pub fn focus_mut(&mut self) -> &mut FocusManager
Get a mutable reference to the underlying focus manager.