Skip to main content

Frame

Struct Frame 

Source
pub struct Frame<'a> {
    pub buffer: Buffer,
    pub pool: &'a mut GraphemePool,
    pub links: Option<&'a mut LinkRegistry>,
    pub hit_grid: Option<HitGrid>,
    pub widget_budget: WidgetBudget,
    pub widget_signals: Vec<WidgetSignal>,
    pub cursor_position: Option<(u16, u16)>,
    pub cursor_visible: bool,
    pub degradation: DegradationLevel,
}
Expand description

Frame = Buffer + metadata for a render pass.

The Frame is passed to Model::view() and contains everything needed to render a single frame. The Buffer holds cells; metadata controls cursor and enables mouse hit testing.

§Lifetime

The frame borrows the GraphemePool from the runtime, so it cannot outlive the render pass. This is correct because frames are ephemeral render targets.

Fields§

§buffer: Buffer

The cell grid for this render pass.

§pool: &'a mut GraphemePool

Reference to the grapheme pool for interning strings.

§links: Option<&'a mut LinkRegistry>

Optional reference to link registry for hyperlinks.

§hit_grid: Option<HitGrid>

Optional hit grid for mouse hit testing.

When Some, widgets can register clickable regions.

§widget_budget: WidgetBudget

Widget render budget policy for this frame.

§widget_signals: Vec<WidgetSignal>

Collected per-widget scheduling signals for this frame.

§cursor_position: Option<(u16, u16)>

Cursor position (if app wants to show cursor).

Coordinates are relative to buffer (0-indexed).

§cursor_visible: bool

Whether cursor should be visible.

§degradation: DegradationLevel

Current degradation level from the render budget.

Widgets can read this to skip expensive operations when the budget is constrained (e.g., use ASCII borders instead of Unicode, skip decorative rendering, etc.).

Implementations§

Source§

impl<'a> Frame<'a>

Source

pub fn new(width: u16, height: u16, pool: &'a mut GraphemePool) -> Self

Create a new frame with given dimensions and grapheme pool.

The frame starts with no hit grid and visible cursor at no position.

Source

pub fn from_buffer(buffer: Buffer, pool: &'a mut GraphemePool) -> Self

Create a frame from an existing buffer.

This avoids per-frame buffer allocation when callers reuse buffers.

Create a new frame with grapheme pool and link registry.

This avoids double-borrowing issues when both pool and links come from the same parent struct.

Source

pub fn with_hit_grid( width: u16, height: u16, pool: &'a mut GraphemePool, ) -> Self

Create a frame with hit testing enabled.

The hit grid allows widgets to register clickable regions.

Set the link registry for this frame.

Register a hyperlink URL and return its ID.

Returns 0 if link registry is not available or full.

Source

pub fn set_widget_budget(&mut self, budget: WidgetBudget)

Set the widget render budget for this frame.

Source

pub fn should_render_widget(&self, widget_id: u64, essential: bool) -> bool

Check whether a widget should be rendered under the current budget.

Source

pub fn register_widget_signal(&mut self, signal: WidgetSignal)

Register a widget scheduling signal for this frame.

Source

pub fn widget_signals(&self) -> &[WidgetSignal]

Borrow the collected widget signals.

Source

pub fn take_widget_signals(&mut self) -> Vec<WidgetSignal>

Take the collected widget signals, leaving an empty list.

Source

pub fn intern(&mut self, text: &str) -> GraphemeId

Intern a string in the grapheme pool.

Returns a GraphemeId that can be used to create a Cell. The width is calculated automatically or can be provided if already known.

§Panics

Panics if width > 127.

Source

pub fn intern_with_width(&mut self, text: &str, width: u8) -> GraphemeId

Intern a string with explicit width.

Source

pub fn enable_hit_testing(&mut self)

Enable hit testing on an existing frame.

Source

pub fn width(&self) -> u16

Frame width in cells.

Source

pub fn height(&self) -> u16

Frame height in cells.

Source

pub fn clear(&mut self)

Clear frame for next render.

Resets both the buffer and hit grid (if present).

Source

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

Set cursor position.

Pass None to indicate no cursor should be shown at a specific position.

Source

pub fn set_cursor_visible(&mut self, visible: bool)

Set cursor visibility.

Source

pub fn set_degradation(&mut self, level: DegradationLevel)

Set the degradation level for this frame.

Propagates to the buffer so widgets can read buf.degradation during rendering without needing access to the full Frame.

Source

pub fn bounds(&self) -> Rect

Get the bounding rectangle of the frame.

Source

pub fn register_hit( &mut self, rect: Rect, id: HitId, region: HitRegion, data: HitData, ) -> bool

Register a hit region (if hit grid is enabled).

Returns true if the region was registered, false if no hit grid.

§Clipping

The region is intersected with the current scissor stack of the internal buffer. Parts of the region outside the scissor are ignored.

Source

pub fn hit_test(&self, x: u16, y: u16) -> Option<(HitId, HitRegion, HitData)>

Hit test at the given position (if hit grid is enabled).

Source

pub fn register_hit_region(&mut self, rect: Rect, id: HitId) -> bool

Register a hit region with default metadata (Content, data=0).

Trait Implementations§

Source§

impl<'a> Debug for Frame<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a> Draw for Frame<'a>

Source§

fn draw_horizontal_line(&mut self, x: u16, y: u16, width: u16, cell: Cell)

Draw a horizontal line of cells.
Source§

fn draw_vertical_line(&mut self, x: u16, y: u16, height: u16, cell: Cell)

Draw a vertical line of cells.
Source§

fn draw_rect_filled(&mut self, rect: Rect, cell: Cell)

Draw a filled rectangle.
Source§

fn draw_rect_outline(&mut self, rect: Rect, cell: Cell)

Draw a rectangle outline using a single cell character.
Source§

fn print_text(&mut self, x: u16, y: u16, text: &str, base_cell: Cell) -> u16

Print text at the given coordinates using the cell’s colors/attrs. Read more
Source§

fn print_text_clipped( &mut self, x: u16, y: u16, text: &str, base_cell: Cell, max_x: u16, ) -> u16

Print text with a right-side clipping boundary. Read more
Source§

fn draw_border(&mut self, rect: Rect, chars: BorderChars, base_cell: Cell)

Draw a border around a rectangle using the given characters. Read more
Source§

fn draw_box( &mut self, rect: Rect, chars: BorderChars, border_cell: Cell, fill_cell: Cell, )

Draw a border and fill the interior. Read more
Source§

fn paint_area( &mut self, rect: Rect, fg: Option<PackedRgba>, bg: Option<PackedRgba>, )

Set all cells in a rectangular area to the given fg/bg/attrs without changing cell content. Read more

Auto Trait Implementations§

§

impl<'a> Freeze for Frame<'a>

§

impl<'a> RefUnwindSafe for Frame<'a>

§

impl<'a> Send for Frame<'a>

§

impl<'a> Sync for Frame<'a>

§

impl<'a> Unpin for Frame<'a>

§

impl<'a> !UnwindSafe for Frame<'a>

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
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.