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
Theme::DARK (as if Modal::theme had been called) 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 (via Panel::inner, the border inset
plus this modal’s Modal::padding) 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.
Modal::render draws through whatever Surface it’s given, on whatever layer that
surface is already scoped to: it has no layer of its own to default. A modal painted over
an active screen should be given a surface on Layer::Overlay
(surface.on_tier(Layer::Overlay)), so it paints on top regardless of whether the screen or
the modal renders first this frame; see Layer’s docs for why that
beats ordering the two draw calls.
§Examples
use retroglyph_core::grid::{Grid, Rect};
use retroglyph_core::surface::Layer;
use retroglyph_ui::{Modal, Surface};
let screen = Rect::new(0, 0, 20, 10);
let mut grid = Grid::new(20, 10);
let mut surface = Surface::new(&mut grid, screen, Layer::World.as_u8());
let inner = Modal::new(10, 4)
.title("Confirm")
.render(screen, &mut surface.on_tier(Layer::Overlay));
// `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 with no title, styled from Theme::DARK (as if
Modal::theme had been called).
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 const fn border_type(self, border_type: BorderType) -> Self
pub const fn border_type(self, border_type: BorderType) -> Self
Set which box-drawing glyphs the border is drawn with. Defaults to
BorderType::Plain, the same as Panel::border_type.
Sourcepub const fn padding(self, padding: Sides) -> Self
pub const fn padding(self, padding: Sides) -> Self
Reserve padding between the border and the rect Modal::render returns, the same as
Panel::padding (a Modal is just a centered Panel). Defaults to Sides::ZERO.
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).
Trait Implementations§
impl<'a> Copy for Modal<'a>
Auto Trait Implementations§
impl<'a> Freeze for Modal<'a>
impl<'a> RefUnwindSafe for Modal<'a>
impl<'a> Send for Modal<'a>
impl<'a> Sync for Modal<'a>
impl<'a> Unpin for Modal<'a>
impl<'a> UnsafeUnpin for Modal<'a>
impl<'a> UnwindSafe for Modal<'a>
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<C> WithAlpha for Cwhere
C: Copy,
impl<C> WithAlpha for Cwhere
C: Copy,
§fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
fn with_alpha_first<A>(self, alpha: A) -> AlphaFirst<A, Self>
self with alpha, storing alpha before the color in memory
(see [AlphaFirst]).§fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
fn with_alpha_last<A>(self, alpha: A) -> AlphaLast<A, Self>
self with alpha, storing alpha after the color in memory
(see [AlphaLast]).