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//! [`Terminal`](retroglyph_core::Terminal) via [`Widget`]/[`StatefulWidget`]
10//! and retains no state of its own -- state that outlives one render call
11//! (a 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`]) let callers box or store
18//!   heterogeneous widgets, e.g. a `Vec<Box<dyn Widget<B>>>` of panes to
19//!   render each frame.
20//! - [`Interaction`] ([`interact`]) for hover/click/drag/focus tracking
21//!   without a retained widget tree -- the sibling of [`ListState`] for
22//!   widgets that don't have a natural selection index of their own.
23//! - [`BoxStyle`] ([`style`]) for a Lip-Gloss-style box model (padding,
24//!   border, margin) rendered into a standalone `Grid`.
25//! - [`join_h`]/[`join_v`] ([`block`]) to compose several `Grid`s -- e.g.
26//!   `BoxStyle::render` output -- into one before drawing it.
27//! - [`Theme`] ([`theme`]) for named color roles (an app picks
28//!   [`Theme::DARK`]/[`Theme::LIGHT`], or builds its own), independent of
29//!   how the app decides which one is active.
30//!
31//! This crate is itself optional: games that draw manually depend only on
32//! `retroglyph-core`.
33
34#![allow(
35    clippy::cast_possible_truncation,
36    clippy::cast_lossless,
37    clippy::cast_precision_loss,
38    clippy::cast_sign_loss,
39    clippy::items_after_statements
40)]
41
42// Compile the code blocks in this crate's own README as doctests so its quick start is
43// type-checked on every test run and cannot silently rot. The `cfg(doctest)` gate keeps this out
44// of the rendered crate documentation -- see `retroglyph-crossterm`'s matching include for the
45// same pattern applied to the workspace root README.
46#[cfg(doctest)]
47#[doc = include_str!("../README.md")]
48struct ReadmeDoctests;
49
50pub mod align;
51pub mod block;
52pub mod draw;
53pub mod interact;
54pub mod layout;
55pub mod state;
56pub mod style;
57pub mod text;
58pub mod theme;
59pub mod widget;
60
61pub use align::Align;
62pub use block::{blit_into, join_h, join_v};
63pub use draw::{fill_rect, offset_for_pos, thumb_geometry};
64pub use interact::{
65    DEFAULT_DRAG_THRESHOLD, Density, FocusRing, HitTester, Interaction, Pointer, Response, Sense,
66    Shortcuts,
67};
68pub use layout::{
69    Constraint, Flex, centered_rect, split_h, split_h_flex, split_h_spaced, split_v, split_v_flex,
70    split_v_spaced,
71};
72pub use state::{ListState, ScrollPhysics, ScrollState, SelectionWrap};
73pub use style::{BoxStyle, Sides};
74pub use text::{truncate, truncate_owned};
75pub use theme::Theme;
76#[cfg(feature = "egc")]
77pub use widget::Paragraph;
78pub use widget::{
79    BoxBorder, Button, Gauge, List, Log, Measure, Meter, Modal, Panel, PrintLine, ProgressBar,
80    Scrollbar, Sparkline, StatBar, StatefulWidget, Table, Tabs, Text, Widget,
81};