From 1afda00fc467b1b335f06e53adc21ea8f7bdc0db Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Sun, 19 Apr 2020 11:11:41 +0200 Subject: [PATCH] Make it easier to create an Outline --- emigui/src/example_app.rs | 5 +---- emigui/src/layout.rs | 5 +---- emigui/src/region.rs | 5 +---- emigui/src/types.rs | 9 +++++++++ emigui/src/widgets.rs | 13 +++++-------- emigui/src/window.rs | 5 +---- 6 files changed, 18 insertions(+), 24 deletions(-) diff --git a/emigui/src/example_app.rs b/emigui/src/example_app.rs index 0f6ee661..64f363ac 100644 --- a/emigui/src/example_app.rs +++ b/emigui/src/example_app.rs @@ -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); diff --git a/emigui/src/layout.rs b/emigui/src/layout.rs index 052019bc..e8d9c9dc 100644 --- a/emigui/src/layout.rs +++ b/emigui/src/layout.rs @@ -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, }, ); diff --git a/emigui/src/region.rs b/emigui/src/region.rs index 53503cfb..b0461284 100644 --- a/emigui/src/region.rs +++ b/emigui/src/region.rs @@ -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, }); diff --git a/emigui/src/types.rs b/emigui/src/types.rs index 9d458212..814b8976 100644 --- a/emigui/src/types.rs +++ b/emigui/src/types.rs @@ -91,6 +91,15 @@ pub struct Outline { pub color: Color, } +impl Outline { + pub fn new(width: impl Into, color: impl Into) -> Self { + Self { + width: width.into(), + color: color.into(), + } + } +} + #[derive(Clone, Debug, Serialize)] #[serde(rename_all = "snake_case", tag = "kind")] pub enum PaintCmd { diff --git a/emigui/src/widgets.rs b/emigui/src/widgets.rs index 8e7927c9..26d29e55 100644 --- a/emigui/src/widgets.rs +++ b/emigui/src/widgets.rs @@ -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, }); } diff --git a/emigui/src/window.rs b/emigui/src/window.rs index 04d8182b..d0e7ca7f 100644 --- a/emigui/src/window.rs +++ b/emigui/src/window.rs @@ -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, }, );