1
0
mirror of https://github.com/emilk/egui.git synced 2026-06-26 22:53:14 -04:00

rotation feature to plot images (#3121)

This commit is contained in:
Roshan Mehta
2023-08-10 00:50:25 -07:00
committed by GitHub
parent f2a58244c8
commit 01b1b2da76

View File

@@ -1132,6 +1132,7 @@ pub struct PlotImage {
pub(super) tint: Color32,
pub(super) highlight: bool,
pub(super) name: String,
pub(crate) rotation: Option<(f32, Vec2)>,
}
impl PlotImage {
@@ -1150,6 +1151,7 @@ impl PlotImage {
size: size.into(),
bg_fill: Default::default(),
tint: Color32::WHITE,
rotation: None,
}
}
@@ -1188,6 +1190,17 @@ impl PlotImage {
self.name = name.to_string();
self
}
/// Rotate the image about an origin by some angle
///
/// Positive angle is clockwise.
/// Origin is a vector in normalized UV space ((0,0) in top-left, (1,1) bottom right).
///
/// To rotate about the center you can pass `Vec2::splat(0.5)` as the origin.
pub fn rotate(mut self, angle: f32, origin: Vec2) -> Self {
self.rotation = Some((angle, origin));
self
}
}
impl PlotItem for PlotImage {
@@ -1215,11 +1228,14 @@ impl PlotItem for PlotImage {
let right_bottom_tf = transform.position_from_point(&right_bottom);
Rect::from_two_pos(left_top_tf, right_bottom_tf)
};
Image::new(*texture_id, *size)
let mut image = Image::new(*texture_id, *size)
.bg_fill(*bg_fill)
.tint(*tint)
.uv(*uv)
.paint_at(ui, rect);
.uv(*uv);
if let Some((angle, origin)) = self.rotation {
image = image.rotate(angle, origin);
}
image.paint_at(ui, rect);
if *highlight {
shapes.push(Shape::rect_stroke(
rect,