Skip to main content

PaintCtx

Struct PaintCtx 

Source
pub struct PaintCtx<'a, State> {
    pub theme: &'a Theme,
    /* private fields */
}
Expand description

Everything painting one declaration needs: where to draw, what to draw with, and where that declaration sits in this frame’s interaction.

Component::paint gets one, and so does every closure queued with DeclareCtx::paint. Both run during the replay that follows the declaration walk, which is why this context can declare nothing: by the time it exists the tree is closed and focus is resolved. That is also the only reason it can carry the four interaction flags at all — they are derived from that resolution, and there is nothing to derive them from while the tree is still being built.

Painting goes through widget, stateful_widget, and with_buffer. The context keeps the frame’s buffer to itself, so a paint call can read ctx.theme, ctx.state(), and the interaction flags while building its widget argument.

Fields§

§theme: &'a Theme

The active theme supplied to Ratcn::render.

Implementations§

Source§

impl<'a, State> PaintCtx<'a, State>

Source

pub fn widget(&mut self, widget: impl Widget, area: Rect)

Paint a ratatui widget onto the active paint surface.

The widget is consumed here; nothing is deferred or allocated. Because the context never lends out the buffer, the widget expression may read ctx freely (ctx.theme, state, interaction flags) in argument position.

Inside a modal, popup, or hint layer the paint lands on that layer’s canvas and composites above everything declared outside it; otherwise it lands on the frame. A layer composites the widget’s whole declared area opaquely — cells the widget left unwritten come through as empty rather than transparent, so paint a panel background first, as the built-in layers do.

Source

pub fn stateful_widget<W: StatefulWidget>( &mut self, widget: W, area: Rect, state: &mut W::State, )

Paint a ratatui stateful widget onto the active paint surface.

The escape hatch for widgets that need a &mut widget state during paint (e.g. ratatui’s List with ListState). Targets the same surface as widget.

Source

pub fn with_buffer<R>(&mut self, paint: impl FnOnce(&mut Buffer) -> R) -> R

Run a paint closure over the active paint surface’s raw cell buffer.

The escape hatch for direct cell writes (set_string, set_style, per-cell edits). The closure receives only the buffer, so values read from ctx must be taken as arguments or moved in. Inside a layer, the buffer is the layer’s canvas and the whole layer footprint counts as painted for compositing.

Source

pub const fn area(&self) -> Rect

The area of the declaration this paint belongs to: a component’s paint allocation, or the DeclareCtx::area a queued closure was reached with.

Source

pub const fn focused(&self) -> bool

This declaration is the focused leaf.

Source

pub const fn contains_focus(&self) -> bool

The focus path passes through or ends at this declaration (the focus-within signal for e.g. pane border highlighting).

Source

pub const fn hovered(&self) -> bool

This declaration is the hovered leaf. Independent of focused: a component can be hovered without being focused, and vice versa.

Source

pub const fn contains_hover(&self) -> bool

The hover path passes through or ends at this declaration (the hover-within signal).

Source

pub const fn hover_position(&self) -> Option<Position>

The pointer position from the most recent mouse event, if it is still inside the terminal.

Raw geometry, for paint that has to know where in the declaration the pointer is — which row of a list, which tab of a row — rather than merely whether it is inside, which hovered and contains_hover already answer.

Source

pub const fn state(&self) -> &'a State

The app state the pass was declared with.

Trait Implementations§

Source§

impl<State> Debug for PaintCtx<'_, State>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a, State> !UnwindSafe for PaintCtx<'a, State>

§

impl<'a, State> Freeze for PaintCtx<'a, State>

§

impl<'a, State> RefUnwindSafe for PaintCtx<'a, State>

§

impl<'a, State> Send for PaintCtx<'a, State>
where &'a State: Send,

§

impl<'a, State> Sync for PaintCtx<'a, State>
where &'a State: Sync,

§

impl<'a, State> Unpin for PaintCtx<'a, State>

§

impl<'a, State> UnsafeUnpin for PaintCtx<'a, State>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.