pub trait Widget {
// Required method
fn render(&self, area: Rect, frame: &mut Frame<'_>);
// Provided method
fn is_essential(&self) -> bool { ... }
}Expand description
A widget that can render itself into a Frame.
§Frame vs Buffer
Widgets render into a Frame rather than directly into a Buffer. This provides:
- Buffer access:
frame.bufferfor drawing cells - Hit testing:
frame.register_hit()for mouse interaction - Cursor control:
frame.cursor_positionfor input widgets - Performance hints:
frame.buffer.degradationfor adaptive rendering
§Implementation Guide
Most widgets only need buffer access:
ⓘ
fn render(&self, area: Rect, frame: &mut Frame) {
for y in area.y..area.bottom() {
for x in area.x..area.right() {
frame.buffer.set(x, y, Cell::from_char('.'));
}
}
}Interactive widgets should register hit regions when a hit_id is set.
Input widgets should set frame.cursor_position when focused.
§Degradation Levels
Check frame.buffer.degradation to adapt rendering:
Full: All features enabledSimpleBorders: Skip fancy borders, use ASCIINoStyling: Skip colors and attributesEssentialOnly: Only render essential widgetsSkeleton: Minimal placeholder rendering
Required Methods§
Provided Methods§
Sourcefn is_essential(&self) -> bool
fn is_essential(&self) -> bool
Whether this widget is essential and should always render.
Essential widgets render even at EssentialOnly degradation level.
Override this to return true for:
- Text inputs (user needs to see what they’re typing)
- Primary content areas (main information display)
- Critical status indicators
Returns false by default, appropriate for decorative widgets.