mirror of
https://github.com/emilk/egui.git
synced 2026-08-30 13:20:05 -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:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user