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: f32Accumulated (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: f32Combined 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: LayoutDirectionActive 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: boolWhether 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: boolWhether 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.