[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();
|
||||
|
||||
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,
|
||||
|
|
|
|||
|
|
@ -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<Pos2> = 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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,12 +19,6 @@ pub enum PaintCmd {
|
|||
color: Color,
|
||||
width: f32,
|
||||
},
|
||||
// TODO: remove. Just have Path.
|
||||
LinePath {
|
||||
points: Vec<Pos2>,
|
||||
color: Color,
|
||||
width: f32,
|
||||
},
|
||||
Path {
|
||||
path: Path,
|
||||
closed: bool,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue