Skip to main content

Widget

Trait Widget 

Source
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.buffer for drawing cells
  • Hit testing: frame.register_hit() for mouse interaction
  • Cursor control: frame.cursor_position for input widgets
  • Performance hints: frame.buffer.degradation for 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 enabled
  • SimpleBorders: Skip fancy borders, use ASCII
  • NoStyling: Skip colors and attributes
  • EssentialOnly: Only render essential widgets
  • Skeleton: Minimal placeholder rendering

Required Methods§

Source

fn render(&self, area: Rect, frame: &mut Frame<'_>)

Render the widget into the frame at the given area.

The area defines the bounding rectangle within which the widget should render. Widgets should respect the area bounds and not draw outside them (the buffer’s scissor stack enforces this).

Provided Methods§

Source

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.

Implementors§

Source§

impl Widget for Badge<'_>

Source§

impl Widget for Block<'_>

Source§

impl Widget for Columns<'_>

Source§

impl Widget for CommandPalette

Source§

impl Widget for ConstraintOverlay<'_>

Source§

impl Widget for DragPreview<'_>

Source§

impl Widget for Emoji

Source§

impl Widget for FallbackWidget

Source§

impl Widget for Group<'_>

Source§

impl Widget for Help

Source§

impl Widget for KeybindingHints

Source§

impl Widget for HistoryPanel

Source§

impl Widget for TextInput

Source§

impl Widget for InspectorOverlay<'_>

Source§

impl Widget for JsonView

Source§

impl Widget for Layout<'_>

Source§

impl Widget for NotificationStack<'_>

Source§

impl Widget for Paginator<'_>

Source§

impl Widget for Paragraph<'_>

Source§

impl Widget for MiniBar

Source§

impl Widget for Rule<'_>

Source§

impl Widget for Sparkline<'_>

Source§

impl Widget for StatusLine<'_>

Source§

impl Widget for Stopwatch<'_>

Source§

impl Widget for TextArea

Source§

impl Widget for Timer<'_>

Source§

impl Widget for Toast

Source§

impl Widget for Tree

Source§

impl Widget for ValidationErrorDisplay

Source§

impl Widget for VoiDebugOverlay

Source§

impl<'a> Widget for List<'a>

Source§

impl<'a> Widget for ProgressBar<'a>

Source§

impl<'a> Widget for Scrollbar<'a>

Source§

impl<'a> Widget for Spinner<'a>

Source§

impl<'a> Widget for Table<'a>

Source§

impl<C: Widget> Widget for Modal<C>

Source§

impl<T: Debug + ?Sized> Widget for Pretty<'_, T>

Source§

impl<W: Widget> Widget for Align<W>

Source§

impl<W: Widget> Widget for Padding<W>

Source§

impl<W: Widget> Widget for Panel<'_, W>

Source§

impl<W: Widget> Widget for Budgeted<W>