From 2765848d4346b473317093789ef2c2660993dcd7 Mon Sep 17 00:00:00 2001 From: Justin Bell Date: Wed, 2 Jul 2025 15:46:53 -0500 Subject: [PATCH 1/6] Adding rotation to text --- demo/src/plot_demo.rs | 8 +++++++- egui_plot/src/items/mod.rs | 11 ++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/demo/src/plot_demo.rs b/demo/src/plot_demo.rs index 01d8e219..93f10403 100644 --- a/demo/src/plot_demo.rs +++ b/demo/src/plot_demo.rs @@ -1,6 +1,7 @@ use std::ops::RangeInclusive; use std::{f64::consts::TAU, sync::Arc}; +use eframe::emath::Align2; use egui::{ Checkbox, Color32, ComboBox, NumExt as _, Pos2, Response, ScrollArea, Stroke, TextWrapMode, Vec2b, WidgetInfo, WidgetType, remap, vec2, @@ -852,7 +853,12 @@ impl ItemsDemo { plot_ui.polygon(polygon.name("Convex polygon").id("convex_polygon")); plot_ui.points(points.name("Points with stems").id("points_with_stems")); plot_ui.text(Text::new("Text", PlotPoint::new(-3.0, -3.0), "wow").id("text0")); - plot_ui.text(Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph").id("text1")); + plot_ui.text( + Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph") + .angle(-std::f32::consts::FRAC_PI_4) + .anchor(Align2::CENTER_TOP) + .id("text1") + ); plot_ui.text(Text::new("Text", PlotPoint::new(3.0, 3.0), "much color").id("text2")); plot_ui.text(Text::new("Text", PlotPoint::new(2.5, -2.0), "such plot").id("text3")); plot_ui.image(image.name("Image")); diff --git a/egui_plot/src/items/mod.rs b/egui_plot/src/items/mod.rs index afdfc8ab..a2247dd1 100644 --- a/egui_plot/src/items/mod.rs +++ b/egui_plot/src/items/mod.rs @@ -729,6 +729,7 @@ pub struct Text { pub(super) position: PlotPoint, pub(super) color: Color32, pub(super) anchor: Align2, + pub(super) angle: f32, } impl Text { @@ -739,6 +740,7 @@ impl Text { position, color: Color32::TRANSPARENT, anchor: Align2::CENTER_CENTER, + angle: 0.0, } } @@ -749,6 +751,13 @@ impl Text { self } + /// Text rotation angle. + #[inline] + pub fn angle(mut self, angle: f32) -> Self { + self.angle = angle; + self + } + /// Anchor position of the text. Default is `Align2::CENTER_CENTER`. #[inline] pub fn anchor(mut self, anchor: Align2) -> Self { @@ -777,7 +786,7 @@ impl PlotItem for Text { let pos = transform.position_from_point(&self.position); let rect = self.anchor.anchor_size(pos, galley.size()); - shapes.push(TextShape::new(rect.min, galley, color).into()); + shapes.push(TextShape::new(rect.min, galley, color).with_angle(self.angle).into()); if self.base.highlight { shapes.push(Shape::rect_stroke( From 1a28072e9a68fcf96b1dcd98750c54c4b93deb29 Mon Sep 17 00:00:00 2001 From: Justin Bell Date: Wed, 2 Jul 2025 16:03:23 -0500 Subject: [PATCH 2/6] Addressing linter recommendations --- demo/src/plot_demo.rs | 7 +++++-- egui_plot/src/items/mod.rs | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/demo/src/plot_demo.rs b/demo/src/plot_demo.rs index 93f10403..9ea39dd1 100644 --- a/demo/src/plot_demo.rs +++ b/demo/src/plot_demo.rs @@ -1,12 +1,15 @@ +use eframe::emath::Align2; use std::ops::RangeInclusive; use std::{f64::consts::TAU, sync::Arc}; -use eframe::emath::Align2; use egui::{ Checkbox, Color32, ComboBox, NumExt as _, Pos2, Response, ScrollArea, Stroke, TextWrapMode, Vec2b, WidgetInfo, WidgetType, remap, vec2, }; +use std::f64::consts::TAU; +use std::ops::RangeInclusive; + use egui_plot::{ Arrows, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter, Corner, GridInput, GridMark, HLine, Legend, Line, LineStyle, MarkerShape, Plot, PlotImage, PlotPoint, @@ -857,7 +860,7 @@ impl ItemsDemo { Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph") .angle(-std::f32::consts::FRAC_PI_4) .anchor(Align2::CENTER_TOP) - .id("text1") + .id("text1"), ); plot_ui.text(Text::new("Text", PlotPoint::new(3.0, 3.0), "much color").id("text2")); plot_ui.text(Text::new("Text", PlotPoint::new(2.5, -2.0), "such plot").id("text3")); diff --git a/egui_plot/src/items/mod.rs b/egui_plot/src/items/mod.rs index a2247dd1..6628bda1 100644 --- a/egui_plot/src/items/mod.rs +++ b/egui_plot/src/items/mod.rs @@ -786,7 +786,11 @@ impl PlotItem for Text { let pos = transform.position_from_point(&self.position); let rect = self.anchor.anchor_size(pos, galley.size()); - shapes.push(TextShape::new(rect.min, galley, color).with_angle(self.angle).into()); + shapes.push( + TextShape::new(rect.min, galley, color) + .with_angle(self.angle) + .into(), + ); if self.base.highlight { shapes.push(Shape::rect_stroke( From 86fc77603051a5ed9b6de70cde0da4f9e73e703f Mon Sep 17 00:00:00 2001 From: Justin Bell Date: Mon, 7 Jul 2025 06:27:16 -0500 Subject: [PATCH 3/6] Reintroducing original "so graph" text label, adding name attribute for plot differentiation --- demo/src/plot_demo.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/demo/src/plot_demo.rs b/demo/src/plot_demo.rs index 9ea39dd1..ba5c0dbb 100644 --- a/demo/src/plot_demo.rs +++ b/demo/src/plot_demo.rs @@ -856,11 +856,13 @@ impl ItemsDemo { plot_ui.polygon(polygon.name("Convex polygon").id("convex_polygon")); plot_ui.points(points.name("Points with stems").id("points_with_stems")); plot_ui.text(Text::new("Text", PlotPoint::new(-3.0, -3.0), "wow").id("text0")); + plot_ui.text(Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph").id("text1")); plot_ui.text( - Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph") + Text::new("Text", PlotPoint::new(-2.0, 2.5), "Very angle") .angle(-std::f32::consts::FRAC_PI_4) .anchor(Align2::CENTER_TOP) - .id("text1"), + .name("Angled text") + .id("text_angled"), ); plot_ui.text(Text::new("Text", PlotPoint::new(3.0, 3.0), "much color").id("text2")); plot_ui.text(Text::new("Text", PlotPoint::new(2.5, -2.0), "such plot").id("text3")); From a969f5a6953cfea8fd0269d5a7aa4ee92bd29f97 Mon Sep 17 00:00:00 2001 From: Justin Bell Date: Mon, 7 Jul 2025 06:29:10 -0500 Subject: [PATCH 4/6] Adding CENTER_CENTER pivot; documenting usage and effective behavior of rotation angle --- egui_plot/src/items/mod.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/egui_plot/src/items/mod.rs b/egui_plot/src/items/mod.rs index 6628bda1..88a7dba5 100644 --- a/egui_plot/src/items/mod.rs +++ b/egui_plot/src/items/mod.rs @@ -751,7 +751,9 @@ impl Text { self } - /// Text rotation angle. + /// Sets the text rotation angle. Angles are defined in radians, with positive values + /// resulting in a clockwise direction. Rotations are performed about the center of the + /// bounding box. #[inline] pub fn angle(mut self, angle: f32) -> Self { self.angle = angle; @@ -788,7 +790,7 @@ impl PlotItem for Text { shapes.push( TextShape::new(rect.min, galley, color) - .with_angle(self.angle) + .with_angle_and_anchor(self.angle, Align2::CENTER_CENTER) .into(), ); From 1ddc250e078ec8ad40ba5c045fbeac22b0c8a3cd Mon Sep 17 00:00:00 2001 From: Justin Bell Date: Mon, 7 Jul 2025 06:30:03 -0500 Subject: [PATCH 5/6] Positioning demo label to avoid existing "so graph" label, updating anchor to better demonstrate how it affects positioning --- demo/src/plot_demo.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/demo/src/plot_demo.rs b/demo/src/plot_demo.rs index ba5c0dbb..151a83b4 100644 --- a/demo/src/plot_demo.rs +++ b/demo/src/plot_demo.rs @@ -858,9 +858,9 @@ impl ItemsDemo { plot_ui.text(Text::new("Text", PlotPoint::new(-3.0, -3.0), "wow").id("text0")); plot_ui.text(Text::new("Text", PlotPoint::new(-2.0, 2.5), "so graph").id("text1")); plot_ui.text( - Text::new("Text", PlotPoint::new(-2.0, 2.5), "Very angle") + Text::new("Text", PlotPoint::new(-1.5, 2.0), "Very angle") .angle(-std::f32::consts::FRAC_PI_4) - .anchor(Align2::CENTER_TOP) + .anchor(Align2::LEFT_TOP) .name("Angled text") .id("text_angled"), ); From ee8323ecfe3160fc7376a8d64933e7bff62ef9f3 Mon Sep 17 00:00:00 2001 From: Michal Sustr Date: Sat, 22 Nov 2025 10:16:08 +0100 Subject: [PATCH 6/6] Rebase fixes --- demo/src/plot_demo.rs | 3 --- 1 file changed, 3 deletions(-) diff --git a/demo/src/plot_demo.rs b/demo/src/plot_demo.rs index 151a83b4..7c39157e 100644 --- a/demo/src/plot_demo.rs +++ b/demo/src/plot_demo.rs @@ -7,9 +7,6 @@ use egui::{ Vec2b, WidgetInfo, WidgetType, remap, vec2, }; -use std::f64::consts::TAU; -use std::ops::RangeInclusive; - use egui_plot::{ Arrows, AxisHints, Bar, BarChart, BoxElem, BoxPlot, BoxSpread, CoordinatesFormatter, Corner, GridInput, GridMark, HLine, Legend, Line, LineStyle, MarkerShape, Plot, PlotImage, PlotPoint,