Skip to main content

NativePaintCtx

Struct NativePaintCtx 

Source
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 str

Identifies the backend that owns Self::target, for example "lumen.render-wgpu".

§bounds: Rect

The leaf’s bounds in logical window coordinates.

§transform: Affine2

Transform 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: f32

Device pixel ratio between logical coordinates and the target’s pixels.

§opacity: f32

Alpha 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>

Source

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.

Source

pub fn payload_as<T: Any>(&self) -> Option<&'a T>

Borrows the payload as T, or None when the leaf carries something else.

Source

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.

Source

pub fn device_transform(&self) -> Affine2

The transform from logical leaf coordinates to target pixels: the ancestor transform followed by the device-pixel scale.

Auto Trait Implementations§

§

impl<'a> Freeze for NativePaintCtx<'a>

§

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

§

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

§

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

§

impl<'a> Unpin for NativePaintCtx<'a>

§

impl<'a> UnsafeUnpin for NativePaintCtx<'a>

§

impl<'a> !UnwindSafe for NativePaintCtx<'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.

§

impl<T> IntoResult<T> for T

§

fn into_result(self) -> Result<T, RunSystemError>

Converts this type into the system output type.
Source§

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

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.