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).
  • 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) for a Lip-Gloss-style box model (padding, border, margin) rendered into a standalone Grid.
  • 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.

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).

Re-exports§

pub use animate::Easing;
pub use animate::Tween;
pub use animate::oscillate;
pub use animate::oscillate_with_phase;
pub use block::join_h;
pub use block::join_v;
pub use camera::Camera;
pub use draw::fill_rect;
pub use draw::offset_for_pos;
pub use draw::thumb_geometry;
pub use interact::Consumed;
pub use interact::DEFAULT_DRAG_THRESHOLD;
pub use interact::Density;
pub use interact::FocusRing;
pub use interact::HitTester;
pub use interact::Interaction;
pub use interact::Pointer;
pub use interact::Response;
pub use interact::Sense;
pub use interact::Shortcuts;
pub use layout::Constraint;
pub use layout::Flex;
pub use layout::Side;
pub use layout::Spacing;
pub use layout::anchored_rect;
pub use layout::centered_rect;
pub use layout::split_h;
pub use layout::split_h_flex;
pub use layout::split_h_n;
pub use layout::split_h_n_flex;
pub use layout::split_h_n_spaced;
pub use layout::split_h_spaced;
pub use layout::split_v;
pub use layout::split_v_flex;
pub use layout::split_v_n;
pub use layout::split_v_n_flex;
pub use layout::split_v_n_spaced;
pub use layout::split_v_spaced;
pub use perf::DEFAULT_LAYER;
pub use perf::DefaultPerfRenderer;
pub use perf::FRAME_HISTORY;
pub use perf::PerfOverlayApp;
pub use perf::PerfOverlayMode;
pub use perf::PerfRenderer;
pub use perf::default_is_toggle_key;
pub use state::ListState;
pub use state::ScrollPhysics;
pub use state::ScrollState;
pub use state::SelectionWrap;
pub use state::TextInputState;
pub use style::BoxStyle;
pub use style::Sides;
pub use text::draw_clipped;
pub use text::truncate;
pub use text::truncate_owned;
pub use theme::Theme;
pub use ui::Ui;
pub use widget::AnimatedPerfOverlay;
pub use widget::AnimatedWidget;
pub use widget::BorderType;
pub use widget::BoxBorder;
pub use widget::Button;
pub use widget::Gauge;
pub use widget::HighlightSpacing;
pub use widget::InteractiveWidget;
pub use widget::List;
pub use widget::ListDirection;
pub use widget::Log;
pub use widget::Measure;
pub use widget::Meter;
pub use widget::Modal;
pub use widget::Panel;
pub use widget::PanelTitle;
pub use widget::Paragraph;
pub use widget::PerfOverlay;
pub use widget::PrintLine;
pub use widget::ProgressBar;
pub use widget::Scrollbar;
pub use widget::Sparkline;
pub use widget::StatBar;
pub use widget::StatefulWidget;
pub use widget::Table;
pub use widget::Tabs;
pub use widget::Text;
pub use widget::TextInput;
pub use widget::TitlePosition;
pub use widget::Widget;

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.
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.
perf
A live frame-time/FPS overlay: PerfOverlayApp wraps any App with one, on any Backend. PerfOverlayApp: a live frame-time/FPS overlay for any App, on any Backend.
state
Reusable widget state, kept separate from drawing.
style
BoxStyle: a Lip-Gloss-style box model (padding, border, margin).
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§

Align
Horizontal alignment of one line of text within the columns it’s rendered into.
Layer
A named z-order tier for Surface::on_tier, covering the split most apps with overlapping UI actually need.