Make it easier to create an Outline

This commit is contained in:
Emil Ernerfeldt 2020-04-19 11:11:41 +02:00
parent 2170081221
commit 1afda00fc4
6 changed files with 18 additions and 24 deletions

View file

@ -116,10 +116,7 @@ impl ExampleApp {
pos2(pos.x + (i as f32) * (self.size.x * 1.1), pos.y),
self.size,
),
outline: Some(Outline {
width: self.stroke_width,
color: gray(255, 255),
}),
outline: Some(Outline::new(self.stroke_width, gray(255, 255))),
});
}
region.add_paint_cmds(cmds);

View file

@ -119,10 +119,7 @@ where
PaintCmd::Rect {
corner_radius: 5.0,
fill_color: Some(style.background_fill_color()),
outline: Some(Outline {
color: color::WHITE,
width: 1.0,
}),
outline: Some(Outline::new(1.0, color::WHITE)),
rect,
},
);

View file

@ -131,10 +131,7 @@ impl Region {
self.add_paint_cmd(PaintCmd::Rect {
corner_radius: 5.0,
fill_color: Some(fill_color),
outline: Some(Outline {
width: 1.0,
color: color::WHITE,
}),
outline: Some(Outline::new(1.0, color::WHITE)),
rect: interact.rect,
});

View file

@ -91,6 +91,15 @@ pub struct Outline {
pub color: Color,
}
impl Outline {
pub fn new(width: impl Into<f32>, color: impl Into<Color>) -> Self {
Self {
width: width.into(),
color: color.into(),
}
}
}
#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "snake_case", tag = "kind")]
pub enum PaintCmd {

View file

@ -416,20 +416,17 @@ impl<'a> Widget for Slider<'a> {
region.add_paint_cmd(PaintCmd::Rect {
corner_radius: 4.0,
fill_color: Some(region.style().background_fill_color()),
outline: Some(Outline {
color: color::gray(200, 255), // TODO
width: 1.0,
}),
outline: Some(Outline::new(1.0, color::gray(200, 255))), // TODO
rect: thin_rect,
});
region.add_paint_cmd(PaintCmd::Circle {
center: pos2(marker_center_x, thin_rect.center().y),
fill_color: Some(region.style().interact_fill_color(&interact)),
outline: Some(Outline {
color: region.style().interact_stroke_color(&interact),
width: 1.5,
}),
outline: Some(Outline::new(
1.5,
region.style().interact_stroke_color(&interact),
)),
radius: thickness / 3.0,
});
}

View file

@ -71,10 +71,7 @@ impl Window {
PaintCmd::Rect {
corner_radius: 5.0,
fill_color: Some(style.background_fill_color()),
outline: Some(Outline {
color: color::WHITE,
width: 1.0,
}),
outline: Some(Outline::new(1.0, color::WHITE)),
rect: state.rect,
},
);