Skip to main content

Module ui

Module ui 

Source
Expand description

Ui: one frame’s Surface and Interaction paired, so a call site names an area/id once and gets both hit-testing and drawing from it.

You rarely build a Ui yourself. Interaction::frame runs one frame’s begin_frame/end_frame lifecycle and hands its closure a ready Ui; Ui::new is the escape hatch for callers driving that lifecycle by hand. From there Ui::show hit-tests and draws an InteractiveWidget from one area/id, Ui::draw renders a plain Widget, and Ui::vertical/Ui::horizontal open a cursor that allocates areas for show_sized/draw_sized so a call site never computes a child Rect by hand.

use retroglyph_core::backend::Headless;
use retroglyph_core::grid::Rect;
use retroglyph_core::terminal::Terminal;
use retroglyph_ui::{Interaction, Sense};

#[derive(Clone, Copy, PartialEq, Eq)]
enum WidgetId {
    Save,
}

let mut term = Terminal::new(Headless::new(20, 10));
let mut interaction = Interaction::<WidgetId>::new();
let clicked = interaction.frame(&mut term.surface(), |ui| {
    let area = Rect::new(0, 0, 10, 1);
    ui.interaction().interact(area, WidgetId::Save, Sense::click()).clicked()
});
assert!(!clicked); // nothing clicked yet: no input was fed in

Structs§

Ui
One frame’s drawing surface and interaction state, together, so a call site names an area/id once and gets both hit-testing and drawing from it: see show.