Skip to main content

retroglyph_widgets/
lib.rs

1//! Immediate-mode drawing helpers over a [`Rect`](retroglyph_core::Rect).
2//!
3//! Box borders, filled panels, gauges, tables, sparklines, and a small
4//! constraint-based [`Rect`](retroglyph_core::Rect) splitter with
5//! ratatui-style `Fixed`/`Percent`/`Fill`/`Min`/`Max` constraints and `Flex`
6//! alignment ([`layout`]).
7//!
8//! Every widget ([`widget`]) is a builder struct that draws itself into a
9//! [`Grid`](retroglyph_core::Grid) via [`Widget`]/[`StatefulWidget`] and
10//! retains no state of its own: state that outlives one render call (a
11//! selection index, a scroll offset) lives in [`ListState`] instead. A
12//! handful of things that are genuinely just functions ([`fill_rect`],
13//! [`thumb_geometry`]/[`offset_for_pos`]) stay free functions in [`draw`]
14//! rather than pretending to be widgets. Three more independent layers
15//! build on top:
16//!
17//! - [`Widget`]/[`StatefulWidget`] ([`widget`]) render into a [`Surface`],
18//!   an area-relative, single-layer view over a [`Grid`](retroglyph_core::Grid), and let
19//!   callers box or store heterogeneous widgets, e.g. a `Vec<Box<dyn Widget>>` of panes to
20//!   render each frame, with no `Backend` type parameter, since drawing touches nothing but
21//!   cells.
22//! - [`Interaction`] ([`interact`]) for hover/click/drag/focus tracking
23//!   without a retained widget tree: the sibling of [`ListState`] for
24//!   widgets that don't have a natural selection index of their own.
25//! - [`BoxStyle`] ([`style`]) for a Lip-Gloss-style box model (padding,
26//!   border, margin) rendered into a standalone `Grid`.
27//! - [`join_h`]/[`join_v`] ([`block`]) to compose several `Grid`s (e.g.
28//!   `BoxStyle::render` output) into one before drawing it.
29//! - [`Theme`] ([`theme`]) for named color roles (an app picks
30//!   [`Theme::DARK`]/[`Theme::LIGHT`], or builds its own), independent of
31//!   how the app decides which one is active.
32//!
33//! This crate is itself optional: games that draw manually depend only on
34//! `retroglyph-core`.
35
36#![cfg_attr(docsrs, feature(doc_cfg))]
37
38// Compile the code blocks in this crate's own README as doctests so its quick start is
39// type-checked on every test run and cannot silently rot. The `cfg(doctest)` gate keeps this out
40// of the rendered crate documentation: see `retroglyph-crossterm`'s matching include for the
41// same pattern applied to the workspace root README.
42#[cfg(doctest)]
43#[doc = include_str!("../README.md")]
44struct ReadmeDoctests;
45
46pub mod align;
47pub mod block;
48pub mod draw;
49pub mod interact;
50pub mod layout;
51pub mod state;
52pub mod style;
53pub mod text;
54pub mod theme;
55pub mod widget;
56
57pub use align::Align;
58pub use block::{blit_into, join_h, join_v};
59pub use draw::{fill_rect, offset_for_pos, thumb_geometry};
60pub use interact::{
61    DEFAULT_DRAG_THRESHOLD, Density, FocusRing, HitTester, Interaction, Pointer, Response, Sense,
62    Shortcuts,
63};
64pub use layout::{
65    Constraint, Flex, centered_rect, split_h, split_h_flex, split_h_spaced, split_v, split_v_flex,
66    split_v_spaced,
67};
68pub use retroglyph_core::{StyledSurface, Surface};
69pub use state::{ListState, ScrollPhysics, ScrollState, SelectionWrap};
70pub use style::{BoxStyle, Sides};
71pub use text::{truncate, truncate_owned};
72pub use theme::Theme;
73#[cfg(feature = "egc")]
74pub use widget::Paragraph;
75pub use widget::{
76    BoxBorder, Button, Gauge, List, Log, Measure, Meter, Modal, Panel, PrintLine, ProgressBar,
77    Scrollbar, Sparkline, StatBar, StatefulWidget, Table, Tabs, Text, Widget,
78};