[refactor] rename Outline to LineStyle

This commit is contained in:
Emil Ernerfeldt 2020-05-23 14:07:49 +02:00
parent ef7f3c4637
commit 0bb042924f
10 changed files with 30 additions and 30 deletions

View file

@ -1,6 +1,6 @@
use crate::{ use crate::{
layout::Direction, layout::Direction,
paint::{Outline, PaintCmd, Path, TextStyle}, paint::{LineStyle, PaintCmd, Path, TextStyle},
widgets::Label, widgets::Label,
*, *,
}; };
@ -87,7 +87,7 @@ impl State {
path: Path::from_point_loop(&points), path: Path::from_point_loop(&points),
closed: true, closed: true,
fill_color: None, fill_color: None,
outline: Some(Outline::new(stroke_width, stroke_color)), outline: Some(LineStyle::new(stroke_width, stroke_color)),
}); });
} }

View file

@ -8,7 +8,7 @@ pub struct Frame {
pub margin: Vec2, pub margin: Vec2,
pub corner_radius: f32, pub corner_radius: f32,
pub fill_color: Option<Color>, pub fill_color: Option<Color>,
pub outline: Option<Outline>, pub outline: Option<LineStyle>,
} }
impl Frame { impl Frame {
@ -26,7 +26,7 @@ impl Frame {
margin: Vec2::splat(1.0), margin: Vec2::splat(1.0),
corner_radius: 0.0, corner_radius: 0.0,
fill_color: None, fill_color: None,
outline: Some(Outline::new(0.5, color::white(128))), outline: Some(LineStyle::new(0.5, color::white(128))),
} }
} }
@ -35,7 +35,7 @@ impl Frame {
margin: Vec2::splat(1.0), margin: Vec2::splat(1.0),
corner_radius: 2.0, corner_radius: 2.0,
fill_color: Some(style.background_fill_color), fill_color: Some(style.background_fill_color),
outline: Some(Outline::new(1.0, color::white(128))), outline: Some(LineStyle::new(1.0, color::white(128))),
} }
} }
@ -44,7 +44,7 @@ impl Frame {
margin: style.window_padding, margin: style.window_padding,
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::new(1.0, color::white(128))), outline: Some(LineStyle::new(1.0, color::white(128))),
} }
} }
@ -53,7 +53,7 @@ impl Frame {
self self
} }
pub fn outline(mut self, outline: Option<Outline>) -> Self { pub fn outline(mut self, outline: Option<LineStyle>) -> Self {
self.outline = outline; self.outline = outline;
self self
} }

View file

@ -363,7 +363,7 @@ impl Context {
PaintCmd::Rect { PaintCmd::Rect {
corner_radius: 0.0, corner_radius: 0.0,
fill_color: Some(color::gray(0, 240)), fill_color: Some(color::gray(0, 240)),
outline: Some(Outline::new(1.0, color::RED)), outline: Some(LineStyle::new(1.0, color::RED)),
rect: rect.expand(2.0), rect: rect.expand(2.0),
}, },
); );
@ -392,7 +392,7 @@ impl Context {
PaintCmd::Rect { PaintCmd::Rect {
corner_radius: 0.0, corner_radius: 0.0,
fill_color: None, fill_color: None,
outline: Some(Outline::new(1.0, color::RED)), outline: Some(LineStyle::new(1.0, color::RED)),
rect, rect,
}, },
); );

View file

@ -406,7 +406,7 @@ impl BoxPainting {
pos2(10.0 + pos.x + (i as f32) * (self.size.x * 1.1), pos.y), pos2(10.0 + pos.x + (i as f32) * (self.size.x * 1.1), pos.y),
self.size, self.size,
), ),
outline: Some(Outline::new(self.stroke_width, gray(255, 255))), outline: Some(LineStyle::new(self.stroke_width, gray(255, 255))),
}); });
} }
ui.add_paint_cmds(cmds); ui.add_paint_cmds(cmds);

View file

