pub trait TuiComponent:
Send
+ Sync
+ 'static {
// Required methods
fn name(&self) -> &'static str;
fn render(
&self,
ctx: &ComponentContext<'_>,
area: Rect,
frame: &mut Frame<'_>,
render_child: &mut dyn FnMut(&str, Rect, &mut Frame<'_>, &str),
measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
);
// Provided methods
fn natural_height(
&self,
_ctx: &ComponentContext<'_>,
_available_width: u16,
_measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
) -> Option<u16> { ... }
fn handle_event(
&self,
_ctx: &ComponentContext<'_>,
_event: &InputEvent,
) -> Option<EventResult> { ... }
}Expand description
Trait for ratatui component implementations.
Each A2UI component type (Text, Button, etc.) implements this.
Required Methods§
Sourcefn render(
&self,
ctx: &ComponentContext<'_>,
area: Rect,
frame: &mut Frame<'_>,
render_child: &mut dyn FnMut(&str, Rect, &mut Frame<'_>, &str),
measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
)
fn render( &self, ctx: &ComponentContext<'_>, area: Rect, frame: &mut Frame<'_>, render_child: &mut dyn FnMut(&str, Rect, &mut Frame<'_>, &str), measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>, )
Render this component.
ctxprovides access to the component’s properties and data bindings.areais the allocated area for this component.frameis the ratatui frame to render into.render_childis a closure to recursively render a child component by ID.measure_childis a closure to ask a child for its natural content height given an available width, mirroringrender_child’s(id, base_path, …)shape so template children measure against their own data path.
Provided Methods§
Sourcefn natural_height(
&self,
_ctx: &ComponentContext<'_>,
_available_width: u16,
_measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>,
) -> Option<u16>
fn natural_height( &self, _ctx: &ComponentContext<'_>, _available_width: u16, _measure_child: &mut dyn FnMut(&str, &str, u16) -> Option<u16>, ) -> Option<u16>
The intrinsic content height of this component including its own chrome
(margins/borders), given available_width cells.
measure_child lets container components measure their own children to sum
(Column/vertical-List) or max (Row) their natural heights. Leaf components
ignore it.
Returning None means “no opinion” — containers treat the component as a
legacy fill participant (it gets an equal/weighted share of the available
space, exactly as before this measure pass existed). Leaf/content components
override this to return a content-driven height so containers can reserve
only as much vertical space as the content actually needs.
The default None keeps unconverted components behaving exactly as today,
so migration is gradual and regression-free.
Sourcefn handle_event(
&self,
_ctx: &ComponentContext<'_>,
_event: &InputEvent,
) -> Option<EventResult>
fn handle_event( &self, _ctx: &ComponentContext<'_>, _event: &InputEvent, ) -> Option<EventResult>
Handle an input event directed at this component.
Returns Some(EventResult) if the component produced an action or data change
that the application should process, or None if the event was not handled.
The default implementation ignores all events (non-interactive components).
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".