mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -04:00
Add anchored text rotation method, and clarify related docs (#7130)
Add a helper method to perform rotation about a specified anchor. * Closes #7051
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
use std::sync::Arc;
|
||||
|
||||
use emath::{Align2, Rot2};
|
||||
|
||||
use crate::*;
|
||||
|
||||
/// How to paint some text on screen.
|
||||
@@ -78,7 +80,7 @@ impl TextShape {
|
||||
self
|
||||
}
|
||||
|
||||
/// Rotate text by this many radians clockwise.
|
||||
/// Set text rotation to `angle` radians clockwise.
|
||||
/// The pivot is `pos` (the upper left corner of the text).
|
||||
#[inline]
|
||||
pub fn with_angle(mut self, angle: f32) -> Self {
|
||||
@@ -86,6 +88,17 @@ impl TextShape {
|
||||
self
|
||||
}
|
||||
|
||||
/// Set the text rotation to the `angle` radians clockwise.
|
||||
/// The pivot is determined by the given `anchor` point on the text bounding box.
|
||||
#[inline]
|
||||
pub fn with_angle_and_anchor(mut self, angle: f32, anchor: Align2) -> Self {
|
||||
self.angle = angle;
|
||||
let a0 = anchor.pos_in_rect(&self.galley.rect).to_vec2();
|
||||
let a1 = Rot2::from_angle(angle) * a0;
|
||||
self.pos += a0 - a1;
|
||||
self
|
||||
}
|
||||
|
||||
/// Render text with this opacity in gamma space
|
||||
#[inline]
|
||||
pub fn with_opacity_factor(mut self, opacity_factor: f32) -> Self {
|
||||
|
||||
Reference in New Issue
Block a user