pub struct NativePaintCtx<'a> {
pub backend_id: &'static str,
pub bounds: Rect,
pub transform: Affine2,
pub dpr: f32,
pub opacity: f32,
/* private fields */
}Expand description
What a backend hands a NativePainter for one leaf.
Both the payload and the draw target are type-erased, which is what keeps this crate free of
backend dependencies. A painter downcasts the payload to the type its extension_id promises
and the target to the type the backend named in Self::backend_id; a painter that does not
recognise the backend draws nothing.
Fields§
§backend_id: &'static strIdentifies the backend that owns Self::target, for example "lumen.render-wgpu".
bounds: RectThe leaf’s bounds in logical window coordinates.
transform: Affine2Transform accumulated from ancestor transform nodes, in logical coordinates. The tree
builder emits no transform nodes today, so this is the identity for now; compose through
Self::device_transform rather than assuming it.
dpr: f32Device pixel ratio between logical coordinates and the target’s pixels.
opacity: f32Alpha multiplier accumulated from ancestor opacity nodes.
The painter is the only thing that applies it. A bounds clip composites nothing, so asking
to be clipped never changes a leaf’s alpha. An ancestor that fades as a group is a layer the
backend composites over whatever the painter draws, so it never reaches this figure, which is
1.0 for every leaf the tree builder places; the way to honour CSS opacity is to fold
NativePlacement::opacity into the payload at extract, which is what the built-in
extractors do with their own colours.
Implementations§
Source§impl<'a> NativePaintCtx<'a>
impl<'a> NativePaintCtx<'a>
Sourcepub fn new(
payload: &'a (dyn Any + Send + Sync),
target: &'a mut dyn Any,
backend_id: &'static str,
bounds: Rect,
transform: Affine2,
dpr: f32,
opacity: f32,
) -> Self
pub fn new( payload: &'a (dyn Any + Send + Sync), target: &'a mut dyn Any, backend_id: &'static str, bounds: Rect, transform: Affine2, dpr: f32, opacity: f32, ) -> Self
Builds a context around one leaf’s payload and the backend’s draw target.
Sourcepub fn payload_as<T: Any>(&self) -> Option<&'a T>
pub fn payload_as<T: Any>(&self) -> Option<&'a T>
Borrows the payload as T, or None when the leaf carries something else.
Sourcepub fn target_as<T: Any>(&mut self) -> Option<&mut T>
pub fn target_as<T: Any>(&mut self) -> Option<&mut T>
Borrows the draw target as T, or None when this backend’s target is something else.
Sourcepub fn device_transform(&self) -> Affine2
pub fn device_transform(&self) -> Affine2
The transform from logical leaf coordinates to target pixels: the ancestor transform followed by the device-pixel scale.