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

Implement rotating text

Closes https://github.com/emilk/egui/issues/428
This commit is contained in:
Emil Ernerfeldt
2021-09-05 09:06:53 +02:00
parent 6902151a96
commit 14c989fdfa
12 changed files with 112 additions and 69 deletions

View File

@@ -150,6 +150,21 @@ impl Rect {
Rect::from_min_size(self.min + amnt, self.size())
}
/// Rotate the bounds (will expand the `Rect`)
#[must_use]
#[inline]
pub fn rotate_bb(self, rot: crate::Rot2) -> Self {
let a = rot * self.left_top().to_vec2();
let b = rot * self.right_top().to_vec2();
let c = rot * self.left_bottom().to_vec2();
let d = rot * self.right_bottom().to_vec2();
Self::from_min_max(
a.min(b).min(c).min(d).to_pos2(),
a.max(b).max(c).max(d).to_pos2(),
)
}
/// The intersection of two `Rect`, i.e. the area covered by both.
#[must_use]
pub fn intersect(self, other: Rect) -> Self {

View File

@@ -33,6 +33,7 @@ impl Rot2 {
/// The identity rotation: nothing rotates
pub const IDENTITY: Self = Self { s: 0.0, c: 1.0 };
/// Angle is clockwise in radians.
/// A 𝞃/4 = 90° rotation means rotating the X axis to the Y axis.
pub fn from_angle(angle: f32) -> Self {
let (s, c) = angle.sin_cos();

View File

@@ -183,7 +183,7 @@ impl Vec2 {
self.y.atan2(self.x)
}
/// Create a unit vector with the given angle (in radians).
/// Create a unit vector with the given CW angle (in radians).
/// * An angle of zero gives the unit X axis.
/// * An angle of 𝞃/4 = 90° gives the unit Y axis.
///