Trait requestty_ui::widgets::Widget [−][src]
pub trait Widget {
fn render<B: Backend>(
&mut self,
layout: &mut Layout,
backend: &mut B
) -> Result<()>;
fn height(&mut self, layout: &mut Layout) -> u16;
fn cursor_pos(&mut self, layout: Layout) -> (u16, u16);
fn handle_key(&mut self, key: KeyEvent) -> bool;
}Expand description
A trait to represent renderable objects.
There are 2 purposes of a widget.
- Rendering to the screen.
- Handling input events.
Render Cycle
Rendering happens in a 3 step process.
- First, the height is calculated with the
heightfunction. - Then, the
renderfunction is called which is where the actual drawing happens. The cursor should end at the position reflected by the layout. - Finally, the cursor position which the user needs should see is calculated with the
cursor_posfunction.
While it is not a guarantee that the terminal will be in raw mode, it is highly recommended that those implementing the render cycle call render while in raw mode.
Required methods
Render to a given backend.
The widget is responsible for updating the layout to reflect the space that it has used.
The number of rows of the terminal the widget will take when rendered.
The widget is responsible for updating the layout to reflect the space that it will use.
The position of the cursor to be placed at after render. The returned value should be in the form of (x, y), with (0, 0) being the start position of the root widget.
fn handle_key(&mut self, key: KeyEvent) -> bool
fn handle_key(&mut self, key: KeyEvent) -> boolHandle a key input. It should return whether key was handled.