pub struct ModalScreen { /* private fields */ }Expand description
A screen that blocks all keyboard and mouse input to screens beneath it while it is on top of the screen stack.
ModalScreen is a transparent wrapper — it owns one inner widget that
becomes its only child. Size the inner widget with CSS (width, height,
margin, align) to position it on screen.
Input blocking is guaranteed by the framework: keyboard focus is always scoped to the top screen, and the mouse hit-map is built from the top screen only. Screens below a modal are frozen but not unmounted.
§Usage
Push a modal from any on_action handler using
AppContext::push_screen_deferred:
struct ConfirmDialog;
impl Widget for ConfirmDialog {
fn widget_type_name(&self) -> &'static str { "ConfirmDialog" }
fn render(&self, _ctx: &AppContext, _area: Rect, _buf: &mut Buffer) {}
fn on_action(&self, action: &str, ctx: &AppContext) {
if action == "ok" || action == "cancel" {
ctx.pop_screen_deferred(); // dismiss the modal
}
}
}
struct MainScreen;
impl Widget for MainScreen {
fn widget_type_name(&self) -> &'static str { "MainScreen" }
fn render(&self, _ctx: &AppContext, _area: Rect, _buf: &mut Buffer) {}
fn on_action(&self, action: &str, ctx: &AppContext) {
if action == "open_confirm" {
ctx.push_screen_deferred(Box::new(ModalScreen::new(Box::new(ConfirmDialog))));
}
}
}§Dismissing a modal
Call AppContext::pop_screen_deferred
from within the inner widget’s on_action. Focus automatically returns to
the widget that was focused before the modal was opened.
Implementations§
Trait Implementations§
Source§impl Widget for ModalScreen
impl Widget for ModalScreen
Source§fn compose(&self) -> Vec<Box<dyn Widget>>
fn compose(&self) -> Vec<Box<dyn Widget>>
Returns the inner widget as a child. Called once at mount time.
Source§fn widget_type_name(&self) -> &'static str
fn widget_type_name(&self) -> &'static str
Source§fn is_modal(&self) -> bool
fn is_modal(&self) -> bool
Source§fn on_mount(&self, id: WidgetId)
fn on_mount(&self, id: WidgetId)
Source§fn on_unmount(&self, _id: WidgetId)
fn on_unmount(&self, _id: WidgetId)
Source§fn render(&self, _ctx: &AppContext, _area: Rect, _buf: &mut Buffer)
fn render(&self, _ctx: &AppContext, _area: Rect, _buf: &mut Buffer)
Source§fn can_focus(&self) -> bool
fn can_focus(&self) -> bool
Source§fn classes(&self) -> &[&str]
fn classes(&self) -> &[&str]
&["primary", "active"]). Read moreSource§fn id(&self) -> Option<&str>
fn id(&self) -> Option<&str>
#id CSS selectors). Read moreSource§fn default_css() -> &'static strwhere
Self: Sized,
fn default_css() -> &'static strwhere
Self: Sized,
Source§fn widget_default_css(&self) -> &'static str
fn widget_default_css(&self) -> &'static str
default_css(). Override this alongside
default_css() to return the same value — this version is callable on
dyn Widget and used by the framework to collect default styles at mount time.Source§fn on_event(&self, _event: &dyn Any, _ctx: &AppContext) -> EventPropagation
fn on_event(&self, _event: &dyn Any, _ctx: &AppContext) -> EventPropagation
Source§fn key_bindings(&self) -> &[KeyBinding]
fn key_bindings(&self) -> &[KeyBinding]
Source§fn on_action(&self, _action: &str, _ctx: &AppContext)
fn on_action(&self, _action: &str, _ctx: &AppContext)
Source§fn border_color_override(&self) -> Option<(u8, u8, u8)>
fn border_color_override(&self) -> Option<(u8, u8, u8)>
Source§fn is_overlay(&self) -> bool
fn is_overlay(&self) -> bool
Source§fn click_action(&self) -> Option<&str>
fn click_action(&self) -> Option<&str>
Source§fn has_text_selection(&self) -> bool
fn has_text_selection(&self) -> bool
Auto Trait Implementations§
impl !Freeze for ModalScreen
impl !RefUnwindSafe for ModalScreen
impl !Send for ModalScreen
impl !Sync for ModalScreen
impl Unpin for ModalScreen
impl UnsafeUnpin for ModalScreen
impl !UnwindSafe for ModalScreen
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more