mirror of
https://github.com/emilk/egui.git
synced 2026-08-29 04:40:03 -04:00
Allow rotation of rectangles and ellipses (#7682)
<!-- Please read the "Making a PR" section of [`CONTRIBUTING.md`](https://github.com/emilk/egui/blob/main/CONTRIBUTING.md) before opening a Pull Request! * Keep your PR:s small and focused. * The PR title is what ends up in the changelog, so make it descriptive! * If applicable, add a screenshot or gif. * If it is a non-trivial addition, consider adding a demo for it to `egui_demo_lib`, or a new example. * Do NOT open PR:s from your `master` branch, as that makes it hard for maintainers to test and add commits to your PR. * Remember to run `cargo fmt` and `cargo clippy`. * Open the PR as a draft until you have self-reviewed it and run `./scripts/check.sh`. * When you have addressed a PR comment, mark it as resolved. Please be patient! I will review your PR, but my time is limited! --> Added the ability to rotate rectangles and ellipses. Similar to the existing text implementation * [x ] I have followed the instructions in the PR template
This commit is contained in:
@@ -1546,6 +1546,7 @@ impl Tessellator {
|
||||
radius,
|
||||
fill,
|
||||
stroke,
|
||||
angle,
|
||||
} = shape;
|
||||
|
||||
if radius.x <= 0.0 || radius.y <= 0.0 {
|
||||
@@ -1596,6 +1597,14 @@ impl Tessellator {
|
||||
points.push(center + Vec2::new(0.0, -radius.y));
|
||||
points.extend(quarter.iter().rev().map(|p| center + Vec2::new(p.x, -p.y)));
|
||||
|
||||
// Apply rotation if angle is non-zero
|
||||
if angle != 0.0 {
|
||||
let rot = emath::Rot2::from_angle(angle);
|
||||
for point in &mut points {
|
||||
*point = center + rot * (*point - center);
|
||||
}
|
||||
}
|
||||
|
||||
let path_stroke = PathStroke::from(stroke).outside();
|
||||
self.scratchpad_path.clear();
|
||||
self.scratchpad_path.add_line_loop(&points);
|
||||
@@ -1773,6 +1782,7 @@ impl Tessellator {
|
||||
round_to_pixels,
|
||||
mut blur_width,
|
||||
brush: _, // brush is extracted on its own, because it is not Copy
|
||||
angle,
|
||||
} = *rect_shape;
|
||||
|
||||
let mut corner_radius = CornerRadiusF32::from(corner_radius);
|
||||
@@ -1940,6 +1950,16 @@ impl Tessellator {
|
||||
let path = &mut self.scratchpad_path;
|
||||
path.clear();
|
||||
path::rounded_rectangle(&mut self.scratchpad_points, rect, corner_radius);
|
||||
|
||||
// Apply rotation if angle is non-zero
|
||||
if angle != 0.0 {
|
||||
let rot = emath::Rot2::from_angle(angle);
|
||||
let center = rect.center();
|
||||
for point in &mut self.scratchpad_points {
|
||||
*point = center + rot * (*point - center);
|
||||
}
|
||||
}
|
||||
|
||||
path.add_line_loop(&self.scratchpad_points);
|
||||
|
||||
let path_stroke = PathStroke::from(stroke).with_kind(stroke_kind);
|
||||
|
||||
Reference in New Issue
Block a user