@ -7,7 +7,7 @@ mod texture_atlas;
pub use { pub use {
color::Color, color::Color,
command::{Outline, PaintCmd}, command::{LineStyle, PaintCmd},
fonts::{FontDefinitions, Fonts, TextStyle}, fonts::{FontDefinitions, Fonts, TextStyle},
mesher::{PaintBatches, PaintOptions, Path, Triangles, Vertex}, mesher::{PaintBatches, PaintOptions, Path, Triangles, Vertex},
texture_atlas::Texture, texture_atlas::Texture,

View file

@ -11,7 +11,7 @@ pub enum PaintCmd {
Circle { Circle {
center: Pos2, center: Pos2,
fill_color: Option<Color>, fill_color: Option<Color>,
outline: Option<Outline>, outline: Option<LineStyle>,
radius: f32, radius: f32,
}, },
LineSegment { LineSegment {
@ -29,15 +29,14 @@ pub enum PaintCmd {
path: Path, path: Path,
closed: bool, closed: bool,
fill_color: Option<Color>, fill_color: Option<Color>,
outline: Option<Outline>, outline: Option<LineStyle>,
}, },
Rect { Rect {
rect: Rect, rect: Rect,
corner_radius: f32, corner_radius: f32,
fill_color: Option<Color>, fill_color: Option<Color>,
outline: Option<Outline>, outline: Option<LineStyle>,
}, },
/// Paint a single line of text
Text { Text {
/// Top left corner of the first character. /// Top left corner of the first character.
pos: Pos2, pos: Pos2,
@ -59,13 +58,14 @@ impl PaintCmd {
} }
} }
// TODO: rename LineStyle
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
pub struct Outline { pub struct LineStyle {
pub width: f32, pub width: f32,
pub color: Color, pub color: Color,
} }
impl Outline { impl LineStyle {
pub fn new(width: impl Into<f32>, color: impl Into<Color>) -> Self { pub fn new(width: impl Into<f32>, color: impl Into<Color>) -> Self {
Self { Self {
width: width.into(), width: width.into(),

View file

@ -5,7 +5,7 @@ use {
super::{ super::{
color::{self, srgba, Color}, color::{self, srgba, Color},
fonts::Fonts, fonts::Fonts,
Outline, PaintCmd, LineStyle, PaintCmd,
}, },
crate::math::*, crate::math::*,
}; };
@ -693,7 +693,7 @@ pub fn paint_commands_into_triangles(
rect: *clip_rect, rect: *clip_rect,
corner_radius: 0.0, corner_radius: 0.0,
fill_color: None, fill_color: None,
outline: Some(Outline::new(2.0, srgba(150, 255, 150, 255))), outline: Some(LineStyle::new(2.0, srgba(150, 255, 150, 255))),
}, },
triangles, triangles,
) )

View file

@ -2,7 +2,7 @@
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use crate::{color::*, math::*, paint::Outline, types::*}; use crate::{color::*, math::*, paint::LineStyle, types::*};
// TODO: split into Spacing and Style? // TODO: split into Spacing and Style?
#[derive(Clone, Copy, Debug, Deserialize, Serialize)] #[derive(Clone, Copy, Debug, Deserialize, Serialize)]
@ -36,7 +36,7 @@ pub struct Style {
/// For stuff like check marks in check boxes. /// For stuff like check marks in check boxes.
pub line_width: f32, pub line_width: f32,
pub thin_outline: Outline, pub thin_outline: LineStyle,
/// e.g. the background of windows /// e.g. the background of windows
pub background_fill_color: Color, pub background_fill_color: Color,
@ -75,7 +75,7 @@ impl Default for Style {
interact: Default::default(), interact: Default::default(),
text_color: gray(160, 255), text_color: gray(160, 255),
line_width: 1.0, line_width: 1.0,
thin_outline: Outline::new(0.5, GRAY), thin_outline: LineStyle::new(0.5, GRAY),
background_fill_color: gray(32, 250), background_fill_color: gray(32, 250),
dark_bg_color: gray(0, 140), dark_bg_color: gray(0, 140),
cursor_blink_hz: 1.0, cursor_blink_hz: 1.0,
@ -104,7 +104,7 @@ impl Default for Interact {
fill_color: srgba(120, 120, 200, 255), fill_color: srgba(120, 120, 200, 255),
stroke_color: WHITE, stroke_color: WHITE,
stroke_width: 2.0, stroke_width: 2.0,
rect_outline: Some(Outline::new(2.0, WHITE)), rect_outline: Some(LineStyle::new(2.0, WHITE)),
corner_radius: 5.0, corner_radius: 5.0,
}, },
hovered: WidgetStyle { hovered: WidgetStyle {
@ -112,7 +112,7 @@ impl Default for Interact {
fill_color: srgba(100, 100, 150, 255), fill_color: srgba(100, 100, 150, 255),
stroke_color: gray(240, 255), stroke_color: gray(240, 255),
stroke_width: 1.5, stroke_width: 1.5,
rect_outline: Some(Outline::new(1.0, WHITE)), rect_outline: Some(LineStyle::new(1.0, WHITE)),
corner_radius: 5.0, corner_radius: 5.0,
}, },
inactive: WidgetStyle { inactive: WidgetStyle {
@ -120,7 +120,7 @@ impl Default for Interact {
fill_color: srgba(60, 60, 80, 255), fill_color: srgba(60, 60, 80, 255),
stroke_color: gray(210, 255), // Mustn't look grayed out! stroke_color: gray(210, 255), // Mustn't look grayed out!
stroke_width: 1.0, stroke_width: 1.0,
rect_outline: Some(Outline::new(1.0, white(128))), rect_outline: Some(LineStyle::new(1.0, white(128))),
corner_radius: 0.0, corner_radius: 0.0,
}, },
} }
@ -156,7 +156,7 @@ pub struct WidgetStyle {
/// For surrounding rectangle of things that need it, /// For surrounding rectangle of things that need it,
/// like buttons, the box of the checkbox, etc. /// like buttons, the box of the checkbox, etc.
pub rect_outline: Option<Outline>, pub rect_outline: Option<LineStyle>,
/// Button frames etdc /// Button frames etdc
pub corner_radius: f32, pub corner_radius: f32,

View file

@ -358,7 +358,7 @@ impl Ui {
self.add_paint_cmd(PaintCmd::Rect { self.add_paint_cmd(PaintCmd::Rect {
rect, rect,
corner_radius: 0.0, corner_radius: 0.0,
outline: Some(Outline::new(1.0, LIGHT_BLUE)), outline: Some(LineStyle::new(1.0, LIGHT_BLUE)),
fill_color: None, fill_color: None,
}); });
@ -442,7 +442,7 @@ impl Ui {
self.add_paint_cmd(PaintCmd::Rect { self.add_paint_cmd(PaintCmd::Rect {
corner_radius: 0.0, corner_radius: 0.0,
fill_color: None, fill_color: None,
outline: Some(Outline::new(1.0, color::RED)), outline: Some(LineStyle::new(1.0, color::RED)),
rect, rect,
}); });
let align = (Align::Min, Align::Min); let align = (Align::Min, Align::Min);

View file

@ -175,14 +175,14 @@ impl<'a> Widget for Slider<'a> {
rect: rail_rect, rect: rail_rect,
corner_radius: rail_radius, corner_radius: rail_radius,
fill_color: Some(ui.style().background_fill_color), fill_color: Some(ui.style().background_fill_color),
outline: Some(Outline::new(1.0, color::gray(200, 255))), // TODO outline: Some(LineStyle::new(1.0, color::gray(200, 255))), // TODO
}); });
ui.add_paint_cmd(PaintCmd::Circle { ui.add_paint_cmd(PaintCmd::Circle {
center: pos2(marker_center_x, rail_rect.center().y), center: pos2(marker_center_x, rail_rect.center().y),
radius: handle_radius, radius: handle_radius,
fill_color: Some(ui.style().interact(&interact).fill_color), fill_color: Some(ui.style().interact(&interact).fill_color),
outline: Some(Outline::new( outline: Some(LineStyle::new(
ui.style().interact(&interact).stroke_width, ui.style().interact(&interact).stroke_width,
ui.style().interact(&interact).stroke_color, ui.style().interact(&interact).stroke_color,
)), )),