1
0
mirror of https://github.com/emilk/egui.git synced 2026-08-30 13:20:05 -04:00

[emath] RectTransform: transforms Pos2 from one Rect to another

Very useful for transforming coordinate systems, e.g. for painting
This commit is contained in:
Emil Ernerfeldt
2021-02-14 10:33:44 +01:00
parent dbc6a620cd
commit c376d0bb7e
8 changed files with 142 additions and 24 deletions

View File

@@ -202,6 +202,29 @@ impl Rect {
pub fn height(&self) -> f32 {
self.max.y - self.min.y
}
/// Width / height
///
/// * `aspect_ratio < 1`: portrait / high
/// * `aspect_ratio = 1`: square
/// * `aspect_ratio > 1`: landscape / wide
pub fn aspect_ratio(&self) -> f32 {
self.width() / self.height()
}
/// `[2, 1]` for wide screen, and `[1, 2]` for portrait, etc.
/// At least one dimension = 1, the other >= 1
/// Returns the proportions required to letter-box a square view area.
pub fn square_proportions(&self) -> Vec2 {
let w = self.width();
let h = self.height();
if w > h {
vec2(w / h, 1.0)
} else {
vec2(1.0, h / w)
}
}
pub fn area(&self) -> f32 {
self.width() * self.height()
}