Guide API
Skip to main content

Renderer

Struct Renderer 

Source
pub struct Renderer { /* private fields */ }
Expand description

Owns the back/front buffer pair and a boxed Backend.

Renderer — the per-frame draw cycle.

The Renderer owns the back/front Buffer pair plus a boxed Backend. Each frame it:

  1. Resets the back buffer.
  2. Runs the paint closure into the back buffer.
  3. Diffs the back buffer against the front buffer.
  4. Pushes changed cells to the backend.
  5. Sets the cursor and, while it is shown, the caret size.
  6. Flushes.
  7. Swaps back/front so the new frame becomes the reference for the next diff.

This mirrors the role of ratatui’s Terminal::draw but is simpler: there is no partial-repaint or damage-tracking — the whole view tree is painted every frame and the cell diff keeps the terminal I/O bounded.

Constructed with Renderer::new; the frame cycle is Renderer::render.

§Turbo Vision heritage

Replaces Turbo Vision’s incremental, per-view screen writes (each view wrote its buffer straight through the screen driver) with a double-buffered whole-tree repaint plus diff. The per-view damage tracking is dropped in favour of repaint-and-diff (deviation D8).

Implementations§

Source§

impl Renderer

Source

pub fn new(backend: Box<dyn Backend>) -> Self

Create a new Renderer backed by backend.

Both buffers are initialized to the backend’s current size.

Source

pub fn render(&mut self, paint: impl FnOnce(&mut Buffer))

Run one frame cycle.

  1. Resets the back buffer to blank.
  2. Calls paint with a mutable reference to the back buffer.
  3. Diffs the back buffer against the front buffer.
  4. Pushes changed cells to the backend.
  5. Sets the cursor and, while it is shown, the caret size.
  6. Flushes.
  7. Swaps back/front.

The borrow structure: self.buffers[back] and self.buffers[front] are distinct elements (different indices), so Rust’s disjoint-field borrow lets the compiler see that diff borrows self.buffers[front] while self.backend is a separate field. No cloning is needed.

Source

pub fn set_cursor(&mut self, pos: Option<(u16, u16)>)

Set the desired cursor position (used by the next render call).

Source

pub fn set_caret_size(&mut self, size: u8)

Set the desired caret size (used by the next render call while the cursor is shown). See Backend::set_caret_size.

Source

pub fn backend(&self) -> &dyn Backend

Borrow the backend.

Source

pub fn backend_mut(&mut self) -> &mut dyn Backend

Borrow the backend mutably (e.g. to call poll_event).

Source

pub fn resize(&mut self, width: u16, height: u16)

Resize both buffers to width × height, resetting all content.

Call this when the terminal reports a resize.

Source

pub fn invalidate_all(&mut self)

Force a full terminal repaint on the next render call.

Clears the front (reference) buffer so the next diff sees every cell as changed. Call after Backend::resume — the terminal’s alt-screen is blank, so a full repaint is required.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.