From 9d4021d703cc8f27ec0be87ad77eaf4916842d29 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 1 Sep 2020 23:54:21 +0200 Subject: [PATCH] [refactor] rename LineStyle to Stroke --- egui/src/containers/collapsing_header.rs | 6 +-- egui/src/containers/frame.rs | 16 +++---- egui/src/containers/resize.rs | 22 +++++----- egui/src/containers/scroll_area.rs | 6 +-- egui/src/containers/window.rs | 14 +++--- egui/src/demos/app.rs | 14 +++--- egui/src/demos/fractal_clock.rs | 2 +- egui/src/demos/toggle_switch.rs | 4 +- egui/src/lib.rs | 2 +- egui/src/menu.rs | 16 +++---- egui/src/paint.rs | 2 +- egui/src/paint/command.rs | 18 ++++---- egui/src/paint/tessellator.rs | 54 ++++++++++++------------ egui/src/painter.rs | 22 +++++----- egui/src/style.rs | 32 +++++++------- egui/src/ui.rs | 2 +- egui/src/widgets.rs | 14 +++--- egui/src/widgets/slider.rs | 4 +- egui/src/widgets/text_edit.rs | 2 +- 19 files changed, 126 insertions(+), 126 deletions(-) diff --git a/egui/src/containers/collapsing_header.rs b/egui/src/containers/collapsing_header.rs index 422703aa..d9fc3aaa 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 line_style = ui.style().interact(response).line_style(); + let stroke = ui.style().interact(response).stroke(); let rect = response.rect; @@ -123,7 +123,7 @@ pub fn paint_icon(ui: &mut Ui, openness: f32, response: &Response) { points, closed: true, fill: Default::default(), - outline: line_style, + stroke, }); } @@ -233,7 +233,7 @@ impl CollapsingHeader { rect: response.rect, corner_radius: ui.style().interact(&response).corner_radius, fill: ui.style().interact(&response).bg_fill, - outline: Default::default(), + stroke: Default::default(), }, ); diff --git a/egui/src/containers/frame.rs b/egui/src/containers/frame.rs index f7b7c6d4..d772889f 100644 --- a/egui/src/containers/frame.rs +++ b/egui/src/containers/frame.rs @@ -9,7 +9,7 @@ pub struct Frame { pub margin: Vec2, pub corner_radius: f32, pub fill: Srgba, - pub outline: LineStyle, + pub stroke: Stroke, } impl Frame { @@ -18,7 +18,7 @@ impl Frame { margin: style.spacing.window_padding, corner_radius: style.visuals.window_corner_radius, fill: style.visuals.background_fill, - outline: style.visuals.interacted.inactive.bg_outline, // because we can resize windows + stroke: style.visuals.interacted.inactive.bg_stroke, // because we can resize windows } } @@ -27,7 +27,7 @@ impl Frame { margin: Vec2::splat(1.0), corner_radius: 0.0, fill: Default::default(), - outline: LineStyle::new(0.5, Srgba::gray(128)), + stroke: Stroke::new(0.5, Srgba::gray(128)), } } @@ -36,7 +36,7 @@ impl Frame { margin: Vec2::splat(1.0), corner_radius: 2.0, fill: style.visuals.background_fill, - outline: LineStyle::new(1.0, Srgba::gray(128)), + stroke: Stroke::new(1.0, Srgba::gray(128)), } } @@ -45,7 +45,7 @@ impl Frame { margin: style.spacing.window_padding, corner_radius: 5.0, fill: style.visuals.background_fill, - outline: LineStyle::new(1.0, Srgba::gray(128)), + stroke: Stroke::new(1.0, Srgba::gray(128)), } } @@ -54,8 +54,8 @@ impl Frame { self } - pub fn outline(mut self, outline: LineStyle) -> Self { - self.outline = outline; + pub fn stroke(mut self, stroke: Stroke) -> Self { + self.stroke = stroke; self } } @@ -111,7 +111,7 @@ impl Prepared { PaintCmd::Rect { corner_radius: frame.corner_radius, fill: frame.fill, - outline: frame.outline, + stroke: frame.stroke, rect: outer_rect, }, ); diff --git a/egui/src/containers/resize.rs b/egui/src/containers/resize.rs index 77a9d83d..ac6d5d6f 100644 --- a/egui/src/containers/resize.rs +++ b/egui/src/containers/resize.rs @@ -28,7 +28,7 @@ pub struct Resize { default_size: Vec2, - outline: bool, + with_stroke: bool, } impl Default for Resize { @@ -38,7 +38,7 @@ impl Default for Resize { resizable: true, min_size: Vec2::splat(16.0), default_size: vec2(320.0, 128.0), // TODO: preferred size of `Resize` area. - outline: true, + with_stroke: true, } } } @@ -110,8 +110,8 @@ impl Resize { self } - pub fn outline(mut self, outline: bool) -> Self { - self.outline = outline; + pub fn with_stroke(mut self, with_stroke: bool) -> Self { + self.with_stroke = with_stroke; self } } @@ -215,7 +215,7 @@ impl Resize { // ------------------------------ - if self.outline || self.resizable { + if self.with_stroke || self.resizable { // We show how large we are, // so we must follow the contents: @@ -231,14 +231,14 @@ impl Resize { // ------------------------------ - if self.outline && corner_response.is_some() { + if self.with_stroke && corner_response.is_some() { let rect = Rect::from_min_size(content_ui.top_left(), state.desired_size); let rect = rect.expand(2.0); // breathing room for content ui.painter().add(paint::PaintCmd::Rect { rect, corner_radius: 3.0, fill: Default::default(), - outline: ui.style().visuals.thin_outline, + stroke: ui.style().visuals.thin_stroke, }); } @@ -267,15 +267,15 @@ impl Resize { } } -use crate::paint::LineStyle; +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, LineStyle::new(width, color)); + paint_resize_corner_with_style(ui, &response.rect, Stroke::new(width, color)); } -pub fn paint_resize_corner_with_style(ui: &mut Ui, rect: &Rect, style: LineStyle) { +pub fn paint_resize_corner_with_style(ui: &mut Ui, rect: &Rect, stroke: Stroke) { let painter = ui.painter(); let corner = painter.round_pos_to_pixels(rect.right_bottom()); let mut w = 2.0; @@ -283,7 +283,7 @@ pub fn paint_resize_corner_with_style(ui: &mut Ui, rect: &Rect, style: LineStyle while w <= rect.width() && w <= rect.height() { painter.line_segment( [pos2(corner.x - w, corner.y), pos2(corner.x, corner.y - w)], - style, + stroke, ); w += 4.0; } diff --git a/egui/src/containers/scroll_area.rs b/egui/src/containers/scroll_area.rs index 5467af9e..aa520efb 100644 --- a/egui/src/containers/scroll_area.rs +++ b/egui/src/containers/scroll_area.rs @@ -238,20 +238,20 @@ impl Prepared { let style = ui.style(); let handle_fill = style.interact(&response).main_fill; - let handle_outline = style.interact(&response).bg_outline; + let handle_stroke = style.interact(&response).bg_stroke; ui.painter().add(paint::PaintCmd::Rect { rect: outer_scroll_rect, corner_radius, fill: ui.style().visuals.dark_bg_color, - outline: Default::default(), + stroke: Default::default(), }); ui.painter().add(paint::PaintCmd::Rect { rect: handle_rect.expand(-2.0), corner_radius, fill: handle_fill, - outline: handle_outline, + stroke: handle_stroke, }); } diff --git a/egui/src/containers/window.rs b/egui/src/containers/window.rs index c9af75fb..519bcb91 100644 --- a/egui/src/containers/window.rs +++ b/egui/src/containers/window.rs @@ -38,7 +38,7 @@ impl<'open> Window<'open> { area, frame: None, resize: Resize::default() - .outline(false) + .with_stroke(false) .min_size([96.0, 32.0]) .default_size([420.0, 420.0]), scroll: None, @@ -231,7 +231,7 @@ impl<'open> Window<'open> { { // BEGIN FRAME -------------------------------- - let frame_outline = frame.outline; + let frame_stroke = frame.stroke; let mut frame = frame.begin(&mut area_content_ui); let default_expanded = true; @@ -270,7 +270,7 @@ impl<'open> Window<'open> { if possible.resizable { // TODO: draw BEHIND contents ? - paint_resize_corner(&mut area_content_ui, outer_rect, frame_outline); + paint_resize_corner(&mut area_content_ui, outer_rect, frame_stroke); } // END FRAME -------------------------------- @@ -311,12 +311,12 @@ impl<'open> Window<'open> { } } -fn paint_resize_corner(ui: &mut Ui, outer_rect: Rect, outline: LineStyle) { +fn paint_resize_corner(ui: &mut Ui, outer_rect: Rect, stroke: Stroke) { let corner_size = Vec2::splat(ui.style().visuals.resize_corner_size); let handle_offset = -Vec2::splat(2.0); let corner_rect = Rect::from_min_size(outer_rect.max - corner_size + handle_offset, corner_size); - crate::resize::paint_resize_corner_with_style(ui, &corner_rect, outline); + crate::resize::paint_resize_corner_with_style(ui, &corner_rect, stroke); } // ---------------------------------------------------------------------------- @@ -574,7 +574,7 @@ fn paint_frame_interaction( points, closed: false, fill: Default::default(), - outline: visuals.bg_outline, + stroke: visuals.bg_stroke, }); } @@ -678,7 +678,7 @@ impl TitleBar { let y = content_rect.top() + ui.style().spacing.item_spacing.y * 0.5; ui.painter().line_segment( [pos2(left, y), pos2(right, y)], - ui.style().visuals.interacted.inactive.bg_outline, + ui.style().visuals.interacted.inactive.bg_stroke, ); } diff --git a/egui/src/demos/app.rs b/egui/src/demos/app.rs index 8421195e..b4940e0d 100644 --- a/egui/src/demos/app.rs +++ b/egui/src/demos/app.rs @@ -405,11 +405,11 @@ impl DemoWindow { let c = painter.clip_rect().center(); let r = painter.clip_rect().width() / 2.0 - 1.0; let color = Srgba::gray(128); - let line_style = LineStyle::new(1.0, color); - painter.circle_outline(c, r, line_style); - painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], line_style); - painter.line_segment([c, c + r * Vec2::angled(TAU * 1.0 / 8.0)], line_style); - painter.line_segment([c, c + r * Vec2::angled(TAU * 3.0 / 8.0)], line_style); + let stroke = Stroke::new(1.0, color); + painter.circle_stroke(c, r, stroke); + painter.line_segment([c - vec2(0.0, r), c + vec2(0.0, r)], stroke); + painter.line_segment([c, c + r * Vec2::angled(TAU * 1.0 / 8.0)], stroke); + painter.line_segment([c, c + r * Vec2::angled(TAU * 3.0 / 8.0)], stroke); }); }); @@ -584,7 +584,7 @@ impl BoxPainting { pos2(10.0 + pos.x + (i as f32) * (self.size.x * 1.1), pos.y), self.size, ), - outline: LineStyle::new(self.stroke_width, WHITE), + stroke: Stroke::new(self.stroke_width, WHITE), }); } ui.painter().extend(cmds); @@ -655,7 +655,7 @@ impl Painting { painter.add(PaintCmd::Path { points, closed: false, - outline: LineStyle::new(self.line_width, LIGHT_GRAY), + stroke: Stroke::new(self.line_width, LIGHT_GRAY), fill: Default::default(), }); } diff --git a/egui/src/demos/fractal_clock.rs b/egui/src/demos/fractal_clock.rs index 566ad9dc..f6cac5c9 100644 --- a/egui/src/demos/fractal_clock.rs +++ b/egui/src/demos/fractal_clock.rs @@ -55,7 +55,7 @@ impl FractalClock { Frame::popup(ui.style()) .fill(Rgba::luminance_alpha(0.02, 0.5).into()) - .outline(LineStyle::none()) + .stroke(Stroke::none()) .show(&mut ui.left_column(320.0), |ui| { CollapsingHeader::new("Settings").show(ui, |ui| self.options_ui(ui)); }); diff --git a/egui/src/demos/toggle_switch.rs b/egui/src/demos/toggle_switch.rs index 5c51029b..60f9bd4d 100644 --- a/egui/src/demos/toggle_switch.rs +++ b/egui/src/demos/toggle_switch.rs @@ -37,7 +37,7 @@ pub fn toggle(ui: &mut Ui, on: &mut bool) -> Response { rect, corner_radius: radius, fill: lerp(off_color..=on_color, how_on).into(), - outline: style.bg_outline, + stroke: style.bg_stroke, }); // Animate the circle from left to right: let circle_x = lerp((rect.left() + radius)..=(rect.right() - radius), how_on); @@ -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, - outline: style.line_style(), + stroke: style.stroke(), }); // All done! Return the response so the user can check what happened diff --git a/egui/src/lib.rs b/egui/src/lib.rs index 459fa814..78aceded 100644 --- a/egui/src/lib.rs +++ b/egui/src/lib.rs @@ -74,7 +74,7 @@ pub use { layout::*, math::*, memory::Memory, - paint::{color, LineStyle, PaintJobs, Rgba, Srgba, TextStyle, Texture}, + paint::{color, PaintJobs, Rgba, Srgba, Stroke, TextStyle, Texture}, painter::Painter, style::Style, types::*, diff --git a/egui/src/menu.rs b/egui/src/menu.rs index afd60c82..d96938b6 100644 --- a/egui/src/menu.rs +++ b/egui/src/menu.rs @@ -15,7 +15,7 @@ //! } //! ``` -use crate::{color::TRANSPARENT, paint::LineStyle, widgets::*, *}; +use crate::{color::TRANSPARENT, paint::Stroke, widgets::*, *}; /// What is saved between frames. #[derive(Clone, Copy, Debug)] @@ -63,11 +63,11 @@ pub fn bar(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect) let mut style = ui.style().clone(); style.spacing.button_padding = vec2(2.0, 0.0); // style.visuals.interacted.active.bg_fill = TRANSPARENT; - style.visuals.interacted.active.bg_outline = LineStyle::none(); + style.visuals.interacted.active.bg_stroke = Stroke::none(); // style.visuals.interacted.hovered.bg_fill = TRANSPARENT; - style.visuals.interacted.hovered.bg_outline = LineStyle::none(); + style.visuals.interacted.hovered.bg_stroke = Stroke::none(); style.visuals.interacted.inactive.bg_fill = TRANSPARENT; - style.visuals.interacted.inactive.bg_outline = LineStyle::none(); + style.visuals.interacted.inactive.bg_stroke = Stroke::none(); ui.set_style(style); // Take full width and fixed height: @@ -121,7 +121,7 @@ fn menu_impl<'c>( .fixed_pos(button_response.rect.left_bottom()); let frame = Frame::menu(ui.style()); - let resize = Resize::default().auto_sized().outline(false); + let resize = Resize::default().auto_sized().with_stroke(false); let menu_response = area.show(ui.ctx(), |ui| { frame.show(ui, |ui| { @@ -129,11 +129,11 @@ fn menu_impl<'c>( let mut style = ui.style().clone(); style.spacing.button_padding = vec2(2.0, 0.0); // style.visuals.interacted.active.bg_fill = TRANSPARENT; - style.visuals.interacted.active.bg_outline = LineStyle::none(); + style.visuals.interacted.active.bg_stroke = Stroke::none(); // style.visuals.interacted.hovered.bg_fill = TRANSPARENT; - style.visuals.interacted.hovered.bg_outline = LineStyle::none(); + style.visuals.interacted.hovered.bg_stroke = Stroke::none(); style.visuals.interacted.inactive.bg_fill = TRANSPARENT; - style.visuals.interacted.inactive.bg_outline = LineStyle::none(); + style.visuals.interacted.inactive.bg_stroke = Stroke::none(); ui.set_style(style); ui.set_layout(Layout::justified(Direction::Vertical)); add_contents(ui) diff --git a/egui/src/paint.rs b/egui/src/paint.rs index 1ff70963..3326c65a 100644 --- a/egui/src/paint.rs +++ b/egui/src/paint.rs @@ -11,7 +11,7 @@ mod texture_atlas; pub use { color::{Rgba, Srgba}, - command::{LineStyle, PaintCmd}, + command::{PaintCmd, Stroke}, fonts::{FontDefinitions, Fonts, TextStyle}, tessellator::{PaintJobs, PaintOptions, Triangles, Vertex}, texture_atlas::Texture, diff --git a/egui/src/paint/command.rs b/egui/src/paint/command.rs index 0f631bc4..389bc160 100644 --- a/egui/src/paint/command.rs +++ b/egui/src/paint/command.rs @@ -12,11 +12,11 @@ pub enum PaintCmd { center: Pos2, radius: f32, fill: Srgba, - outline: LineStyle, + stroke: Stroke, }, LineSegment { points: [Pos2; 2], - style: LineStyle, + stroke: Stroke, }, Path { points: Vec, @@ -24,13 +24,13 @@ pub enum PaintCmd { /// This is required if `fill != TRANSPARENT`. closed: bool, fill: Srgba, - outline: LineStyle, + stroke: Stroke, }, Rect { rect: Rect, corner_radius: f32, fill: Srgba, - outline: LineStyle, + stroke: Stroke, }, Text { /// Top left corner of the first character. @@ -45,12 +45,12 @@ pub enum PaintCmd { #[derive(Clone, Copy, Debug, Default)] #[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))] -pub struct LineStyle { +pub struct Stroke { pub width: f32, pub color: Srgba, } -impl LineStyle { +impl Stroke { pub fn none() -> Self { Self::new(0.0, crate::color::TRANSPARENT) } @@ -63,11 +63,11 @@ impl LineStyle { } } -impl From<(f32, Color)> for LineStyle +impl From<(f32, Color)> for Stroke where Color: Into, { - fn from((width, color): (f32, Color)) -> LineStyle { - LineStyle::new(width, color) + fn from((width, color): (f32, Color)) -> Stroke { + Stroke::new(width, color) } } diff --git a/egui/src/paint/tessellator.rs b/egui/src/paint/tessellator.rs index 092920d3..e6af1b0e 100644 --- a/egui/src/paint/tessellator.rs +++ b/egui/src/paint/tessellator.rs @@ -9,7 +9,7 @@ use { super::{ color::{self, srgba, Rgba, Srgba, TRANSPARENT}, fonts::Fonts, - LineStyle, PaintCmd, + PaintCmd, Stroke, }, crate::math::*, }; @@ -170,9 +170,9 @@ impl Triangles { pub struct PathPoint { pos: Pos2, - /// For filled paths the normal is used for anti-aliasing (both outlines and filled areas). + /// For filled paths the normal is used for anti-aliasing (both strokes and filled areas). /// - /// For outlines the normal is also used for giving thickness to the path + /// For strokes the normal is also used for giving thickness to the path /// (i.e. in what direction to expand). /// /// The normal could be estimated by differences between successive points, @@ -183,7 +183,7 @@ pub struct PathPoint { } /// A connected line (without thickness or gaps) which can be tessellated -/// to either to an outline (with thickness) or a filled convex area. +/// to either to a stroke (with thickness) or a filled convex area. /// Used as a scratch-pad during tesselation. #[derive(Clone, Debug, Default)] struct Path(Vec); @@ -418,15 +418,15 @@ fn fill_closed_path(path: &[PathPoint], color: Srgba, options: PaintOptions, out } } -/// Tesselate the given path as an outline with thickness. -fn paint_path_outline( +/// Tesselate the given path as a stroke with thickness. +fn stroke_path( path: &[PathPoint], path_type: PathType, - style: LineStyle, + stroke: Stroke, options: PaintOptions, out: &mut Triangles, ) { - if style.width <= 0.0 || style.color == color::TRANSPARENT { + if stroke.width <= 0.0 || stroke.color == color::TRANSPARENT { return; } @@ -440,10 +440,10 @@ fn paint_path_outline( }; if options.anti_alias { - let color_inner = style.color; + let color_inner = stroke.color; let color_outer = color::TRANSPARENT; - let thin_line = style.width <= options.aa_size; + let thin_line = stroke.width <= options.aa_size; if thin_line { /* We paint the line using three edges: outer, inner, outer. @@ -453,7 +453,7 @@ fn paint_path_outline( */ // Fade out as it gets thinner: - let color_inner = mul_color(color_inner, style.width / options.aa_size); + let color_inner = mul_color(color_inner, stroke.width / options.aa_size); if color_inner == color::TRANSPARENT { return; } @@ -502,8 +502,8 @@ fn paint_path_outline( let mut i0 = n - 1; for i1 in 0..n { let connect_with_previous = path_type == PathType::Closed || i1 > 0; - let inner_rad = 0.5 * (style.width - options.aa_size); - let outer_rad = 0.5 * (style.width + options.aa_size); + let inner_rad = 0.5 * (stroke.width - options.aa_size); + let outer_rad = 0.5 * (stroke.width + options.aa_size); let p1 = &path[i1 as usize]; let p = p1.pos; let n = p1.normal; @@ -543,11 +543,11 @@ fn paint_path_outline( ); } - let thin_line = style.width <= options.aa_size; + let thin_line = stroke.width <= options.aa_size; if thin_line { // Fade out thin lines rather than making them thinner let radius = options.aa_size / 2.0; - let color = mul_color(style.color, style.width / options.aa_size); + let color = mul_color(stroke.color, stroke.width / options.aa_size); if color == color::TRANSPARENT { return; } @@ -556,12 +556,12 @@ fn paint_path_outline( out.vertices.push(vert(p.pos - radius * p.normal, color)); } } else { - let radius = style.width / 2.0; + let radius = stroke.width / 2.0; for p in path { out.vertices - .push(vert(p.pos + radius * p.normal, style.color)); + .push(vert(p.pos + radius * p.normal, stroke.color)); out.vertices - .push(vert(p.pos - radius * p.normal, style.color)); + .push(vert(p.pos - radius * p.normal, stroke.color)); } } } @@ -600,26 +600,26 @@ fn tessellate_paint_command( center, radius, fill, - outline, + stroke, } => { if radius > 0.0 { path.add_circle(center, radius); fill_closed_path(&path.0, fill, options, out); - paint_path_outline(&path.0, Closed, outline, options, out); + stroke_path(&path.0, Closed, stroke, options, out); } } PaintCmd::Triangles(triangles) => { out.append(&triangles); } - PaintCmd::LineSegment { points, style } => { + PaintCmd::LineSegment { points, stroke } => { path.add_line_segment(points); - paint_path_outline(&path.0, Open, style, options, out); + stroke_path(&path.0, Open, stroke, options, out); } PaintCmd::Path { points, closed, fill, - outline, + stroke, } => { if points.len() >= 2 { if closed { @@ -636,14 +636,14 @@ fn tessellate_paint_command( fill_closed_path(&path.0, fill, options, out); } let typ = if closed { Closed } else { Open }; - paint_path_outline(&path.0, typ, outline, options, out); + stroke_path(&path.0, typ, stroke, options, out); } } PaintCmd::Rect { mut rect, corner_radius, fill, - outline, + stroke, } => { if !rect.is_empty() { // It is common to (sometimes accidentally) create an infinitely sized rectangle. @@ -654,7 +654,7 @@ fn tessellate_paint_command( path::rounded_rectangle(scratchpad_points, rect, corner_radius); path.add_line_loop(scratchpad_points); fill_closed_path(&path.0, fill, options, out); - paint_path_outline(&path.0, Closed, outline, options, out); + stroke_path(&path.0, Closed, stroke, options, out); } } PaintCmd::Text { @@ -746,7 +746,7 @@ pub fn tessellate_paint_commands( rect: *clip_rect, corner_radius: 0.0, fill: Default::default(), - outline: LineStyle::new(2.0, srgba(150, 255, 150, 255)), + stroke: Stroke::new(2.0, srgba(150, 255, 150, 255)), }, options, fonts, diff --git a/egui/src/painter.rs b/egui/src/painter.rs index a6aed48f..52e1feeb 100644 --- a/egui/src/painter.rs +++ b/egui/src/painter.rs @@ -4,7 +4,7 @@ use crate::{ anchor_rect, color, layers::PaintCmdIdx, math::{Pos2, Rect, Vec2}, - paint::{font, Fonts, LineStyle, PaintCmd, TextStyle}, + paint::{font, Fonts, PaintCmd, Stroke, TextStyle}, Align, Context, Layer, Srgba, }; @@ -115,7 +115,7 @@ impl Painter { /// ## Debug painting impl Painter { pub fn debug_rect(&mut self, rect: Rect, color: Srgba, text: impl Into) { - self.rect_outline(rect, 0.0, (1.0, color)); + self.rect_stroke(rect, 0.0, (1.0, color)); let anchor = (Align::Min, Align::Min); let text_style = TextStyle::Monospace; self.text(rect.min, anchor, text.into(), text_style, color); @@ -132,7 +132,7 @@ impl Painter { rect: rect.expand(2.0), corner_radius: 0.0, fill: Srgba::black_alpha(240), - outline: LineStyle::new(1.0, color::RED), + stroke: Stroke::new(1.0, color::RED), }); self.galley(rect.min, galley, text_style, color::RED); } @@ -140,10 +140,10 @@ impl Painter { /// # Paint different primitives impl Painter { - pub fn line_segment(&self, points: [Pos2; 2], style: impl Into) { + pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into) { self.add(PaintCmd::LineSegment { points, - style: style.into(), + stroke: stroke.into(), }); } @@ -152,16 +152,16 @@ impl Painter { center, radius, fill: fill_color.into(), - outline: Default::default(), + stroke: Default::default(), }); } - pub fn circle_outline(&self, center: Pos2, radius: f32, outline: impl Into) { + pub fn circle_stroke(&self, center: Pos2, radius: f32, stroke: impl Into) { self.add(PaintCmd::Circle { center, radius, fill: Default::default(), - outline: outline.into(), + stroke: stroke.into(), }); } @@ -170,16 +170,16 @@ impl Painter { rect, corner_radius, fill: fill_color.into(), - outline: Default::default(), + stroke: Default::default(), }); } - pub fn rect_outline(&self, rect: Rect, corner_radius: f32, outline: impl Into) { + pub fn rect_stroke(&self, rect: Rect, corner_radius: f32, stroke: impl Into) { self.add(PaintCmd::Rect { rect, corner_radius, fill: Default::default(), - outline: outline.into(), + stroke: stroke.into(), }); } } diff --git a/egui/src/style.rs b/egui/src/style.rs index 5c40c674..8a1758ab 100644 --- a/egui/src/style.rs +++ b/egui/src/style.rs @@ -1,6 +1,6 @@ #![allow(clippy::if_same_then_else)] -use crate::{color::*, math::*, paint::LineStyle, types::*}; +use crate::{color::*, math::*, paint::Stroke, types::*}; /// Specifies the look and feel of a `Ui`. #[derive(Clone, Debug)] @@ -92,7 +92,7 @@ pub struct Visuals { /// For stuff like check marks in check boxes. pub line_width: f32, - pub thin_outline: LineStyle, + pub thin_stroke: Stroke, /// e.g. the background of windows pub background_fill: Srgba, @@ -108,7 +108,7 @@ pub struct Visuals { pub cursor_blink_hz: f32, pub text_cursor_width: f32, - /// Allow child widgets to be just on the border and still have an outline with some thickness + /// Allow child widgets to be just on the border and still have a stroke with some thickness pub clip_rect_margin: f32, // ----------------------------------------------- @@ -148,7 +148,7 @@ pub struct WidgetVisuals { /// For surrounding rectangle of things that need it, /// like buttons, the box of the checkbox, etc. - pub bg_outline: LineStyle, + pub bg_stroke: Stroke, /// Button frames etc pub corner_radius: f32, @@ -165,8 +165,8 @@ pub struct WidgetVisuals { } impl WidgetVisuals { - pub fn line_style(&self) -> LineStyle { - LineStyle::new(self.stroke_width, self.stroke_color) + pub fn stroke(&self) -> Stroke { + Stroke::new(self.stroke_width, self.stroke_color) } } @@ -214,7 +214,7 @@ impl Default for Visuals { interacted: Default::default(), text_color: Srgba::gray(160), line_width: 0.5, - thin_outline: LineStyle::new(0.5, GRAY), + thin_stroke: Stroke::new(0.5, GRAY), background_fill: Rgba::luminance_alpha(0.013, 0.95).into(), dark_bg_color: Srgba::black_alpha(140), window_corner_radius: 10.0, @@ -233,7 +233,7 @@ impl Default for Interacted { Self { active: WidgetVisuals { bg_fill: Srgba::black_alpha(128), - bg_outline: LineStyle::new(2.0, WHITE), + bg_stroke: Stroke::new(2.0, WHITE), corner_radius: 4.0, main_fill: srgba(120, 120, 200, 255), stroke_color: WHITE, @@ -241,7 +241,7 @@ impl Default for Interacted { }, hovered: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.06, 0.5).into(), - bg_outline: LineStyle::new(1.0, Rgba::white_alpha(0.5)), + 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), @@ -249,7 +249,7 @@ impl Default for Interacted { }, inactive: WidgetVisuals { bg_fill: Rgba::luminance_alpha(0.04, 0.5).into(), - bg_outline: LineStyle::new(1.0, Rgba::white_alpha(0.04)), + 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! @@ -257,7 +257,7 @@ impl Default for Interacted { }, disabled: WidgetVisuals { bg_fill: TRANSPARENT, - bg_outline: LineStyle::new(0.5, Srgba::gray(70)), + 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 @@ -362,7 +362,7 @@ impl WidgetVisuals { pub fn ui(&mut self, ui: &mut crate::Ui) { let Self { bg_fill, - bg_outline, + bg_stroke, corner_radius, main_fill, stroke_color, @@ -370,7 +370,7 @@ impl WidgetVisuals { } = self; ui_color(ui, bg_fill, "bg_fill"); - bg_outline.ui(ui, "bg_outline"); + 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"); @@ -388,7 +388,7 @@ impl Visuals { interacted, text_color, line_width, - thin_outline, + thin_stroke, background_fill, dark_bg_color, window_corner_radius, @@ -403,7 +403,7 @@ impl Visuals { ui.collapsing("interacted", |ui| interacted.ui(ui)); ui_color(ui, text_color, "text_color"); ui.add(Slider::f32(line_width, 0.0..=10.0).text("line_width")); - thin_outline.ui(ui, "thin_outline"); + thin_stroke.ui(ui, "thin_stroke"); ui_color(ui, background_fill, "background_fill"); ui_color(ui, dark_bg_color, "dark_bg_color"); ui.add(Slider::f32(window_corner_radius, 0.0..=20.0).text("window_corner_radius")); @@ -420,7 +420,7 @@ impl Visuals { } } -impl LineStyle { +impl Stroke { pub fn ui(&mut self, ui: &mut crate::Ui, text: &str) { let Self { width, color } = self; ui.horizontal_centered(|ui| { diff --git a/egui/src/ui.rs b/egui/src/ui.rs index 4f3a3087..6eaf8f85 100644 --- a/egui/src/ui.rs +++ b/egui/src/ui.rs @@ -367,7 +367,7 @@ impl Ui { let rect = self.reserve_space_impl(desired_size); if self.style().visuals.debug_widget_rects { - self.painter.rect_outline(rect, 0.0, (1.0, LIGHT_BLUE)); + self.painter.rect_stroke(rect, 0.0, (1.0, LIGHT_BLUE)); let color = color::srgba(200, 0, 0, 255); let width = 2.5; diff --git a/egui/src/widgets.rs b/egui/src/widgets.rs index 6786082c..8954364d 100644 --- a/egui/src/widgets.rs +++ b/egui/src/widgets.rs @@ -295,7 +295,7 @@ impl Widget for Button { rect: response.rect, corner_radius: ui.style().interact(&response).corner_radius, fill, - outline: ui.style().interact(&response).bg_outline, + stroke: ui.style().interact(&response).bg_stroke, }); let stroke_color = ui.style().interact(&response).stroke_color; let text_color = text_color.unwrap_or(stroke_color); @@ -365,10 +365,10 @@ impl<'a> Widget for Checkbox<'a> { rect: big_icon_rect, corner_radius: ui.style().interact(&response).corner_radius, fill: ui.style().interact(&response).bg_fill, - outline: ui.style().interact(&response).bg_outline, + stroke: ui.style().interact(&response).bg_stroke, }); - let line_style = ui.style().interact(&response).line_style(); + let stroke = ui.style().interact(&response).stroke(); if *checked { ui.painter().add(PaintCmd::Path { @@ -378,12 +378,12 @@ impl<'a> Widget for Checkbox<'a> { pos2(small_icon_rect.right(), small_icon_rect.top()), ], closed: false, - outline: line_style, + stroke, fill: Default::default(), }); } - let text_color = text_color.unwrap_or(line_style.color); + let text_color = text_color.unwrap_or(stroke.color); ui.painter() .galley(text_cursor, galley, text_style, text_color); response @@ -452,7 +452,7 @@ impl Widget for RadioButton { center: big_icon_rect.center(), radius: big_icon_rect.width() / 2.0, fill: bg_fill, - outline: ui.style().interact(&response).bg_outline, + stroke: ui.style().interact(&response).bg_stroke, }); if checked { @@ -460,7 +460,7 @@ impl Widget for RadioButton { center: small_icon_rect.center(), radius: small_icon_rect.width() / 3.0, fill: stroke_color, - outline: Default::default(), + stroke: Default::default(), }); } diff --git a/egui/src/widgets/slider.rs b/egui/src/widgets/slider.rs index c911f34c..69853d0c 100644 --- a/egui/src/widgets/slider.rs +++ b/egui/src/widgets/slider.rs @@ -165,14 +165,14 @@ impl<'a> Slider<'a> { rect: rail_rect, corner_radius: rail_radius, fill: ui.style().visuals.interacted.inactive.bg_fill, - outline: ui.style().visuals.interacted.inactive.bg_outline, + stroke: ui.style().visuals.interacted.inactive.bg_stroke, }); ui.painter().add(PaintCmd::Circle { center: pos2(marker_center_x, rail_rect.center().y), radius: handle_radius(rect), fill: ui.style().interact(response).main_fill, - outline: LineStyle::new( + stroke: Stroke::new( ui.style().interact(response).stroke_width, ui.style().interact(response).stroke_color, ), diff --git a/egui/src/widgets/text_edit.rs b/egui/src/widgets/text_edit.rs index bfe1041e..78d6ba72 100644 --- a/egui/src/widgets/text_edit.rs +++ b/egui/src/widgets/text_edit.rs @@ -184,7 +184,7 @@ impl<'t> Widget for TextEdit<'t> { rect: bg_rect, corner_radius: ui.style().interact(&response).corner_radius, fill: ui.style().visuals.dark_bg_color, - outline: ui.style().interact(&response).bg_outline, + stroke: ui.style().interact(&response).bg_stroke, }); }