pub trait Component {
type Props<'a>;
// Required methods
fn handle_event(
&mut self,
event: &EventKind,
props: Self::Props<'_>,
) -> Vec<impl Action>;
fn render(
&mut self,
frame: &mut Frame<'_>,
area: Rect,
props: Self::Props<'_>,
);
// Provided methods
fn subscriptions(&self) -> Vec<EventType> { ... }
fn area(&self) -> Option<Rect> { ... }
}Expand description
A pure UI component that renders based on props and emits actions
Components follow these rules:
- Props contain ALL read-only data needed for rendering
handle_eventreturns actions, never mutates external staterenderis a pure function of props (plus internal UI state like scroll position)
Internal UI state (scroll position, selection highlight) can be stored in &mut self,
but data mutations must go through actions.
§Focus and Context
Components receive EventKind (the raw event) rather than the full Event with context.
Focus information and other context should be passed through Props. This keeps components
decoupled from the specific ComponentId type used by the application.
Required Associated Types§
Required Methods§
Provided Methods§
Sourcefn subscriptions(&self) -> Vec<EventType>
fn subscriptions(&self) -> Vec<EventType>
Event types this component wants to receive
Return the event types this component should be subscribed to. Global events are always delivered regardless of this.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.