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), pos2(pos.x + (i as f32) * (self.size.x * 1.1), pos.y),
self.size, self.size,
), ),
outline: Some(Outline { outline: Some(Outline::new(self.stroke_width, gray(255, 255))),
width: self.stroke_width,
color: gray(255, 255),
}),
}); });
} }
region.add_paint_cmds(cmds); region.add_paint_cmds(cmds);

View file

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

View file

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

View file

@ -91,6 +91,15 @@ pub struct Outline {
pub color: Color, 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)] #[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "snake_case", tag = "kind")] #[serde(rename_all = "snake_case", tag = "kind")]
pub enum PaintCmd { pub enum PaintCmd {

View file

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

View file

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