From 196ddff499e7e27c0abf3119ac93fd5df81cb081 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Thu, 20 May 2021 22:14:08 +0200 Subject: [PATCH] Rename Shape::polygon to Shape::convex_polygon epaint only supports filling convex polygons (for now) --- egui/src/widgets/color_picker.rs | 2 +- epaint/src/shape.rs | 13 ++++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/egui/src/widgets/color_picker.rs b/egui/src/widgets/color_picker.rs index e7eed613..c27b0f95 100644 --- a/egui/src/widgets/color_picker.rs +++ b/egui/src/widgets/color_picker.rs @@ -129,7 +129,7 @@ fn color_slider_1d(ui: &mut Ui, value: &mut f32, color_at: impl Fn(f32) -> Color let x = lerp(rect.left()..=rect.right(), *value); let r = rect.height() / 4.0; let picked_color = color_at(*value); - ui.painter().add(Shape::polygon( + ui.painter().add(Shape::convex_polygon( vec![ pos2(x - r, rect.bottom()), pos2(x + r, rect.bottom()), diff --git a/epaint/src/shape.rs b/epaint/src/shape.rs index ecb6a4af..aa46c4d4 100644 --- a/epaint/src/shape.rs +++ b/epaint/src/shape.rs @@ -29,6 +29,7 @@ pub enum Shape { /// If true, connect the first and last of the points together. /// This is required if `fill != TRANSPARENT`. closed: bool, + /// Fill is only supported for convex polygons. fill: Color32, stroke: Stroke, }, @@ -85,7 +86,12 @@ impl Shape { } } - pub fn polygon(points: Vec, fill: impl Into, stroke: impl Into) -> Self { + /// A convex polygon with a fill and optional stroke. + pub fn convex_polygon( + points: Vec, + fill: impl Into, + stroke: impl Into, + ) -> Self { Self::Path { points, closed: true, @@ -94,6 +100,11 @@ impl Shape { } } + #[deprecated = "Renamed convex_polygon"] + pub fn polygon(points: Vec, fill: impl Into, stroke: impl Into) -> Self { + Self::convex_polygon(points, fill, stroke) + } + pub fn circle_filled(center: Pos2, radius: f32, fill_color: impl Into) -> Self { Self::Circle { center,