Skip to main content

Crate retroglyph_ui

Crate retroglyph_ui 

Source
Expand description

Immediate-mode drawing helpers over a Rect.

Box borders, filled panels, gauges, tables, sparklines, and a small constraint-based Rect splitter with ratatui-style Fixed/Percent/Fill/Min/Max constraints and Flex alignment (layout).

Every widget (widget) is a builder struct that draws itself into a Grid via Widget/StatefulWidget and retains no state of its own: state that outlives one render call (a selection index, a scroll offset, a text field’s value and cursor) lives in ListState/TextInputState instead. A handful of things that are genuinely just functions (fill_rect, thumb_geometry/offset_for_pos in draw; truncate/truncate_owned in text) stay free functions rather than pretending to be widgets. Three more independent layers build on top:

  • Widget/StatefulWidget (widget) render into a Surface, an area-relative, single-layer view over a Grid, and let callers box or store heterogeneous widgets, e.g. a Vec<Box<dyn Widget>> of panes to render each frame, with no Backend type parameter, since drawing touches nothing but cells. AnimatedWidget is StatefulWidget’s sibling for state that evolves with wall-clock time (e.g. ScrollState’s momentum physics) instead of only in response to input; see its own docs. InteractiveWidget is the sibling trait for widgets that also read a Response (Button, Scrollbar, List, Tabs). For a bordered box drawn straight into that Surface – with titles, BorderType glyph sets, padding, and theming – reach for Panel first; it’s the default answer to “draw me a box”.
  • Interaction (interact) for hover/click/drag/focus tracking without a retained widget tree: the sibling of ListState for widgets that don’t have a natural selection index of their own. Ui pairs one frame’s Surface with an Interaction, via Interaction::frame: Ui::show is how an InteractiveWidget gets hit-tested and drawn from the one area/id a call site names.
  • BoxStyle (style) is the standalone alternative to Panel: a Lip-Gloss-style box model (padding, border, margin) rendered into its own Grid, independent of any Surface/Backend/Terminal. Reach for it instead of Panel when composing a box outside a frame, laying several boxes out with join_h/ join_v below, or needing margin (space outside the border, which Panel has no concept of); it has no titles, BorderType, or theming.
  • join_h/join_v (block) to compose several Grids (e.g. BoxStyle::render output) into one; retroglyph_core::surface::Surface::blit stamps the result onto a surface.
  • Theme (theme) for named color roles (an app picks Theme::DARK/Theme::LIGHT, or builds its own), independent of how the app decides which one is active.
  • HalfBlockCanvas/QuadrantCanvas/ SextantCanvas/BrailleCanvas (canvas) for sub-cell drawing: plot points at higher-than-one-per-cell resolution, then read a frame’s worth of glyphs back out, one per cell.

This crate is itself optional: games that draw manually depend only on retroglyph-core.

This crate is no_std-compatible: disable the std feature and enable libm instead (also requires an allocator). See the std and libm features below.

§Features

Default features: std.

§dev

⚪ Optional.

Forwards retroglyph-core’s dev feature, which forces development diagnostics on in a build that would otherwise compile them out (see retroglyph_core::dev).

§egc

⚪ Optional.

Forwards to retroglyph-core’s egc feature.

Upgrades Paragraph’s word-wrap (always available) to grapheme-cluster-aware correctness.

§libm

⚪ Optional.

Uses retroglyph-core’s libm feature (the no_std float backend: easing curves and tweens, scrollbar geometry, gauge/sparkline/bar percentage rounding, scroll momentum decay) instead of std’s own float intrinsics. See std below; a build needs exactly one of the two.

§serde

⚪ Optional.

Adds Serialize/Deserialize impls for Theme and Density, forwarding to retroglyph-core’s serde feature.

Theme round-trips through Color’s own serde impl.

§std

🟢 Enabled by default.

Enables retroglyph-core/std, whose float intrinsics back this crate’s own float use (see libm above for the no_std alternative).

Disabling this feature (--no-default-features) builds this crate no_std (requires an allocator and one of std/libm; see the crate-level compile_error! in src/lib.rs).

§testing

⚪ Optional.

Enables testing’s WidgetHarness, the sibling of retroglyph-core’s testing::TestHarness for driving a bare Interaction<Id>/Ui (no App required) against Headless for tests, with synthetic input queuing and a step that drains it.

Test-only surface, off by default so it never ships in a release build by accident. Headless is unconditionally available in retroglyph-core, so this needs no feature forwarding there.

Modules§

align
Align: horizontal alignment of a single line of text within a fixed-width area.
animate
Time-driven value animation: easing curves, a stateful Tween, and a periodic oscillator.
block
Compose Grid values before drawing them.
camera
A scrolling viewport into a world larger than the screen. A scrolling viewport into a world larger than the screen.
canvas
Sub-cell drawing: plot points/pixels at higher-than-one-per-cell resolution and read them back as glyphs, via retroglyph_core::symbols’s quantizers. Sub-cell drawing: a buffer to plot into before there are pixels to posterize.
draw
fill_rect and thumb_geometry/offset_for_pos: the handful of things genuinely useful as standalone functions rather than Widgets.
interact
Pointer and keyboard focus tracking for interactive widgets, without a retained widget tree.
layout
Constraint-based Rect splitter for multi-panel UIs.
state
Reusable widget state, kept separate from drawing.
style
BoxStyle: a Lip-Gloss-style box model (padding, border, margin).
testing
Headless widget-level test harness: WidgetHarness drives a bare Interaction<Id>/Ui against Headless, without an App.
text
Single-line column-clipping, unicode-width aware.
theme
Theme: named color roles for a light/dark-aware app.
ui
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.
widget
Widget/StatefulWidget structs: one file per widget, each a builder that owns its own drawing logic.

Structs§

StyledSurface
A Surface with a Style bound in, returned by Surface::with_style.
Surface
The render target for every drawing call in the workspace: a mutable reference to a Grid plus a fixed layer, scoped to an area and clipped to a clip rect.

Enums§

Layer
A named z-order tier for Surface::on_tier, covering the split most apps with overlapping UI actually need.