Skip to main content

Widget

Trait Widget 

Source
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::widget::Widget;
use retroglyph_ui::Surface;

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§

Source

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.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Widget for BoxBorder

Source§

impl Widget for Boxed<'_>

Source§

impl Widget for Button<'_>

Source§

impl Widget for Gauge<'_>

Source§

impl Widget for Log<'_>

Source§

impl Widget for Panel<'_>

Source§

impl Widget for Paragraph<'_>

Available on crate feature egc only.
Source§

impl Widget for PrintLine<'_>

Source§

impl Widget for ProgressBar

Source§

impl Widget for Scrollbar

Source§

impl Widget for Sparkline<'_>

Source§

impl Widget for StatBar<'_>

Source§

impl Widget for Tabs<'_>

Source§

impl Widget for Text<'_>

Source§

impl<const N: usize> Widget for PerfOverlay<'_, N>