pub struct Renderer { /* private fields */ }Expand description
A Renderer is responsible for rendering the UI to the terminal. It takes
a Container and displays its components on the screen.
§Usage
A Renderer is used to render a Container to the terminal. It manages
drawing operations and handles the rendering process efficiently.
§Derives
Clone, Debug, PartialEq, Eq
§Example
// Create a Renderer with a width of 40 and a height of 20
let mut renderer = Renderer::new(40, 20);
// Clear the buffer before rendering
renderer.clear();
// Render the container (assuming `container` is created elsewhere)
renderer.render(&container);
// Draw the final output to the terminal
renderer.draw();Implementations§
Source§impl Renderer
impl Renderer
Sourcepub fn new(width: u16, height: u16) -> Renderer
pub fn new(width: u16, height: u16) -> Renderer
Constructs a new Renderer with the specified width and height.
§Parameters
width: Au16representing the width in characters.height: Au16representing the height in characters.
§Returns
A Renderer instance.
§Example
// Create a Renderer with a width of 40 and a height of 20 characters.
let renderer = Renderer::new(40, 20);Sourcepub fn fullscreen() -> FtuiResult<Renderer>
pub fn fullscreen() -> FtuiResult<Renderer>
Sourcepub fn render(&mut self, container: &mut Container) -> FtuiResult<()>
pub fn render(&mut self, container: &mut Container) -> FtuiResult<()>
Renders a Container into the Renderer buffer without drawing to the terminal.
§Parameters
container: A mutable reference to theContainerto be rendered.
§Note
- This method only updates the internal buffer.
- To display the rendered content, call the
drawmethod. - You should use the
clearmethod to clear the buffer first.
§Returns
Ok(()): Returns nothing.Err(FtuiError): Returns an error.
§Example
// Create a `Renderer` with a width of 40 and a height of 20 characters.
let mut renderer = Renderer::new(40, 20);
// Render the container into the renderer buffer
// (assuming `container` is created elsewhere)
renderer.render(&mut container)?;Sourcepub fn render_list(&mut self, list: &mut List) -> FtuiResult<()>
pub fn render_list(&mut self, list: &mut List) -> FtuiResult<()>
Renders a List into the Renderer buffer without drawing to the terminal.
§Parameters
list: A mutable reference to theListto be rendered.
§Note
- This method only updates the internal buffer.
- To display the rendered content, call the
drawmethod. - You should use the
clearmethod to clear the buffer first.
§Returns
Ok(()): Returns nothing.Err(FtuiError): Returns an error.
§Example
// Create a `Renderer` with a width of 40 and a height of 20 characters.
let mut renderer = Renderer::new(40, 20);
// Render a list into the renderer buffer
// (assuming `list` is created elsewhere)
renderer.render_list(&mut list)?;Sourcepub fn draw(&mut self) -> FtuiResult<()>
pub fn draw(&mut self) -> FtuiResult<()>
Draws the Renderer buffer to the terminal.
§Note
The render method must be called at least once before draw, as draw only
displays the content stored in the Renderer buffer.
§Example
// Create a `Renderer` with a width of 40 and a height of 20 characters.
let mut renderer = Renderer::new(40, 20);
// Render the container into the renderer buffer
// (assuming `container` is created elsewhere)
renderer.render(&mut container)?;
// Draw the rendered content to the terminal
renderer.draw();
// The draw method can be called again without re-rendering,
// but changes won't be reflected unless `render` is called.
renderer.draw();Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the Renderer buffer. This method should be called before rendering.
§Note
Calling this method before rendering prevents visual artifacts.
§Example
// Create a `Renderer` with a width of 40 and a height of 20 characters.
let mut renderer = Renderer::new(40, 20);
// Rendering loop
loop {
// Clear the `Renderer` buffer to remove previous frame content
renderer.clear();
// Render the container into the renderer buffer
// (assuming `container` is created elsewhere)
renderer.render(&mut container)?;
// Draw the rendered content to the terminal
renderer.draw();
}Sourcepub fn simple_draw(&mut self, container: &mut Container) -> FtuiResult<()>
pub fn simple_draw(&mut self, container: &mut Container) -> FtuiResult<()>
Executes a full rendering cycle in a single method call. This method
automatically calls clear, render, and draw in sequence.
§Parameters
container: A mutable reference to theContainerto be drawn.
§Returns
Ok(()): Returns nothing.Err(FtuiError): Returns an error.
§Example
// Create a `Renderer` with a width of 40 and a height of 20 characters.
let mut renderer = Renderer::new(40, 20);
// Standard rendering loop
loop {
renderer.clear();
// Render content (assuming `container` is created elsewhere)
renderer.render(&mut container)?;
renderer.draw();
}
// Simplified rendering loop using `simple_draw`
loop {
// Render and draw in a single step
renderer.simple_draw(&mut container)?;
}