pub trait Widget {
// Required method
fn render(&self, surface: &mut Surface<'_>);
}Expand description
A type that draws itself into a Surface, without retaining any
state: the minimal shape shared by every widget-like consumer.
§Examples
use retroglyph_core::color::Style;
use retroglyph_core::grid::{Grid, Rect};
use retroglyph_ui::{Surface, Widget};
struct Marker(char);
impl Widget for Marker {
fn render(&self, surface: &mut Surface<'_>) {
surface.put((0, 0), self.0, Style::new());
}
}
let area = Rect::new(0, 0, 4, 1);
let mut grid = Grid::new(4, 1);
Marker('*').render(&mut Surface::new(&mut grid, area, 0));Required Methods§
Sourcefn render(&self, surface: &mut Surface<'_>)
fn render(&self, surface: &mut Surface<'_>)
Draw this widget into surface, filling surface.area().
Coordinates on every Surface drawing method are local to surface itself, where
(0, 0) is surface.area()’s own top-left corner, not the underlying grid’s. Placement
should therefore be built from Surface::width/Surface::height (or
surface.area().at_origin() for a rect), never from surface.area()’s own
left/top: those are
absolute grid coordinates, and passing them straight to a drawing call only lands
correctly for a surface whose area happens to start at the grid origin.
Implementors§
impl Widget for Boxed<'_>
impl Widget for BoxBorder
impl Widget for Button<'_>
impl Widget for Gauge<'_>
impl Widget for Log<'_>
impl Widget for Panel<'_>
impl Widget for Paragraph<'_>
Available on crate feature
egc only.