pub struct AdjustedImageSource {
x0: f32,
y0: f32,
x1: f32,
y1: f32,
}
Expand description
Represents an adjustment to apply to an image primitive. This can be used to compensate for a difference between the bounds of the images expected by the primitive and the bounds that were actually drawn in the texture cache.
This happens when rendering snapshot images: A picture is marked so that a specific reference area in layout space can be rendered as an image. However, the bounds of the rasterized area of the picture typically differ from that reference area.
The adjustment is stored as 4 floats (x0, y0, x1, y1) that represent a transformation of the primitve’s local rect such that:
adjusted_rect.min = prim_rect.min + prim_rect.size() * (x0, y0);
adjusted_rect.max = prim_rect.max + prim_rect.size() * (x1, y1);
Fields§
§x0: f32
§y0: f32
§x1: f32
§y1: f32
Implementations§
Source§impl AdjustedImageSource
impl AdjustedImageSource
Sourcepub fn from_rects(reference: &LayoutRect, actual: &LayoutRect) -> Self
pub fn from_rects(reference: &LayoutRect, actual: &LayoutRect) -> Self
An adjustment to render an image item defined in function of the reference
rect whereas the actual
rect was cached instead.
Sourcepub fn map_local_rect(&self, rect: &LayoutRect) -> LayoutRect
pub fn map_local_rect(&self, rect: &LayoutRect) -> LayoutRect
Adjust the primitive’s local rect.
Sourcepub fn map_stretch_size(&self, size: LayoutSize) -> LayoutSize
pub fn map_stretch_size(&self, size: LayoutSize) -> LayoutSize
The stretch size has to be adjusted as well because it is defined using the snapshot area as reference but will stretch the rasterized area instead.
It has to be scaled by a factor of (adjusted.size() / prim_rect.size()). We derive the formula in function of the adjustment factors:
factor = (adjusted.max - adjusted.min) / (w, h)
= (rect.max + (w, h) * (x1, y1) - (rect.min + (w, h) * (x0, y0))) / (w, h)
= ((w, h) + (w, h) * (x1, y1) - (w, h) * (x0, y0)) / (w, h)
= (1.0, 1.0) + (x1, y1) - (x0, y0)
Trait Implementations§
Source§impl Clone for AdjustedImageSource
impl Clone for AdjustedImageSource
Source§fn clone(&self) -> AdjustedImageSource
fn clone(&self) -> AdjustedImageSource
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moreSource§impl Debug for AdjustedImageSource
impl Debug for AdjustedImageSource
Source§impl Serialize for AdjustedImageSource
impl Serialize for AdjustedImageSource
impl Copy for AdjustedImageSource
Auto Trait Implementations§
impl Freeze for AdjustedImageSource
impl RefUnwindSafe for AdjustedImageSource
impl Send for AdjustedImageSource
impl Sync for AdjustedImageSource
impl Unpin for AdjustedImageSource
impl UnwindSafe for AdjustedImageSource
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more