pub struct LogicalSize(pub f32, pub f32);
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§

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)
    }

Convert to SizeRules, fixed size

Convert to SizeRules

Ideal size is component * ideal_factor * scale_factor.

Take horizontal/vertical axis component

Examples found in repository?
src/layout/size_types.rs (line 65)
64
65
66
    pub fn extract_scaled(self, dir: impl Directional, scale_factor: f32) -> i32 {
        (self.extract(dir) * scale_factor).cast_nearest()
    }

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§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Try converting from T to Self Read more
Convert from T to Self Read more
Try converting from T to Self Read more
Convert from T to Self Read more
Try converting from T to Self Read more
Convert from T to Self Read more
Formats the value using the given formatter. Read more
Returns the “default value” for a type. Read more
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
Converts to this type from the input type.
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==.
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Cast from Self to T Read more
Try converting from Self to T Read more
Try approximate conversion from Self to T Read more
Cast approximately from Self to T Read more
Cast to integer, truncating Read more
Cast to the nearest integer Read more
Cast the floor to an integer Read more
Cast the ceiling to an integer Read more
Try converting to integer with truncation Read more
Try converting to the nearest integer Read more
Try converting the floor to an integer Read more
Try convert the ceiling to an integer Read more
Try converting from T to Self, allowing approximation of value Read more
Converting from T to Self, allowing approximation of value Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.