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 ThemeThe active theme supplied to Ratcn::render.
Implementations§
Source§impl<'a, State> PaintCtx<'a, State>
impl<'a, State> PaintCtx<'a, State>
Sourcepub fn widget(&mut self, widget: impl Widget, area: Rect)
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.
Sourcepub fn stateful_widget<W: StatefulWidget>(
&mut self,
widget: W,
area: Rect,
state: &mut W::State,
)
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.
Sourcepub fn with_buffer<R>(&mut self, paint: impl FnOnce(&mut Buffer) -> R) -> R
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.
Sourcepub const fn area(&self) -> Rect
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.
Sourcepub const fn contains_focus(&self) -> bool
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).
Sourcepub const fn hovered(&self) -> bool
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.
Sourcepub const fn contains_hover(&self) -> bool
pub const fn contains_hover(&self) -> bool
The hover path passes through or ends at this declaration (the
hover-within signal).
Sourcepub const fn hover_position(&self) -> Option<Position>
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.
Trait Implementations§
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>where
&'a State: RefUnwindSafe,
impl<'a, State> Send for PaintCtx<'a, State>
impl<'a, State> Sync for PaintCtx<'a, State>
impl<'a, State> Unpin for PaintCtx<'a, State>
impl<'a, State> UnsafeUnpin for PaintCtx<'a, State>where
&'a State: UnsafeUnpin,
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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