Struct kas_core::layout::LogicalSize
source · Expand description
Logical (pre-scaling) pixel size
A measure of size in “logical pixels”. May be used to define scalable layouts.
Tuple Fields§
§0: f32
§1: f32
Implementations§
source§impl LogicalSize
impl LogicalSize
sourcepub fn to_physical(self, scale_factor: f32) -> Size
pub fn to_physical(self, scale_factor: f32) -> Size
Convert to physical pixels
Values are multiplied by the window’s scale factor and cast to nearest.
Examples found in repository?
src/layout/size_types.rs (line 258)
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
pub fn size_rules(&mut self, mgr: SizeMgr, axis: AxisInfo) -> SizeRules {
let margins = mgr.margins(self.margins).extract(axis);
let scale_factor = mgr.scale_factor();
let min = self
.size
.to_physical(scale_factor * self.min_factor)
.extract(axis);
let ideal = self
.size
.to_physical(scale_factor * self.ideal_factor)
.extract(axis);
self.align.set_component(axis, axis.align_or_center());
SizeRules::new(min, ideal, margins, self.stretch)
}
/// Constrains and aligns within `rect`
///
/// The resulting size is then aligned using the `align` hints, defaulting to centered.
pub fn align_rect(&mut self, rect: Rect, scale_factor: f32) -> Rect {
let mut size = rect.size;
if self.stretch == Stretch::None {
let ideal = self.size.to_physical(scale_factor * self.ideal_factor);
size = size.min(ideal);
}
if self.fix_aspect {
let logical_size = Vec2::from(self.size);
let Vec2(rw, rh) = Vec2::conv(size) / logical_size;
// Use smaller ratio, if any is finite
if rw < rh {
size.1 = i32::conv_nearest(rw * logical_size.1);
} else if rh < rw {
size.0 = i32::conv_nearest(rh * logical_size.0);
}
}
self.align.aligned_rect(size, rect)
}
sourcepub fn to_rules(self, dir: impl Directional, scale_factor: f32) -> SizeRules
pub fn to_rules(self, dir: impl Directional, scale_factor: f32) -> SizeRules
Convert to SizeRules
, fixed size
sourcepub fn to_rules_with_factor(
self,
dir: impl Directional,
scale_factor: f32,
ideal_factor: f32
) -> SizeRules
pub fn to_rules_with_factor(
self,
dir: impl Directional,
scale_factor: f32,
ideal_factor: f32
) -> SizeRules
Convert to SizeRules
Ideal size is component * ideal_factor * scale_factor
.
sourcepub fn extract(self, dir: impl Directional) -> f32
pub fn extract(self, dir: impl Directional) -> f32
Take horizontal/vertical axis component
sourcepub fn extract_scaled(self, dir: impl Directional, scale_factor: f32) -> i32
pub fn extract_scaled(self, dir: impl Directional, scale_factor: f32) -> i32
Take component and scale
Examples found in repository?
src/layout/size_types.rs (line 38)
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
pub fn to_rules(self, dir: impl Directional, scale_factor: f32) -> SizeRules {
SizeRules::fixed(self.extract_scaled(dir, scale_factor), (0, 0))
}
/// Convert to [`SizeRules`]
///
/// Ideal size is `component * ideal_factor * scale_factor`.
pub fn to_rules_with_factor(
self,
dir: impl Directional,
scale_factor: f32,
ideal_factor: f32,
) -> SizeRules {
let min = self.extract_scaled(dir, scale_factor);
let ideal = self.extract_scaled(dir, scale_factor * ideal_factor);
SizeRules::new(min, ideal, (0, 0), Stretch::None)
}
Trait Implementations§
source§impl Clone for LogicalSize
impl Clone for LogicalSize
source§fn clone(&self) -> LogicalSize
fn clone(&self) -> LogicalSize
Returns a copy of the value. Read more
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moresource§impl Conv<Size> for LogicalSize
impl Conv<Size> for LogicalSize
source§impl Debug for LogicalSize
impl Debug for LogicalSize
source§impl Default for LogicalSize
impl Default for LogicalSize
source§fn default() -> LogicalSize
fn default() -> LogicalSize
Returns the “default value” for a type. Read more
source§impl<'de> Deserialize<'de> for LogicalSize
impl<'de> Deserialize<'de> for LogicalSize
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl From<LogicalSize> for Vec2
impl From<LogicalSize> for Vec2
source§fn from(LogicalSize: LogicalSize) -> Self
fn from(LogicalSize: LogicalSize) -> Self
Converts to this type from the input type.
source§impl From<Vec2> for LogicalSize
impl From<Vec2> for LogicalSize
source§impl PartialEq<LogicalSize> for LogicalSize
impl PartialEq<LogicalSize> for LogicalSize
source§fn eq(&self, other: &LogicalSize) -> bool
fn eq(&self, other: &LogicalSize) -> bool
This method tests for
self
and other
values to be equal, and is used
by ==
.source§impl Serialize for LogicalSize
impl Serialize for LogicalSize
impl Copy for LogicalSize
impl StructuralPartialEq for LogicalSize
Auto Trait Implementations§
impl RefUnwindSafe for LogicalSize
impl Send for LogicalSize
impl Sync for LogicalSize
impl Unpin for LogicalSize
impl UnwindSafe for LogicalSize
Blanket Implementations§
source§impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
impl<S, T> CastApprox<T> for Swhere
T: ConvApprox<S>,
source§fn try_cast_approx(self) -> Result<T, Error>
fn try_cast_approx(self) -> Result<T, Error>
source§fn cast_approx(self) -> T
fn cast_approx(self) -> T
source§impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
impl<S, T> CastFloat<T> for Swhere
T: ConvFloat<S>,
source§fn cast_trunc(self) -> T
fn cast_trunc(self) -> T
Cast to integer, truncating Read more
source§fn cast_nearest(self) -> T
fn cast_nearest(self) -> T
Cast to the nearest integer Read more
source§fn cast_floor(self) -> T
fn cast_floor(self) -> T
Cast the floor to an integer Read more