Skip to main content

PaintContext

Struct PaintContext 

Source
pub struct PaintContext<'a> {
    pub theme: &'a Theme,
    pub scale_factor: f32,
    pub text_scale: f32,
    pub layout_direction: LayoutDirection,
    pub effective_enabled: bool,
    pub prefers_high_contrast: bool,
    pub prefers_reduced_motion: bool,
    pub prefers_large_text: bool,
    pub window_active: bool,
    pub clip_bounds: Option<Rect>,
}
Expand description

Context available during painting.

Fields§

§theme: &'a Theme§scale_factor: f32

Accumulated (quantized) scale of the transform scopes enclosing this widget — 1.0 outside any scale transform, the zoom-derived raster ladder value inside a SceneView / Scale wrapper. This is the ambient text raster scale the walker has already set on the shared TextBackend; widgets normally don’t need it (text drawn via Canvas::draw_text / draw_paragraph picks it up automatically), but resolution-dependent custom paint can read it to densify its own raster content. NOT the HiDPI device scale — that lives on the renderer/text-service.

§text_scale: f32

Combined user×OS text-scale factor (1.0 = 100 %) — the logical accessibility magnification, distinct from the raster scale_factor above. Widgets that paint text via Theme.typography already scale through the effective theme; this is for paint paths that size text from another source (e.g. a scene TextItem that opts in). 1.0 when no scale is active.

§layout_direction: LayoutDirection

Active layout direction. Used by widgets that have to resolve Leading/Trailing semantics into geometric Left/Right at paint time (e.g. attached-side shadow suppression on a popover that opened off the trailing edge of its anchor).

§effective_enabled: bool

Whether the widget being painted is effectively enabled — false iff this node or any ancestor has its arena-level enabled_state resolved to false. Computed once per node by the paint walker (start true at root, AND with each node’s enabled_state value as the walker descends).

Leaf widgets that paint role-derived colors (crate::color_prop::ColorProp::TextRole and the dynamic variants) consult this to substitute TextRole::Disabled automatically — the single hook that makes any descendant of a disabled subtree dim without the composite parent doing per-color bookkeeping. Static and bound color props are not substituted (caller’s literal wins).

§prefers_high_contrast: bool§prefers_reduced_motion: bool§prefers_large_text: bool§window_active: bool

Whether the host window is currently active (focused AND not occluded). Widgets that change appearance when the window loses focus read this directly in paint() — the selection band in TableView/TreeTableView desaturates, text engines swap their selection colour, custom paint can dim. A window-active flip triggers a global repaint (WidgetArena::mark_all_needs_paint_only), so no per-widget signal binding is required to keep a paint-time read correct. true in headless test contexts.

§clip_bounds: Option<Rect>

The accumulated clip rectangle this widget is painted within — the intersection of every clips_children ancestor’s bounds (a ScrollArea viewport, a MaxSize, …), in the same screen space as the widget’s own bounds. None when no ancestor clips (the widget can paint anywhere).

The paint walker already computes this to skip fully-offscreen subtrees; surfacing it lets a widget that is laid out larger than its visible slot — an editor at full document height inside an outer ScrollArea (“dubious mode”) — window its own expensive work to clip ∩ bounds instead of processing the whole document. Correct under arbitrary nesting, since it is the intersection of all clipping ancestors.

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for PaintContext<'a>

§

impl<'a> !Send for PaintContext<'a>

§

impl<'a> !Sync for PaintContext<'a>

§

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

§

impl<'a> Freeze for PaintContext<'a>

§

impl<'a> Unpin for PaintContext<'a>

§

impl<'a> UnsafeUnpin for PaintContext<'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 = !

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.