pub struct DesignMapping {
pub design: [f32; 2],
pub canvas_dp: [f32; 2],
pub policy: DesignFit,
}Expand description
A design box mapped onto a dp canvas under one DesignFit policy: the
scale, the offsets it implies, the inverse, and the snapping rule. Build it
per frame, or on resize, from the measured canvas and the game’s design
size.
Degenerate sides (<= 0.0: the state before the first measure) fall back
exactly like contain_fit / cover_fit: scale 1.0, offsets 0.0,
so the mapping is the identity on design units and visible reports that
canvas over 1.0. Sides so far apart that the ratio underflows past the
shared 1e-6 guard read the same way. A non-finite side is not repaired:
it surfaces in the offsets rather than being replaced by an invented
number.
Fields§
§design: [f32; 2]Design box in design units.
canvas_dp: [f32; 2]Measured canvas in dp.
policy: DesignFitWhich ratio wins.
Implementations§
Source§impl DesignMapping
impl DesignMapping
Sourcepub fn contain(canvas_dp: [f32; 2], design: [f32; 2]) -> Self
pub fn contain(canvas_dp: [f32; 2], design: [f32; 2]) -> Self
Contain, the design box fully visible. Canvas first, matching
contain_fit.
Sourcepub fn cover(canvas_dp: [f32; 2], design: [f32; 2]) -> Self
pub fn cover(canvas_dp: [f32; 2], design: [f32; 2]) -> Self
Cover, the canvas fully filled and the overflow cropped. Canvas first,
matching cover_fit.
Sourcepub fn scale(&self) -> f32
pub fn scale(&self) -> f32
dp per design unit for this policy: the games’ grid_scale /
ui_scale under DesignFit::Contain, world_scale under
DesignFit::Cover.
Sourcepub fn fit(&self) -> (f32, f32, f32)
pub fn fit(&self) -> (f32, f32, f32)
The (scale, offset_x, offset_y) tuple the framing functions take. With
the default centered camera the design origin lands at the offsets, so
this tuple feeds fit_view_proj_with_roll,
world_to_dp and picks alike; under
DesignFit::Cover the offsets are negative on the cropped axis.
Sourcepub fn box_dp(&self) -> [f32; 2]
pub fn box_dp(&self) -> [f32; 2]
The design box scaled to dp at scale: the games’
cover_box under DesignFit::Cover, whose top-left sits at the
offsets fit reports.
Sourcepub fn visible(&self) -> [f32; 2]
pub fn visible(&self) -> [f32; 2]
Design units the canvas shows, the games’ field_size. For a measured
canvas under DesignFit::Contain this is the design box or more (the
roomier axis reveals past it); under DesignFit::Cover it is the
design sub-rect that survives cropping, so content that must stay
visible belongs inside it.
Sourcepub fn design_to_dp(&self, design: [f32; 2]) -> [f32; 2]
pub fn design_to_dp(&self, design: [f32; 2]) -> [f32; 2]
Design units to dp through the fit: offset + design * scale, no
rounding.
Sourcepub fn dp_to_design(&self, dp: [f32; 2]) -> [f32; 2]
pub fn dp_to_design(&self, dp: [f32; 2]) -> [f32; 2]
Inverse of design_to_dp. Exact up to float
error for any scale the fits can report (they never report zero).
Sourcepub fn snap_box(&self, at: [f32; 2], size: [f32; 2]) -> ([f32; 2], [f32; 2])
pub fn snap_box(&self, at: [f32; 2], size: [f32; 2]) -> ([f32; 2], [f32; 2])
Snap a design box onto whole dp: round the converted top-left and
bottom-right corners, then derive the dp extent from the two snapped
corners. Two boxes that share a design-space edge therefore share the
snapped edge exactly, and the extent can never disagree with its own
corners (round(x) + round(w) can, by up to a dp per seam). Opt in:
this is for art that must land on whole dp, not for moving content.
Trait Implementations§
Source§impl Clone for DesignMapping
impl Clone for DesignMapping
impl Copy for DesignMapping
Source§impl Debug for DesignMapping
impl Debug for DesignMapping
Source§impl PartialEq for DesignMapping
impl PartialEq for DesignMapping
impl StructuralPartialEq for DesignMapping
Auto Trait Implementations§
impl Freeze for DesignMapping
impl RefUnwindSafe for DesignMapping
impl Send for DesignMapping
impl Sync for DesignMapping
impl Unpin for DesignMapping
impl UnsafeUnpin for DesignMapping
impl UnwindSafe for DesignMapping
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.