pub trait Panel: Any {
Show 13 methods
// Required methods
fn name(&self) -> &'static str;
fn title(&self) -> String;
fn render(&mut self, area: Rect, buf: &mut Buffer, ctx: &RenderContext<'_>);
fn handle_key(&mut self, chord: KeyChord) -> Vec<PanelEvent>;
fn as_any(&self) -> &dyn Any;
fn as_any_mut(&mut self) -> &mut dyn Any;
// Provided methods
fn handle_mouse(
&mut self,
event: MouseEvent,
panel_area: Rect,
) -> Vec<PanelEvent> { ... }
fn handle_scroll(&mut self, delta: i32, panel_area: Rect) -> Vec<PanelEvent> { ... }
fn cursor_position(&self, panel_area: Rect) -> Option<(u16, u16)> { ... }
fn apply_action(&mut self, action: Action) -> Option<Vec<PanelEvent>> { ... }
fn tick(&mut self) -> Vec<PanelEvent> { ... }
fn captures_escape(&self) -> bool { ... }
fn needs_close_confirmation(&self) -> Option<String> { ... }
}Expand description
A rectangular, focusable unit of UI.
Implementors provide five methods; everything else has a default. Panels communicate outward by returning events, never by mutating shared state.
Required Methods§
fn render(&mut self, area: Rect, buf: &mut Buffer, ctx: &RenderContext<'_>)
fn handle_key(&mut self, chord: KeyChord) -> Vec<PanelEvent>
fn as_any(&self) -> &dyn Any
fn as_any_mut(&mut self) -> &mut dyn Any
Provided Methods§
Sourcefn handle_mouse(
&mut self,
event: MouseEvent,
panel_area: Rect,
) -> Vec<PanelEvent>
fn handle_mouse( &mut self, event: MouseEvent, panel_area: Rect, ) -> Vec<PanelEvent>
panel_area is supplied so the panel can translate to local coordinates.
Sourcefn handle_scroll(&mut self, delta: i32, panel_area: Rect) -> Vec<PanelEvent>
fn handle_scroll(&mut self, delta: i32, panel_area: Rect) -> Vec<PanelEvent>
Coalesced scroll. Positive is down.
Sourcefn cursor_position(&self, panel_area: Rect) -> Option<(u16, u16)>
fn cursor_position(&self, panel_area: Rect) -> Option<(u16, u16)>
Where the terminal cursor belongs, in screen coordinates, when this
panel holds focus. None hides it.
The app draws the real terminal cursor rather than a styled cell, so it blinks and reshapes the way every other terminal program’s does. A panel with nothing to edit — a file tree, a viewer — leaves this defaulted.
Sourcefn apply_action(&mut self, action: Action) -> Option<Vec<PanelEvent>>
fn apply_action(&mut self, action: Action) -> Option<Vec<PanelEvent>>
Perform a named action.
This is the only way a binding, the command palette, or the vim layer reaches a panel’s behavior.
None means “I do not handle this action” and lets the app try it.
Some(vec![]) means “handled, nothing to report” — a real outcome, as
when adding a cursor at the edge of the document does nothing. Folding
those two answers into an empty vector reads fine today and becomes a
silent bug the first time an action needs both a panel implementation
and an app fallback.
Sourcefn tick(&mut self) -> Vec<PanelEvent>
fn tick(&mut self) -> Vec<PanelEvent>
Periodic hook for background work.
Sourcefn captures_escape(&self) -> bool
fn captures_escape(&self) -> bool
True when the panel consumes Escape itself (e.g. an open search box).
Sourcefn needs_close_confirmation(&self) -> Option<String>
fn needs_close_confirmation(&self) -> Option<String>
Some(message) blocks closing until confirmed.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".