Draw a panel
Panel, from
retroglyph-ui, is a bordered, optionally titled, filled rectangle: the box every other widget in
this crate typically sits inside. It’s a plain
Widget like the rest of
the crate: build it, then render it into a
Surface-shaped
area, no Backend type parameter involved.
Rendering into a sub-area
Surface::scope narrows a surface to one rectangle so a widget draws relative to that rectangle’s
own (0, 0) instead of the whole screen’s. 11_sokoban’s status pane is exactly this: a Panel
with a title, filled and bordered into the right-hand column reserved for it:
Panel::new()
.title("Status")
.render(&mut surface.scope(status_area));
status_area is one of the Rects a split_h call produced earlier in the same function; see
Split a layout for where that comes from. Content drawn after the Panel
call (the move counter, the key legend) is offset from status_area’s own top-left, one cell in
from the border it just drew, matching the interior inset Panel reserves for its box outline.
Styling and theming
Panel::border_style/fill_style set the outline and background directly; .title() (and
.add_title() for more than one, or a title on the bottom edge) adds a label into the top border.
For an app with more than one widget, prefer .theme() over hand-picking
border_style/fill_style so every widget’s panel matches the same palette; see
Theme a widget.
See also
- Split a layout, for the
RectaPanelrenders into. - Handle a click, for widgets that read pointer/keyboard input instead of only drawing.
examples/examples/11_sokoban.rs,examples/examples/09_widgets_dashboard.rs, andexamples/examples/17_theme_switch.rsfor complete panels in context.