diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index d9fc3aaa..d89d0c36 100644 --- a/egui/src/containers/collapsing_header.rs +++ b/egui/src/containers/collapsing_header.rs @@ -105,7 +105,7 @@ impl State { /// Paint the arrow icon that indicated if the region is open or not pub fn paint_icon(ui: &mut Ui, openness: f32, response: &Response) { - let stroke = ui.style().interact(response).stroke(); + let stroke = ui.style().interact(response).stroke; let rect = response.rect; @@ -224,7 +224,7 @@ impl CollapsingHeader { text_pos, galley, label.text_style, - ui.style().interact(&response).stroke_color, + ui.style().interact(&response).stroke.color, ); painter.set( diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index ac6d5d6f..c4999f21 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -270,9 +270,8 @@ impl Resize { use crate::paint::Stroke; pub fn paint_resize_corner(ui: &mut Ui, response: &Response) { - let color = ui.style().interact(response).stroke_color; - let width = ui.style().interact(response).stroke_width; - paint_resize_corner_with_style(ui, &response.rect, Stroke::new(width, color)); + let stroke = ui.style().interact(response).stroke; + paint_resize_corner_with_style(ui, &response.rect, stroke); } pub fn paint_resize_corner_with_style(ui: &mut Ui, rect: &Rect, stroke: Stroke) { diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index 519bcb91..f1427168 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -711,15 +711,10 @@ fn close_button(ui: &mut Ui, rect: Rect) -> Response { let response = ui.interact(rect, close_id, Sense::click()); ui.expand_to_include_child(response.rect); - let stroke_color = ui.style().interact(&response).stroke_color; - let stroke_width = ui.style().interact(&response).stroke_width; - ui.painter().line_segment( - [rect.left_top(), rect.right_bottom()], - (stroke_width, stroke_color), - ); - ui.painter().line_segment( - [rect.right_top(), rect.left_bottom()], - (stroke_width, stroke_color), - ); + let stroke = ui.style().interact(&response).stroke; + ui.painter() + .line_segment([rect.left_top(), rect.right_bottom()], stroke); + ui.painter() + .line_segment([rect.right_top(), rect.left_bottom()], stroke); response } diff --git a/egui/src/demos/toggle_switch.rs b/egui/src/demos/toggle_switch.rs index 60f9bd4d..12c4cede 100644 --- a/egui/src/demos/toggle_switch.rs +++ b/egui/src/demos/toggle_switch.rs @@ -45,7 +45,7 @@ pub fn toggle(ui: &mut Ui, on: &mut bool) -> Response { center: pos2(circle_x, rect.center().y), radius: 0.75 * radius, fill: style.main_fill, - stroke: style.stroke(), + stroke: style.stroke, }); // All done! Return the response so the user can check what happened diff --git a/egui/src/style.rs b/egui/src/style.rs index 8a1758ab..22ba1d1a 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -155,19 +155,10 @@ pub struct WidgetVisuals { /// Fill color of the interactive part of a component (slider grab, checkbox, ...) /// When you need a fill. - pub main_fill: Srgba, + pub main_fill: Srgba, // TODO: just fill? /// Stroke and text color of the interactive part of a component (button text, slider grab, check-mark, ...) - pub stroke_color: Srgba, - - /// For lines etc - pub stroke_width: f32, -} - -impl WidgetVisuals { - pub fn stroke(&self) -> Stroke { - Stroke::new(self.stroke_width, self.stroke_color) - } + pub stroke: Stroke, } // ---------------------------------------------------------------------------- @@ -236,32 +227,28 @@ impl Default for Interacted { bg_stroke: Stroke::new(2.0, WHITE), corner_radius: 4.0, main_fill: srgba(120, 120, 200, 255), - stroke_color: WHITE, - stroke_width: 2.0, + stroke: Stroke::new(2.0, WHITE), }, hovered: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.06, 0.5).into(), bg_stroke: Stroke::new(1.0, Rgba::white_alpha(0.5)), corner_radius: 4.0, main_fill: srgba(100, 100, 150, 255), - stroke_color: Srgba::gray(240), - stroke_width: 1.5, + stroke: Stroke::new(1.5, Srgba::gray(240)), }, inactive: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.04, 0.5).into(), bg_stroke: Stroke::new(1.0, Rgba::white_alpha(0.04)), corner_radius: 4.0, main_fill: srgba(60, 60, 80, 255), - stroke_color: Srgba::gray(200), // Should NOT look grayed out! - stroke_width: 0.5, + stroke: Stroke::new(0.5, Srgba::gray(200)), // Should NOT look grayed out! }, disabled: WidgetVisuals { bg_fill: TRANSPARENT, bg_stroke: Stroke::new(0.5, Srgba::gray(70)), corner_radius: 4.0, main_fill: srgba(50, 50, 50, 255), - stroke_color: Srgba::gray(128), // Should look grayed out - stroke_width: 0.5, + stroke: Stroke::new(0.5, Srgba::gray(128)), // Should look grayed out }, } } @@ -365,16 +352,14 @@ impl WidgetVisuals { bg_stroke, corner_radius, main_fill, - stroke_color, - stroke_width, + stroke, } = self; ui_color(ui, bg_fill, "bg_fill"); bg_stroke.ui(ui, "bg_stroke"); ui.add(Slider::f32(corner_radius, 0.0..=10.0).text("corner_radius")); ui_color(ui, main_fill, "main_fill"); - ui_color(ui, stroke_color, "stroke_color"); - ui.add(Slider::f32(stroke_width, 0.0..=10.0).text("stroke_width")); + stroke.ui(ui, "stroke"); } } diff --git a/egui/src/widgets.rs b/egui/src/widgets.rs index 8954364d..27d665db 100644 --- a/egui/src/widgets.rs +++ b/egui/src/widgets.rs @@ -297,7 +297,7 @@ impl Widget for Button { fill, stroke: ui.style().interact(&response).bg_stroke, }); - let stroke_color = ui.style().interact(&response).stroke_color; + let stroke_color = ui.style().interact(&response).stroke.color; let text_color = text_color.unwrap_or(stroke_color); ui.painter() .galley(text_cursor, galley, text_style, text_color); @@ -368,7 +368,7 @@ impl<'a> Widget for Checkbox<'a> { stroke: ui.style().interact(&response).bg_stroke, }); - let stroke = ui.style().interact(&response).stroke(); + let stroke = ui.style().interact(&response).stroke; if *checked { ui.painter().add(PaintCmd::Path { @@ -442,7 +442,7 @@ impl Widget for RadioButton { ); let bg_fill = ui.style().interact(&response).bg_fill; - let stroke_color = ui.style().interact(&response).stroke_color; + let stroke_color = ui.style().interact(&response).stroke.color; let (small_icon_rect, big_icon_rect) = ui.style().spacing.icon_rectangles(response.rect); diff --git a/egui/src/widgets/slider.rs b/egui/src/widgets/slider.rs index 69853d0c..c8d18011 100644 --- a/egui/src/widgets/slider.rs +++ b/egui/src/widgets/slider.rs @@ -172,10 +172,7 @@ impl<'a> Slider<'a> { center: pos2(marker_center_x, rail_rect.center().y), radius: handle_radius(rect), fill: ui.style().interact(response).main_fill, - stroke: Stroke::new( - ui.style().interact(response).stroke_width, - ui.style().interact(response).stroke_color, - ), + stroke: ui.style().interact(response).stroke, }); } } diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index 78d6ba72..4800dfea 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -208,7 +208,7 @@ impl<'t> Widget for TextEdit<'t> { } } - let text_color = text_color.unwrap_or_else(|| ui.style().interact(&response).stroke_color); + let text_color = text_color.unwrap_or_else(|| ui.style().interact(&response).stroke.color); painter.galley(response.rect.min, galley, text_style, text_color); ui.memory().text_edit.insert(id, state); response