From c7a59b57d2f94d439642c1f0914f068110f2f211 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sat, 23 May 2020 14:14:36 +0200 Subject: [PATCH] [refactor] remove PaintCmd::LinePath --- emigui/src/containers/window.rs | 12 ++++++------ emigui/src/examples/app.rs | 10 ++++++---- emigui/src/paint/command.rs | 6 ------ emigui/src/paint/mesher.rs | 20 +++++++------------- emigui/src/widgets.rs | 11 ++++++----- 5 files changed, 25 insertions(+), 34 deletions(-) diff --git a/emigui/src/containers/window.rs b/emigui/src/containers/window.rs index 4a7f8fc2..7dd5e7b5 100644 --- a/emigui/src/containers/window.rs +++ b/emigui/src/containers/window.rs @@ -477,30 +477,30 @@ fn paint_frame_interaction( let mut path = Path::default(); if interaction.right && !interaction.bottom && !interaction.top { - path.add_line(&[pos2(max.x, min.y + cr), pos2(max.x, max.y - cr)]); + path.add_line_segment([pos2(max.x, min.y + cr), pos2(max.x, max.y - cr)]); } if interaction.right && interaction.bottom { - path.add_line(&[pos2(max.x, min.y + cr), pos2(max.x, max.y - cr)]); + path.add_line_segment([pos2(max.x, min.y + cr), pos2(max.x, max.y - cr)]); path.add_circle_quadrant(pos2(max.x - cr, max.y - cr), cr, 0.0); } if interaction.bottom { - path.add_line(&[pos2(max.x - cr, max.y), pos2(min.x + cr, max.y)]); + path.add_line_segment([pos2(max.x - cr, max.y), pos2(min.x + cr, max.y)]); } if interaction.left && interaction.bottom { path.add_circle_quadrant(pos2(min.x + cr, max.y - cr), cr, 1.0); } if interaction.left { - path.add_line(&[pos2(min.x, max.y - cr), pos2(min.x, min.y + cr)]); + path.add_line_segment([pos2(min.x, max.y - cr), pos2(min.x, min.y + cr)]); } if interaction.left && interaction.top { path.add_circle_quadrant(pos2(min.x + cr, min.y + cr), cr, 2.0); } if interaction.top { - path.add_line(&[pos2(min.x + cr, min.y), pos2(max.x - cr, min.y)]); + path.add_line_segment([pos2(min.x + cr, min.y), pos2(max.x - cr, min.y)]); } if interaction.right && interaction.top { path.add_circle_quadrant(pos2(max.x - cr, min.y + cr), cr, 3.0); - path.add_line(&[pos2(max.x, min.y + cr), pos2(max.x, max.y - cr)]); + path.add_line_segment([pos2(max.x, min.y + cr), pos2(max.x, max.y - cr)]); } ui.add_paint_cmd(PaintCmd::Path { path, diff --git a/emigui/src/examples/app.rs b/emigui/src/examples/app.rs index 24a54bb5..f49daf98 100644 --- a/emigui/src/examples/app.rs +++ b/emigui/src/examples/app.rs @@ -458,10 +458,12 @@ impl Painting { for line in &self.lines { if line.len() >= 2 { - ui.add_paint_cmd(PaintCmd::LinePath { - points: line.iter().map(|p| rect.min + *p).collect(), - color: LIGHT_GRAY, - width: 2.0, + let points: Vec = line.iter().map(|p| rect.min + *p).collect(); + ui.add_paint_cmd(PaintCmd::Path { + path: Path::from_open_points(&points), + closed: false, + outline: Some(LineStyle::new(2.0, LIGHT_GRAY)), + fill_color: None, }); } } diff --git a/emigui/src/paint/command.rs b/emigui/src/paint/command.rs index d7c96f91..0cd485b4 100644 --- a/emigui/src/paint/command.rs +++ b/emigui/src/paint/command.rs @@ -19,12 +19,6 @@ pub enum PaintCmd { color: Color, width: f32, }, - // TODO: remove. Just have Path. - LinePath { - points: Vec, - color: Color, - width: f32, - }, Path { path: Path, closed: bool, diff --git a/emigui/src/paint/mesher.rs b/emigui/src/paint/mesher.rs index f900b74b..8070421f 100644 --- a/emigui/src/paint/mesher.rs +++ b/emigui/src/paint/mesher.rs @@ -159,6 +159,12 @@ impl Path { path } + pub fn from_open_points(points: &[Pos2]) -> Self { + let mut path = Self::default(); + path.add_open_points(points); + path + } + pub fn clear(&mut self) { self.0.clear(); } @@ -192,8 +198,7 @@ impl Path { self.add_point(points[1], normal); } - // TODO: make it clear it is an open (non-closed) thing. - pub fn add_line(&mut self, points: &[Pos2]) { + pub fn add_open_points(&mut self, points: &[Pos2]) { let n = points.len(); assert!(n >= 2); @@ -572,17 +577,6 @@ pub fn paint_command_into_triangles( path.add_line_segment(points); paint_path_outline(out, options, Open, &path.0, color, width); } - PaintCmd::LinePath { - points, - color, - width, - } => { - let n = points.len(); - if n >= 2 { - path.add_line(&points); - paint_path_outline(out, options, Open, &path.0, color, width); - } - } PaintCmd::Path { path, closed, diff --git a/emigui/src/widgets.rs b/emigui/src/widgets.rs index 1abe4b1c..71299159 100644 --- a/emigui/src/widgets.rs +++ b/emigui/src/widgets.rs @@ -315,14 +315,15 @@ impl<'a> Widget for Checkbox<'a> { let stroke_color = ui.style().interact(&interact).stroke_color; if *checked { - ui.add_paint_cmd(PaintCmd::LinePath { - points: vec![ + ui.add_paint_cmd(PaintCmd::Path { + path: Path::from_open_points(&[ pos2(small_icon_rect.left(), small_icon_rect.center().y), pos2(small_icon_rect.center().x, small_icon_rect.bottom()), pos2(small_icon_rect.right(), small_icon_rect.top()), - ], - color: stroke_color, - width: ui.style().line_width, + ]), + closed: false, + outline: Some(LineStyle::new(ui.style().line_width, stroke_color)), + fill_color: None, }); }