mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Require a StrokeKind when painting rectangles with strokes (#5648)
This is a breaking change, requiring users to think about wether the stroke is inside/centered/outside the rect. When in doubt, add `egui::StrokeKind::Inside` to the function call.
This commit is contained in:
@@ -76,7 +76,13 @@ pub fn criterion_benchmark(c: &mut Criterion) {
|
||||
let painter = ui.painter();
|
||||
let rect = ui.max_rect();
|
||||
b.iter(|| {
|
||||
painter.rect(rect, 2.0, egui::Color32::RED, (1.0, egui::Color32::WHITE));
|
||||
painter.rect(
|
||||
rect,
|
||||
2.0,
|
||||
egui::Color32::RED,
|
||||
(1.0, egui::Color32::WHITE),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -390,6 +390,7 @@ impl BoxPainting {
|
||||
self.rounding,
|
||||
ui.visuals().text_color().gamma_multiply(0.5),
|
||||
Stroke::new(self.stroke_width, Color32::WHITE),
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use egui::epaint::{CubicBezierShape, PathShape, QuadraticBezierShape};
|
||||
use egui::{
|
||||
emath, epaint, pos2, Color32, Context, Frame, Grid, Pos2, Rect, Sense, Shape, Stroke, Ui, Vec2,
|
||||
emath,
|
||||
epaint::{self, CubicBezierShape, PathShape, QuadraticBezierShape},
|
||||
pos2, Color32, Context, Frame, Grid, Pos2, Rect, Sense, Shape, Stroke, StrokeKind, Ui, Vec2,
|
||||
Widget, Window,
|
||||
};
|
||||
|
||||
@@ -132,6 +133,7 @@ impl PaintBezier {
|
||||
shape.visual_bounding_rect(),
|
||||
0.0,
|
||||
self.bounding_box_stroke,
|
||||
StrokeKind::Outside,
|
||||
));
|
||||
painter.add(shape);
|
||||
}
|
||||
@@ -143,6 +145,7 @@ impl PaintBezier {
|
||||
shape.visual_bounding_rect(),
|
||||
0.0,
|
||||
self.bounding_box_stroke,
|
||||
StrokeKind::Outside,
|
||||
));
|
||||
painter.add(shape);
|
||||
}
|
||||
|
||||
@@ -56,8 +56,13 @@ pub fn toggle_ui(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
|
||||
// All coordinates are in absolute screen coordinates so we use `rect` to place the elements.
|
||||
let rect = rect.expand(visuals.expansion);
|
||||
let radius = 0.5 * rect.height();
|
||||
ui.painter()
|
||||
.rect(rect, radius, visuals.bg_fill, visuals.bg_stroke);
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
radius,
|
||||
visuals.bg_fill,
|
||||
visuals.bg_stroke,
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
// Paint the circle, animating it from left to right with `how_on`:
|
||||
let circle_x = egui::lerp((rect.left() + radius)..=(rect.right() - radius), how_on);
|
||||
let center = egui::pos2(circle_x, rect.center().y);
|
||||
@@ -88,8 +93,13 @@ fn toggle_ui_compact(ui: &mut egui::Ui, on: &mut bool) -> egui::Response {
|
||||
let visuals = ui.style().interact_selectable(&response, *on);
|
||||
let rect = rect.expand(visuals.expansion);
|
||||
let radius = 0.5 * rect.height();
|
||||
ui.painter()
|
||||
.rect(rect, radius, visuals.bg_fill, visuals.bg_stroke);
|
||||
ui.painter().rect(
|
||||
rect,
|
||||
radius,
|
||||
visuals.bg_fill,
|
||||
visuals.bg_stroke,
|
||||
egui::StrokeKind::Inside,
|
||||
);
|
||||
let circle_x = egui::lerp((rect.left() + radius)..=(rect.right() - radius), how_on);
|
||||
let center = egui::pos2(circle_x, rect.center().y);
|
||||
ui.painter()
|
||||
|
||||
@@ -452,7 +452,12 @@ fn pixel_test_strokes(ui: &mut Ui) {
|
||||
Pos2::new(cursor_pixel.x, cursor_pixel.y),
|
||||
Vec2::splat(size as f32),
|
||||
);
|
||||
painter.rect_stroke(rect_points / pixels_per_point, 0.0, stroke);
|
||||
painter.rect_stroke(
|
||||
rect_points / pixels_per_point,
|
||||
0.0,
|
||||
stroke,
|
||||
egui::StrokeKind::Outside,
|
||||
);
|
||||
cursor_pixel.x += (1 + size) as f32 + thickness_pixels * 2.0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:7d8135b745cb95a7e7c7a26e73e160742f88ec177a2fa262215c4886d98ff172
|
||||
size 24403
|
||||
oid sha256:e4fef5fa8661f207bae2c58381e729cdaf77aecc8b3f178caf262dc310e3a490
|
||||
size 24206
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:64fe3ef34aaf3104931954f4a39760b99944f42da13f866622ca0222b750f6be
|
||||
size 17731
|
||||
oid sha256:6efc59cb9908533baa1a7346b359e9e21c5faf0e373dac6fa7db5476e644233d
|
||||
size 17678
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4eed8890c6d8fa6b97639197f5d1be79a72724a70470c5e5ae4b55e3447b9b88
|
||||
size 35561
|
||||
oid sha256:d076f5365bfa87b7e61d3808b8b9b367157ea6e55ccf665720cbd2237d53793d
|
||||
size 35563
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:b3dc1bf9a59007a6ad0fb66a345d6cf272bd8bdcd26b10dbf411c1280e62b6fc
|
||||
size 158285
|
||||
oid sha256:a291f3a5724aefc59ba7881f48752ccc826ca5e480741c221d195061f562ccc9
|
||||
size 158220
|
||||
|
||||
Reference in New Issue
Block a user