pub struct Modal { /* private fields */ }Expand description
A modal dialog widget
Implementations§
Source§impl Modal
impl Modal
Set buttons
Sourcepub fn yes_no_cancel(self) -> Self
pub fn yes_no_cancel(self) -> Self
Add Yes, No, and Cancel buttons
Sourcepub fn body(self, widget: impl View + 'static) -> Self
pub fn body(self, widget: impl View + 'static) -> Self
Set a child widget as body content
When a body widget is set, it takes precedence over text content. The widget will be rendered inside the modal’s content area.
§Example
use revue::prelude::*;
let modal = Modal::new()
.title("User Form")
.body(
vstack()
.gap(1)
.child(Input::new().placeholder("Name"))
.child(Input::new().placeholder("Email"))
)
.ok_cancel();Sourcepub fn show_with_focus_trap(
&mut self,
fm: &mut FocusManager,
container_id: u64,
button_ids: &[u64],
)
pub fn show_with_focus_trap( &mut self, fm: &mut FocusManager, container_id: u64, button_ids: &[u64], )
Show the modal and activate focus trapping
Traps keyboard focus within the modal’s buttons so Tab/Shift+Tab only cycles between modal buttons and doesn’t escape to background widgets.
§Arguments
fm- The focus manager to trap focus incontainer_id- Unique ID for this modal’s focus trap containerbutton_ids- Widget IDs for each button (must match button count)
Sourcepub fn hide_with_focus_restore(&mut self, fm: &mut FocusManager)
pub fn hide_with_focus_restore(&mut self, fm: &mut FocusManager)
Hide the modal and release focus trapping
Releases the focus trap and restores focus to the previously focused widget.
Sourcepub fn has_focus_trap(&self) -> bool
pub fn has_focus_trap(&self) -> bool
Check if this modal has an active focus trap
Sourcepub fn is_visible(&self) -> bool
pub fn is_visible(&self) -> bool
Check if modal is visible
Get selected button index
Select next button
Select previous button
Sourcepub fn handle_key(&mut self, key: &Key) -> Option<usize>
pub fn handle_key(&mut self, key: &Key) -> Option<usize>
Handle key input, returns Some(button_index) if button confirmed
Sourcepub fn handle_key_with_focus(
&mut self,
key: &Key,
fm: &mut FocusManager,
) -> Option<usize>
pub fn handle_key_with_focus( &mut self, key: &Key, fm: &mut FocusManager, ) -> Option<usize>
Handle key input with focus manager integration
Like handle_key, but also releases the focus trap on Escape
or when a button is confirmed.