Skip to main content

ShadowCache

Struct ShadowCache 

Source
pub struct ShadowCache { /* private fields */ }
Expand description

Rendered shadows, most recently used last.

Implementations§

Source§

impl ShadowCache

Source

pub fn new(capacity: usize) -> Self

A cache holding capacity shadows.

Zero is treated as DEFAULT_CAPACITY: a cache that held nothing would re-blur every shadow every frame, which is the cost this type exists to remove.

Source

pub fn len(&self) -> usize

How many shadows are cached.

Source

pub fn is_empty(&self) -> bool

Whether nothing is cached.

Source

pub const fn capacity(&self) -> usize

How many it will hold.

Source

pub fn contains(&self, key: &ShadowKey) -> bool

Whether this shadow is already rendered.

Source

pub fn clear(&mut self)

Forget everything.

For a theme change that invalidates every shadow at once, where evicting one at a time would blur each of them again on the way out.

Source

pub fn blit_into( &mut self, key: ShadowKey, theme: &Theme, dst: &mut ShadowDest<'_>, ) -> bool

Composite this shadow onto dst, rendering it first if it is not cached.

Source-over, in premultiplied alpha, as the reference composites it: what is already in dst shows through where the shadow is not opaque. On a cleared buffer that is the same as a copy.

Returns false, writing nothing, for a zero-sized key or destination, and true otherwise — rather than failing: a window being resized passes through zero, and a decoration that errored on the way would flicker.

A destination smaller than the patch is clipped, not refused — the alternative is writing past the caller’s buffer. Rows that do not fit in pixels at stride are skipped too, and the call still returns true.

Source

pub fn blit_cross_fade( &mut self, a: ShadowKey, b: ShadowKey, theme: &Theme, dst: &mut ShadowDest<'_>, t: f32, ) -> bool

Composite a blend of two shadows, t of the way from a to b, onto dst.

What a focus change animates through. Both patches are cached, so the transition costs a per-pixel lerp rather than a blur per frame — given a capacity of at least two. With a capacity of one, rendering b evicts a, and a mid-transition blend draws nothing and returns false. The blend is composited source-over, as blit_into is, and the endpoints are exactly blit_into of one patch.

t is clamped to 0..=1: an animation that overshoots is a caller bug, and extrapolating a color past its endpoints produces values that are not a shadow at all.

The two keys must be the same size, as the reference requires; keys that differ write nothing and return false. Otherwise the return is as for blit_into: false, writing nothing, for a zero-sized key or destination, and true once the blend is composited.

Trait Implementations§

Source§

impl Debug for ShadowCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ShadowCache

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

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.