pub struct Modal<'a> { /* private fields */ }Expand description
A bordered, filled box centered in a screen Rect.
Shorthand for a Panel sized width x height and centered via
centered_rect. border_style/fill_style default to
Style::new() and there is no title by default – set whichever a
caller needs via Modal::border_style/Modal::fill_style/Modal::title,
the same as Panel.
Modal::render returns the inner content Rect (inside the
border, the same implicit one-cell inset Panel uses for its own
interior) ready to hand to another widget (e.g. super::Log).
Draws only the box itself; everything outside it is left untouched (no
dimming or backdrop fill – that would need to read and blend existing
cells, a separate feature from this thin layout convenience). Not a
Widget: Widget::render can’t return a value, and the inner
content rect is part of this type’s contract.
§Examples
use retroglyph_core::{Headless, Rect, Terminal};
use retroglyph_widgets::Modal;
let mut term = Terminal::new(Headless::new(20, 10));
let screen = Rect::new(0, 0, 20, 10);
let inner = Modal::new(10, 4).title("Confirm").render(screen, &mut term);
// `inner` is ready to hand to another widget, e.g. a `Log` or `Text`.
assert_eq!(inner.width(), 8);Implementations§
Source§impl<'a> Modal<'a>
impl<'a> Modal<'a>
Sourcepub fn new(width: u16, height: u16) -> Self
pub fn new(width: u16, height: u16) -> Self
A width x height modal in the default style, with no title.
Sourcepub const fn title_align(self, align: Align) -> Self
pub const fn title_align(self, align: Align) -> Self
Set how the title is aligned along the top border. Defaults to
Align::Center, the same as Panel::title_align.
Sourcepub const fn border_style(self, style: Style) -> Self
pub const fn border_style(self, style: Style) -> Self
Set the box outline and title’s style.
Sourcepub const fn fill_style(self, style: Style) -> Self
pub const fn fill_style(self, style: Style) -> Self
Set the interior background’s style.
Sourcepub fn theme(self, theme: Theme) -> Self
pub fn theme(self, theme: Theme) -> Self
Applies theme’s named roles to this modal’s border and fill, the same mapping as
Panel::theme (a Modal is just a centered Panel): border_style becomes
theme.border on theme.title_bg, and fill_style becomes theme.panel_bg.
Call before any manual Modal::border_style/Modal::fill_style override you want to
keep – whichever call comes last wins.
Sourcepub fn theme_on(self, theme: Theme, bg: Color) -> Self
pub fn theme_on(self, theme: Theme, bg: Color) -> Self
Same as Modal::theme, but fill_style is drawn on bg instead of theme.panel_bg –
the same Panel::theme_on escape hatch, for a modal whose interior should read as a
different surface than theme.panel_bg (border_style still uses theme.title_bg,
unaffected by bg). Modal::theme is exactly theme_on(theme, theme.panel_bg).