Rename Shape::polygon to Shape::convex_polygon

epaint only supports filling convex polygons (for now)
This commit is contained in:
Emil Ernerfeldt 2021-05-20 22:14:08 +02:00
parent 085233f907
commit 196ddff499
2 changed files with 13 additions and 2 deletions

View file

@ -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()),

View file

@ -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<Pos2>, fill: impl Into<Color32>, stroke: impl Into<Stroke>) -> Self {
/// A convex polygon with a fill and optional stroke.
pub fn convex_polygon(
points: Vec<Pos2>,
fill: impl Into<Color32>,
stroke: impl Into<Stroke>,
) -> Self {
Self::Path {
points,
closed: true,
@ -94,6 +100,11 @@ impl Shape {
}
}
#[deprecated = "Renamed convex_polygon"]
pub fn polygon(points: Vec<Pos2>, fill: impl Into<Color32>, stroke: impl Into<Stroke>) -> Self {
Self::convex_polygon(points, fill, stroke)
}
pub fn circle_filled(center: Pos2, radius: f32, fill_color: impl Into<Color32>) -> Self {
Self::Circle {
center,