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:
- Resets the back buffer.
- Runs the paint closure into the back buffer.
- Diffs the back buffer against the front buffer.
- Pushes changed cells to the backend.
- Sets the cursor and, while it is shown, the caret size.
- Flushes.
- 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
impl Renderer
Sourcepub fn new(backend: Box<dyn Backend>) -> Self
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.
Sourcepub fn render(&mut self, paint: impl FnOnce(&mut Buffer))
pub fn render(&mut self, paint: impl FnOnce(&mut Buffer))
Run one frame cycle.
- Resets the back buffer to blank.
- Calls
paintwith a mutable reference to the back buffer. - Diffs the back buffer against the front buffer.
- Pushes changed cells to the backend.
- Sets the cursor and, while it is shown, the caret size.
- Flushes.
- 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.
Sourcepub fn set_cursor(&mut self, pos: Option<(u16, u16)>)
pub fn set_cursor(&mut self, pos: Option<(u16, u16)>)
Set the desired cursor position (used by the next render call).
Sourcepub fn set_caret_size(&mut self, size: u8)
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.
Sourcepub fn backend_mut(&mut self) -> &mut dyn Backend
pub fn backend_mut(&mut self) -> &mut dyn Backend
Borrow the backend mutably (e.g. to call poll_event).
Sourcepub fn resize(&mut self, width: u16, height: u16)
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.
Sourcepub fn invalidate_all(&mut self)
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§
impl !RefUnwindSafe for Renderer
impl !Send for Renderer
impl !Sync for Renderer
impl !UnwindSafe for Renderer
impl Freeze for Renderer
impl Unpin for Renderer
impl UnsafeUnpin for Renderer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.