1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
//! `Widget`/`StatefulWidget` structs: one file per widget, each a builder
//! that owns its own drawing logic.
//!
//! `new()` takes only the arguments a widget cannot mean anything without
//! (the content: a value, a label, a slice of samples/rows). Every other
//! knob (styles, offsets, titles) has a default and is set through a
//! chainable `#[must_use] fn field(mut self, ...) -> Self` method, the same
//! shape as [`Panel::title`] or [`Log::offset`]. See `crates/widgets/AGENTS.md`
//! for the rule this is enforcing and why.
//!
//! A few widgets share logic: [`Gauge`] and [`StatBar`] both delegate to a
//! crate-private `bar` module, and [`Sparkline`]/[`Gauge`]/[`StatBar`] all
//! use [`Meter`] for their ratio-to-color ramp. [`Paragraph`] (behind the
//! `egc` feature) additionally implements [`Measure`], since it needs
//! `retroglyph_core::layout::TextLayout`'s grapheme-aware word-wrap to
//! report a height before rendering.
use Rect;
use crateSurface;
pub use BoxBorder;
pub use Button;
pub use Gauge;
pub use List;
pub use Log;
pub use Meter;
pub use Modal;
pub use Panel;
pub use Paragraph;
pub use PerfOverlay;
pub use PrintLine;
pub use ProgressBar;
pub use Scrollbar;
pub use Sparkline;
pub use StatBar;
pub use Table;
pub use Tabs;
pub use Text;
/// A type that draws itself into a [`Surface`], without retaining any
/// state — the minimal shape shared by every widget-like consumer.
///
/// # Examples
///
/// ```
/// use retroglyph_core::{Grid, Rect, Style};
/// use retroglyph_widgets::{Surface, Widget};
///
/// struct Marker(char);
///
/// impl Widget for Marker {
/// fn render(&self, _area: Rect, surface: &mut Surface<'_>) {
/// surface.put((0, 0), self.0, Style::new());
/// }
/// }
///
/// let area = Rect::new(0, 0, 4, 1);
/// let mut grid = Grid::new(4, 1);
/// Marker('*').render(area, &mut Surface::new(&mut grid, area, 0));
/// ```
/// Like [`Widget`], but for widgets that read (and may update) externally
/// owned state — a selection index, a scroll offset — that outlives a
/// single render call. See [`crate::ListState`].
///
/// # Examples
///
/// ```
/// use retroglyph_core::{Grid, Rect, Style};
/// use retroglyph_widgets::{Surface, StatefulWidget};
///
/// struct Counter;
///
/// impl StatefulWidget for Counter {
/// type State = u32;
///
/// fn render(&self, _area: Rect, surface: &mut Surface<'_>, state: &mut Self::State) {
/// *state += 1;
/// surface.put((0, 0), 'x', Style::new());
/// }
/// }
///
/// let area = Rect::new(0, 0, 4, 1);
/// let mut grid = Grid::new(4, 1);
/// let mut renders = 0;
/// Counter.render(area, &mut Surface::new(&mut grid, area, 0), &mut renders);
/// assert_eq!(renders, 1);
/// ```
/// A widget that can report the height it needs for a given width, before
/// ever being rendered.
///
/// Lets a caller size a pane to fit content (e.g. a wrapped `Paragraph`,
/// behind the `egc` feature) instead of guessing a fixed height up front.
/// Sizing is pure content math, not drawing.
///
/// # Examples
///
/// ```
/// use retroglyph_widgets::Measure;
///
/// struct FixedHeight(u16);
///
/// impl Measure for FixedHeight {
/// fn height_for(&self, _width: u16) -> u16 {
/// self.0
/// }
/// }
///
/// assert_eq!(FixedHeight(3).height_for(80), 3);
/// ```