mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-29 13:24:48 +00:00

The code was mixing logical and physical sizes, causing glyphs being doubly scaled down. Instead, this patch introduces: * Physical* and Logical* euclid length/size/rect aliases * some extraction traits for getting the scalars in rects/sizes as lengths (until euclid has them built-in) * wrapper traits/types for safely extracting the physical font metrics the compiler generates (i16) * Fix a bug in the text height calculation where we failed to take the descent into account
87 lines
2.4 KiB
Rust
87 lines
2.4 KiB
Rust
// Copyright © SixtyFPS GmbH <info@slint-ui.com>
|
|
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-commercial
|
|
|
|
pub struct PhysicalPx;
|
|
pub type PhysicalLength = euclid::Length<i16, PhysicalPx>;
|
|
pub type PhysicalRect = euclid::Rect<i16, PhysicalPx>;
|
|
pub type PhysicalSize = euclid::Size2D<i16, PhysicalPx>;
|
|
pub type PhysicalPoint = euclid::Point2D<i16, PhysicalPx>;
|
|
|
|
pub struct LogicalPx;
|
|
pub type LogicalLength = euclid::Length<f32, LogicalPx>;
|
|
pub type LogicalRect = euclid::Rect<f32, LogicalPx>;
|
|
pub type LogicalPoint = euclid::Point2D<f32, LogicalPx>;
|
|
pub type LogicalSize = euclid::Size2D<f32, LogicalPx>;
|
|
|
|
pub type ScaleFactor = euclid::Scale<f32, LogicalPx, PhysicalPx>;
|
|
|
|
pub trait SizeLengths<LengthType> {
|
|
fn width_length(&self) -> LengthType;
|
|
fn height_length(&self) -> LengthType;
|
|
}
|
|
|
|
impl SizeLengths<LogicalLength> for LogicalSize {
|
|
fn width_length(&self) -> LogicalLength {
|
|
LogicalLength::new(self.width)
|
|
}
|
|
|
|
fn height_length(&self) -> LogicalLength {
|
|
LogicalLength::new(self.height)
|
|
}
|
|
}
|
|
|
|
impl SizeLengths<PhysicalLength> for PhysicalSize {
|
|
fn width_length(&self) -> PhysicalLength {
|
|
PhysicalLength::new(self.width)
|
|
}
|
|
|
|
fn height_length(&self) -> PhysicalLength {
|
|
PhysicalLength::new(self.height)
|
|
}
|
|
}
|
|
|
|
pub trait PointLengths<LengthType> {
|
|
fn x_length(&self) -> LengthType;
|
|
fn y_length(&self) -> LengthType;
|
|
}
|
|
|
|
impl PointLengths<LogicalLength> for LogicalPoint {
|
|
fn x_length(&self) -> LogicalLength {
|
|
LogicalLength::new(self.x)
|
|
}
|
|
|
|
fn y_length(&self) -> LogicalLength {
|
|
LogicalLength::new(self.y)
|
|
}
|
|
}
|
|
|
|
impl PointLengths<PhysicalLength> for PhysicalPoint {
|
|
fn x_length(&self) -> PhysicalLength {
|
|
PhysicalLength::new(self.x)
|
|
}
|
|
|
|
fn y_length(&self) -> PhysicalLength {
|
|
PhysicalLength::new(self.y)
|
|
}
|
|
}
|
|
|
|
pub trait RectLengths<SizeType> {
|
|
fn size_length(&self) -> SizeType;
|
|
}
|
|
|
|
impl RectLengths<LogicalSize> for LogicalRect {
|
|
fn size_length(&self) -> LogicalSize {
|
|
let size = self.size;
|
|
LogicalSize::from_lengths(size.width_length(), size.height_length())
|
|
}
|
|
}
|
|
|
|
pub trait LogicalItemGeometry {
|
|
fn logical_geometry(self: core::pin::Pin<&Self>) -> LogicalRect;
|
|
}
|
|
|
|
impl<T: i_slint_core::items::Item> LogicalItemGeometry for T {
|
|
fn logical_geometry(self: core::pin::Pin<&Self>) -> LogicalRect {
|
|
LogicalRect::from_untyped(&self.geometry())
|
|
}
|
|
}
|