[refactor] remove PaintCmd::LinePath
This commit is contained in:
parent
0bb042924f
commit
c7a59b57d2
|
|
@ -477,30 +477,30 @@ fn paint_frame_interaction(
|
||||||
let mut path = Path::default();
|
let mut path = Path::default();
|
||||||
|
|
||||||
if interaction.right && !interaction.bottom && !interaction.top {
|
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 {
|
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);
|
path.add_circle_quadrant(pos2(max.x - cr, max.y - cr), cr, 0.0);
|
||||||
}
|
}
|
||||||
if interaction.bottom {
|
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 {
|
if interaction.left && interaction.bottom {
|
||||||
path.add_circle_quadrant(pos2(min.x + cr, max.y - cr), cr, 1.0);
|
path.add_circle_quadrant(pos2(min.x + cr, max.y - cr), cr, 1.0);
|
||||||
}
|
}
|
||||||
if interaction.left {
|
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 {
|
if interaction.left && interaction.top {
|
||||||
path.add_circle_quadrant(pos2(min.x + cr, min.y + cr), cr, 2.0);
|
path.add_circle_quadrant(pos2(min.x + cr, min.y + cr), cr, 2.0);
|
||||||
}
|
}
|
||||||
if interaction.top {
|
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 {
|
if interaction.right && interaction.top {
|
||||||
path.add_circle_quadrant(pos2(max.x - cr, min.y + cr), cr, 3.0);
|
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 {
|
ui.add_paint_cmd(PaintCmd::Path {
|
||||||
path,
|
path,
|
||||||
|
|
|
||||||
|
|
@ -458,10 +458,12 @@ impl Painting {
|
||||||
|
|
||||||
for line in &self.lines {
|
for line in &self.lines {
|
||||||
if line.len() >= 2 {
|
if line.len() >= 2 {
|
||||||
ui.add_paint_cmd(PaintCmd::LinePath {
|
let points: Vec<Pos2> = line.iter().map(|p| rect.min + *p).collect();
|
||||||
points: line.iter().map(|p| rect.min + *p).collect(),
|
ui.add_paint_cmd(PaintCmd::Path {
|
||||||
color: LIGHT_GRAY,
|
path: Path::from_open_points(&points),
|
||||||
width: 2.0,
|
closed: false,
|
||||||
|
outline: Some(LineStyle::new(2.0, LIGHT_GRAY)),
|
||||||
|
fill_color: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,12 +19,6 @@ pub enum PaintCmd {
|
||||||
color: Color,
|
color: Color,
|
||||||
width: f32,
|
width: f32,
|
||||||
},
|
},
|
||||||
// TODO: remove. Just have Path.
|
|
||||||
LinePath {
|
|
||||||
points: Vec<Pos2>,
|
|
||||||
color: Color,
|
|
||||||
width: f32,
|
|
||||||
},
|
|
||||||
Path {
|
Path {
|
||||||
path: Path,
|
path: Path,
|
||||||
closed: bool,
|
closed: bool,
|
||||||
|
|
|
||||||
|
|
@ -159,6 +159,12 @@ impl Path {
|
||||||
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) {
|
pub fn clear(&mut self) {
|
||||||
self.0.clear();
|
self.0.clear();
|
||||||
}
|
}
|
||||||
|
|
@ -192,8 +198,7 @@ impl Path {
|
||||||
self.add_point(points[1], normal);
|
self.add_point(points[1], normal);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make it clear it is an open (non-closed) thing.
|
pub fn add_open_points(&mut self, points: &[Pos2]) {
|
||||||
pub fn add_line(&mut self, points: &[Pos2]) {
|
|
||||||
let n = points.len();
|
let n = points.len();
|
||||||
assert!(n >= 2);
|
assert!(n >= 2);
|
||||||
|
|
||||||
|
|
@ -572,17 +577,6 @@ pub fn paint_command_into_triangles(
|
||||||
path.add_line_segment(points);
|
path.add_line_segment(points);
|
||||||
paint_path_outline(out, options, Open, &path.0, color, width);
|
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 {
|
PaintCmd::Path {
|
||||||
path,
|
path,
|
||||||
closed,
|
closed,
|
||||||
|
|
|
||||||
|
|
@ -315,14 +315,15 @@ impl<'a> Widget for Checkbox<'a> {
|
||||||
let stroke_color = ui.style().interact(&interact).stroke_color;
|
let stroke_color = ui.style().interact(&interact).stroke_color;
|
||||||
|
|
||||||
if *checked {
|
if *checked {
|
||||||
ui.add_paint_cmd(PaintCmd::LinePath {
|
ui.add_paint_cmd(PaintCmd::Path {
|
||||||
points: vec![
|
path: Path::from_open_points(&[
|
||||||
pos2(small_icon_rect.left(), small_icon_rect.center().y),
|
pos2(small_icon_rect.left(), small_icon_rect.center().y),
|
||||||
pos2(small_icon_rect.center().x, small_icon_rect.bottom()),
|
pos2(small_icon_rect.center().x, small_icon_rect.bottom()),
|
||||||
pos2(small_icon_rect.right(), small_icon_rect.top()),
|
pos2(small_icon_rect.right(), small_icon_rect.top()),
|
||||||
],
|
]),
|
||||||
color: stroke_color,
|
closed: false,
|
||||||
width: ui.style().line_width,
|
outline: Some(LineStyle::new(ui.style().line_width, stroke_color)),
|
||||||
|
fill_color: None,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue