[refactor] Remove Option wrappers around colors and line styles
Just use transparency instead of None
This commit is contained in:
parent
413ed6999e
commit
96153a86e5
17 changed files with 108 additions and 116 deletions
|
@ -123,8 +123,8 @@ pub fn paint_icon(ui: &mut Ui, openness: f32, response: &Response) {
|
||||||
ui.painter().add(PaintCmd::Path {
|
ui.painter().add(PaintCmd::Path {
|
||||||
path: Path::from_point_loop(&points),
|
path: Path::from_point_loop(&points),
|
||||||
closed: true,
|
closed: true,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: Some(LineStyle::new(stroke_width, stroke_color)),
|
outline: LineStyle::new(stroke_width, stroke_color),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -229,10 +229,10 @@ impl CollapsingHeader {
|
||||||
painter.set(
|
painter.set(
|
||||||
bg_index,
|
bg_index,
|
||||||
PaintCmd::Rect {
|
PaintCmd::Rect {
|
||||||
|
rect: response.rect,
|
||||||
corner_radius: ui.style().interact(&response).corner_radius,
|
corner_radius: ui.style().interact(&response).corner_radius,
|
||||||
fill: ui.style().interact(&response).bg_fill,
|
fill: ui.style().interact(&response).bg_fill,
|
||||||
outline: None,
|
outline: Default::default(),
|
||||||
rect: response.rect,
|
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ pub struct Frame {
|
||||||
// On each side
|
// On each side
|
||||||
pub margin: Vec2,
|
pub margin: Vec2,
|
||||||
pub corner_radius: f32,
|
pub corner_radius: f32,
|
||||||
pub fill: Option<Srgba>,
|
pub fill: Srgba,
|
||||||
pub outline: Option<LineStyle>,
|
pub outline: LineStyle,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Frame {
|
impl Frame {
|
||||||
|
@ -17,7 +17,7 @@ impl Frame {
|
||||||
Self {
|
Self {
|
||||||
margin: style.spacing.window_padding,
|
margin: style.spacing.window_padding,
|
||||||
corner_radius: style.visuals.window_corner_radius,
|
corner_radius: style.visuals.window_corner_radius,
|
||||||
fill: Some(style.visuals.background_fill),
|
fill: style.visuals.background_fill,
|
||||||
outline: style.visuals.interacted.inactive.bg_outline, // because we can resize windows
|
outline: style.visuals.interacted.inactive.bg_outline, // because we can resize windows
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -26,8 +26,8 @@ impl Frame {
|
||||||
Self {
|
Self {
|
||||||
margin: Vec2::splat(1.0),
|
margin: Vec2::splat(1.0),
|
||||||
corner_radius: 0.0,
|
corner_radius: 0.0,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: Some(LineStyle::new(0.5, Srgba::gray(128))),
|
outline: LineStyle::new(0.5, Srgba::gray(128)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ impl Frame {
|
||||||
Self {
|
Self {
|
||||||
margin: Vec2::splat(1.0),
|
margin: Vec2::splat(1.0),
|
||||||
corner_radius: 2.0,
|
corner_radius: 2.0,
|
||||||
fill: Some(style.visuals.background_fill),
|
fill: style.visuals.background_fill,
|
||||||
outline: Some(LineStyle::new(1.0, Srgba::gray(128))),
|
outline: LineStyle::new(1.0, Srgba::gray(128)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,17 +44,17 @@ impl Frame {
|
||||||
Self {
|
Self {
|
||||||
margin: style.spacing.window_padding,
|
margin: style.spacing.window_padding,
|
||||||
corner_radius: 5.0,
|
corner_radius: 5.0,
|
||||||
fill: Some(style.visuals.background_fill),
|
fill: style.visuals.background_fill,
|
||||||
outline: Some(LineStyle::new(1.0, Srgba::gray(128))),
|
outline: LineStyle::new(1.0, Srgba::gray(128)),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn fill(mut self, fill: Option<Srgba>) -> Self {
|
pub fn fill(mut self, fill: Srgba) -> Self {
|
||||||
self.fill = fill;
|
self.fill = fill;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn outline(mut self, outline: Option<LineStyle>) -> Self {
|
pub fn outline(mut self, outline: LineStyle) -> Self {
|
||||||
self.outline = outline;
|
self.outline = outline;
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
|
|
|
@ -237,8 +237,8 @@ impl Resize {
|
||||||
ui.painter().add(paint::PaintCmd::Rect {
|
ui.painter().add(paint::PaintCmd::Rect {
|
||||||
rect,
|
rect,
|
||||||
corner_radius: 3.0,
|
corner_radius: 3.0,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: Some(ui.style().visuals.thin_outline),
|
outline: ui.style().visuals.thin_outline,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -243,14 +243,14 @@ impl Prepared {
|
||||||
ui.painter().add(paint::PaintCmd::Rect {
|
ui.painter().add(paint::PaintCmd::Rect {
|
||||||
rect: outer_scroll_rect,
|
rect: outer_scroll_rect,
|
||||||
corner_radius,
|
corner_radius,
|
||||||
fill: Some(ui.style().visuals.dark_bg_color),
|
fill: ui.style().visuals.dark_bg_color,
|
||||||
outline: None,
|
outline: Default::default(),
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.painter().add(paint::PaintCmd::Rect {
|
ui.painter().add(paint::PaintCmd::Rect {
|
||||||
rect: handle_rect.expand(-2.0),
|
rect: handle_rect.expand(-2.0),
|
||||||
corner_radius,
|
corner_radius,
|
||||||
fill: Some(handle_fill),
|
fill: handle_fill,
|
||||||
outline: handle_outline,
|
outline: handle_outline,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -311,12 +311,11 @@ impl<'open> Window<'open> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn paint_resize_corner(ui: &mut Ui, outer_rect: Rect, frame_outline: Option<LineStyle>) {
|
fn paint_resize_corner(ui: &mut Ui, outer_rect: Rect, outline: LineStyle) {
|
||||||
let corner_size = Vec2::splat(ui.style().visuals.resize_corner_size);
|
let corner_size = Vec2::splat(ui.style().visuals.resize_corner_size);
|
||||||
let handle_offset = -Vec2::splat(2.0);
|
let handle_offset = -Vec2::splat(2.0);
|
||||||
let corner_rect =
|
let corner_rect =
|
||||||
Rect::from_min_size(outer_rect.max - corner_size + handle_offset, corner_size);
|
Rect::from_min_size(outer_rect.max - corner_size + handle_offset, corner_size);
|
||||||
let outline = frame_outline.unwrap_or_else(|| LineStyle::new(1.0, color::GRAY));
|
|
||||||
crate::resize::paint_resize_corner_with_style(ui, &corner_rect, outline);
|
crate::resize::paint_resize_corner_with_style(ui, &corner_rect, outline);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -566,7 +565,7 @@ fn paint_frame_interaction(
|
||||||
ui.painter().add(PaintCmd::Path {
|
ui.painter().add(PaintCmd::Path {
|
||||||
path,
|
path,
|
||||||
closed: false,
|
closed: false,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: visuals.bg_outline,
|
outline: visuals.bg_outline,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -671,7 +670,7 @@ impl TitleBar {
|
||||||
let y = content_rect.top() + ui.style().spacing.item_spacing.y * 0.5;
|
let y = content_rect.top() + ui.style().spacing.item_spacing.y * 0.5;
|
||||||
ui.painter().line_segment(
|
ui.painter().line_segment(
|
||||||
[pos2(left, y), pos2(right, y)],
|
[pos2(left, y), pos2(right, y)],
|
||||||
ui.style().visuals.interacted.inactive.bg_outline.unwrap(),
|
ui.style().visuals.interacted.inactive.bg_outline,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -579,12 +579,12 @@ impl BoxPainting {
|
||||||
for i in 0..self.num_boxes {
|
for i in 0..self.num_boxes {
|
||||||
cmds.push(PaintCmd::Rect {
|
cmds.push(PaintCmd::Rect {
|
||||||
corner_radius: self.corner_radius,
|
corner_radius: self.corner_radius,
|
||||||
fill: Some(Srgba::gray(64)),
|
fill: Srgba::gray(64),
|
||||||
rect: Rect::from_min_size(
|
rect: Rect::from_min_size(
|
||||||
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(LineStyle::new(self.stroke_width, WHITE)),
|
outline: LineStyle::new(self.stroke_width, WHITE),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ui.painter().extend(cmds);
|
ui.painter().extend(cmds);
|
||||||
|
@ -655,8 +655,8 @@ impl Painting {
|
||||||
painter.add(PaintCmd::Path {
|
painter.add(PaintCmd::Path {
|
||||||
path: Path::from_open_points(&points),
|
path: Path::from_open_points(&points),
|
||||||
closed: false,
|
closed: false,
|
||||||
outline: Some(LineStyle::new(self.line_width, LIGHT_GRAY)),
|
outline: LineStyle::new(self.line_width, LIGHT_GRAY),
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,7 +37,7 @@ impl FractalClock {
|
||||||
.default_rect(ctx.rect().expand(-42.0))
|
.default_rect(ctx.rect().expand(-42.0))
|
||||||
.scroll(false)
|
.scroll(false)
|
||||||
// Dark background frame to make it pop:
|
// Dark background frame to make it pop:
|
||||||
.frame(Frame::window(&ctx.style()).fill(Some(Srgba::black_alpha(250))))
|
.frame(Frame::window(&ctx.style()).fill(Srgba::black_alpha(250)))
|
||||||
.show(ctx, |ui| self.ui(ui));
|
.show(ctx, |ui| self.ui(ui));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,8 +54,8 @@ impl FractalClock {
|
||||||
self.fractal_ui(&painter);
|
self.fractal_ui(&painter);
|
||||||
|
|
||||||
Frame::popup(ui.style())
|
Frame::popup(ui.style())
|
||||||
.fill(Some(Rgba::luminance_alpha(0.02, 0.5).into()))
|
.fill(Rgba::luminance_alpha(0.02, 0.5).into())
|
||||||
.outline(None)
|
.outline(LineStyle::none())
|
||||||
.show(&mut ui.left_column(320.0), |ui| {
|
.show(&mut ui.left_column(320.0), |ui| {
|
||||||
CollapsingHeader::new("Settings").show(ui, |ui| self.options_ui(ui));
|
CollapsingHeader::new("Settings").show(ui, |ui| self.options_ui(ui));
|
||||||
});
|
});
|
||||||
|
|
|
@ -36,16 +36,16 @@ pub fn toggle(ui: &mut Ui, on: &mut bool) -> Response {
|
||||||
ui.painter().add(PaintCmd::Rect {
|
ui.painter().add(PaintCmd::Rect {
|
||||||
rect,
|
rect,
|
||||||
corner_radius: radius,
|
corner_radius: radius,
|
||||||
|
fill: lerp(off_color..=on_color, how_on).into(),
|
||||||
outline: style.bg_outline,
|
outline: style.bg_outline,
|
||||||
fill: Some(lerp(off_color..=on_color, how_on).into()),
|
|
||||||
});
|
});
|
||||||
// Animate the circle from left to right:
|
// Animate the circle from left to right:
|
||||||
let circle_x = lerp((rect.left() + radius)..=(rect.right() - radius), how_on);
|
let circle_x = lerp((rect.left() + radius)..=(rect.right() - radius), how_on);
|
||||||
ui.painter().add(PaintCmd::Circle {
|
ui.painter().add(PaintCmd::Circle {
|
||||||
center: pos2(circle_x, rect.center().y),
|
center: pos2(circle_x, rect.center().y),
|
||||||
radius: 0.75 * radius,
|
radius: 0.75 * radius,
|
||||||
outline: Some(style.line_style()),
|
fill: style.main_fill,
|
||||||
fill: Some(style.main_fill),
|
outline: style.line_style(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// All done! Return the response so the user can check what happened
|
// All done! Return the response so the user can check what happened
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub use {
|
||||||
layout::*,
|
layout::*,
|
||||||
math::*,
|
math::*,
|
||||||
memory::Memory,
|
memory::Memory,
|
||||||
paint::{color, PaintJobs, Rgba, Srgba, TextStyle, Texture},
|
paint::{color, LineStyle, PaintJobs, Rgba, Srgba, TextStyle, Texture},
|
||||||
painter::Painter,
|
painter::Painter,
|
||||||
style::Style,
|
style::Style,
|
||||||
types::*,
|
types::*,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
//! }
|
//! }
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use crate::{widgets::*, *};
|
use crate::{color::TRANSPARENT, paint::LineStyle, widgets::*, *};
|
||||||
|
|
||||||
/// What is saved between frames.
|
/// What is saved between frames.
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
|
@ -62,12 +62,12 @@ pub fn bar<R>(ui: &mut Ui, add_contents: impl FnOnce(&mut Ui) -> R) -> (R, Rect)
|
||||||
Frame::menu_bar(ui.style()).show(ui, |ui| {
|
Frame::menu_bar(ui.style()).show(ui, |ui| {
|
||||||
let mut style = ui.style().clone();
|
let mut style = ui.style().clone();
|
||||||
style.spacing.button_padding = vec2(2.0, 0.0);
|
style.spacing.button_padding = vec2(2.0, 0.0);
|
||||||
// style.visuals.interacted.active.bg_fill = None;
|
// style.visuals.interacted.active.bg_fill = TRANSPARENT;
|
||||||
style.visuals.interacted.active.bg_outline = None;
|
style.visuals.interacted.active.bg_outline = LineStyle::none();
|
||||||
// style.visuals.interacted.hovered.bg_fill = None;
|
// style.visuals.interacted.hovered.bg_fill = TRANSPARENT;
|
||||||
style.visuals.interacted.hovered.bg_outline = None;
|
style.visuals.interacted.hovered.bg_outline = LineStyle::none();
|
||||||
style.visuals.interacted.inactive.bg_fill = None;
|
style.visuals.interacted.inactive.bg_fill = TRANSPARENT;
|
||||||
style.visuals.interacted.inactive.bg_outline = None;
|
style.visuals.interacted.inactive.bg_outline = LineStyle::none();
|
||||||
ui.set_style(style);
|
ui.set_style(style);
|
||||||
|
|
||||||
// Take full width and fixed height:
|
// Take full width and fixed height:
|
||||||
|
@ -128,12 +128,12 @@ fn menu_impl<'c>(
|
||||||
resize.show(ui, |ui| {
|
resize.show(ui, |ui| {
|
||||||
let mut style = ui.style().clone();
|
let mut style = ui.style().clone();
|
||||||
style.spacing.button_padding = vec2(2.0, 0.0);
|
style.spacing.button_padding = vec2(2.0, 0.0);
|
||||||
// style.visuals.interacted.active.bg_fill = None;
|
// style.visuals.interacted.active.bg_fill = TRANSPARENT;
|
||||||
style.visuals.interacted.active.bg_outline = None;
|
style.visuals.interacted.active.bg_outline = LineStyle::none();
|
||||||
// style.visuals.interacted.hovered.bg_fill = None;
|
// style.visuals.interacted.hovered.bg_fill = TRANSPARENT;
|
||||||
style.visuals.interacted.hovered.bg_outline = None;
|
style.visuals.interacted.hovered.bg_outline = LineStyle::none();
|
||||||
style.visuals.interacted.inactive.bg_fill = None;
|
style.visuals.interacted.inactive.bg_fill = TRANSPARENT;
|
||||||
style.visuals.interacted.inactive.bg_outline = None;
|
style.visuals.interacted.inactive.bg_outline = LineStyle::none();
|
||||||
ui.set_style(style);
|
ui.set_style(style);
|
||||||
ui.set_layout(Layout::justified(Direction::Vertical));
|
ui.set_layout(Layout::justified(Direction::Vertical));
|
||||||
add_contents(ui)
|
add_contents(ui)
|
||||||
|
|
|
@ -11,8 +11,8 @@ pub enum PaintCmd {
|
||||||
Circle {
|
Circle {
|
||||||
center: Pos2,
|
center: Pos2,
|
||||||
radius: f32,
|
radius: f32,
|
||||||
fill: Option<Srgba>,
|
fill: Srgba,
|
||||||
outline: Option<LineStyle>,
|
outline: LineStyle,
|
||||||
},
|
},
|
||||||
LineSegment {
|
LineSegment {
|
||||||
points: [Pos2; 2],
|
points: [Pos2; 2],
|
||||||
|
@ -21,14 +21,14 @@ pub enum PaintCmd {
|
||||||
Path {
|
Path {
|
||||||
path: Path,
|
path: Path,
|
||||||
closed: bool,
|
closed: bool,
|
||||||
fill: Option<Srgba>,
|
fill: Srgba,
|
||||||
outline: Option<LineStyle>,
|
outline: LineStyle,
|
||||||
},
|
},
|
||||||
Rect {
|
Rect {
|
||||||
rect: Rect,
|
rect: Rect,
|
||||||
corner_radius: f32,
|
corner_radius: f32,
|
||||||
fill: Option<Srgba>,
|
fill: Srgba,
|
||||||
outline: Option<LineStyle>,
|
outline: LineStyle,
|
||||||
},
|
},
|
||||||
Text {
|
Text {
|
||||||
/// Top left corner of the first character.
|
/// Top left corner of the first character.
|
||||||
|
@ -41,7 +41,7 @@ pub enum PaintCmd {
|
||||||
Triangles(Triangles),
|
Triangles(Triangles),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug)]
|
#[derive(Clone, Copy, Debug, Default)]
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub struct LineStyle {
|
pub struct LineStyle {
|
||||||
pub width: f32,
|
pub width: f32,
|
||||||
|
@ -49,6 +49,10 @@ pub struct LineStyle {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl LineStyle {
|
impl LineStyle {
|
||||||
|
pub fn none() -> Self {
|
||||||
|
Self::new(0.0, crate::color::TRANSPARENT)
|
||||||
|
}
|
||||||
|
|
||||||
pub fn new(width: impl Into<f32>, color: impl Into<Srgba>) -> Self {
|
pub fn new(width: impl Into<f32>, color: impl Into<Srgba>) -> Self {
|
||||||
Self {
|
Self {
|
||||||
width: width.into(),
|
width: width.into(),
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
use {
|
use {
|
||||||
super::{
|
super::{
|
||||||
color::{self, srgba, Rgba, Srgba},
|
color::{self, srgba, Rgba, Srgba, TRANSPARENT},
|
||||||
fonts::Fonts,
|
fonts::Fonts,
|
||||||
LineStyle, PaintCmd,
|
LineStyle, PaintCmd,
|
||||||
},
|
},
|
||||||
|
@ -427,7 +427,7 @@ pub fn paint_path_outline(
|
||||||
options: PaintOptions,
|
options: PaintOptions,
|
||||||
out: &mut Triangles,
|
out: &mut Triangles,
|
||||||
) {
|
) {
|
||||||
if style.color == color::TRANSPARENT {
|
if style.width <= 0.0 || style.color == color::TRANSPARENT {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,12 +604,8 @@ pub fn tessellate_paint_command(
|
||||||
} => {
|
} => {
|
||||||
if radius > 0.0 {
|
if radius > 0.0 {
|
||||||
path.add_circle(center, radius);
|
path.add_circle(center, radius);
|
||||||
if let Some(fill) = fill {
|
fill_closed_path(&path.0, fill, options, out);
|
||||||
fill_closed_path(&path.0, fill, options, out);
|
paint_path_outline(&path.0, Closed, outline, options, out);
|
||||||
}
|
|
||||||
if let Some(line_style) = outline {
|
|
||||||
paint_path_outline(&path.0, Closed, line_style, options, out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PaintCmd::Triangles(triangles) => {
|
PaintCmd::Triangles(triangles) => {
|
||||||
|
@ -626,17 +622,15 @@ pub fn tessellate_paint_command(
|
||||||
outline,
|
outline,
|
||||||
} => {
|
} => {
|
||||||
if path.len() >= 2 {
|
if path.len() >= 2 {
|
||||||
if let Some(fill) = fill {
|
if fill != TRANSPARENT {
|
||||||
debug_assert!(
|
debug_assert!(
|
||||||
closed,
|
closed,
|
||||||
"You asked to fill a path that is not closed. That makes no sense."
|
"You asked to fill a path that is not closed. That makes no sense."
|
||||||
);
|
);
|
||||||
fill_closed_path(&path.0, fill, options, out);
|
fill_closed_path(&path.0, fill, options, out);
|
||||||
}
|
}
|
||||||
if let Some(line_style) = outline {
|
let typ = if closed { Closed } else { Open };
|
||||||
let typ = if closed { Closed } else { Open };
|
paint_path_outline(&path.0, typ, outline, options, out);
|
||||||
paint_path_outline(&path.0, typ, line_style, options, out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PaintCmd::Rect {
|
PaintCmd::Rect {
|
||||||
|
@ -652,12 +646,8 @@ pub fn tessellate_paint_command(
|
||||||
rect.max = rect.max.min(pos2(1e7, 1e7));
|
rect.max = rect.max.min(pos2(1e7, 1e7));
|
||||||
|
|
||||||
path.add_rounded_rectangle(rect, corner_radius);
|
path.add_rounded_rectangle(rect, corner_radius);
|
||||||
if let Some(fill) = fill {
|
fill_closed_path(&path.0, fill, options, out);
|
||||||
fill_closed_path(&path.0, fill, options, out);
|
paint_path_outline(&path.0, Closed, outline, options, out);
|
||||||
}
|
|
||||||
if let Some(line_style) = outline {
|
|
||||||
paint_path_outline(&path.0, Closed, line_style, options, out);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PaintCmd::Text {
|
PaintCmd::Text {
|
||||||
|
@ -666,6 +656,9 @@ pub fn tessellate_paint_command(
|
||||||
text_style,
|
text_style,
|
||||||
color,
|
color,
|
||||||
} => {
|
} => {
|
||||||
|
if color == TRANSPARENT {
|
||||||
|
return;
|
||||||
|
}
|
||||||
galley.sanity_check();
|
galley.sanity_check();
|
||||||
|
|
||||||
let num_chars = galley.text.chars().count();
|
let num_chars = galley.text.chars().count();
|
||||||
|
@ -737,8 +730,8 @@ pub fn tessellate_paint_commands(
|
||||||
PaintCmd::Rect {
|
PaintCmd::Rect {
|
||||||
rect: *clip_rect,
|
rect: *clip_rect,
|
||||||
corner_radius: 0.0,
|
corner_radius: 0.0,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: Some(LineStyle::new(2.0, srgba(150, 255, 150, 255))),
|
outline: LineStyle::new(2.0, srgba(150, 255, 150, 255)),
|
||||||
},
|
},
|
||||||
options,
|
options,
|
||||||
fonts,
|
fonts,
|
||||||
|
|
|
@ -131,8 +131,8 @@ impl Painter {
|
||||||
self.add(PaintCmd::Rect {
|
self.add(PaintCmd::Rect {
|
||||||
rect: rect.expand(2.0),
|
rect: rect.expand(2.0),
|
||||||
corner_radius: 0.0,
|
corner_radius: 0.0,
|
||||||
fill: Some(Srgba::black_alpha(240)),
|
fill: Srgba::black_alpha(240),
|
||||||
outline: Some(LineStyle::new(1.0, color::RED)),
|
outline: LineStyle::new(1.0, color::RED),
|
||||||
});
|
});
|
||||||
self.galley(rect.min, galley, text_style, color::RED);
|
self.galley(rect.min, galley, text_style, color::RED);
|
||||||
}
|
}
|
||||||
|
@ -151,8 +151,8 @@ impl Painter {
|
||||||
self.add(PaintCmd::Circle {
|
self.add(PaintCmd::Circle {
|
||||||
center,
|
center,
|
||||||
radius,
|
radius,
|
||||||
fill: Some(fill_color.into()),
|
fill: fill_color.into(),
|
||||||
outline: None,
|
outline: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,8 +160,8 @@ impl Painter {
|
||||||
self.add(PaintCmd::Circle {
|
self.add(PaintCmd::Circle {
|
||||||
center,
|
center,
|
||||||
radius,
|
radius,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: Some(outline.into()),
|
outline: outline.into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -169,8 +169,8 @@ impl Painter {
|
||||||
self.add(PaintCmd::Rect {
|
self.add(PaintCmd::Rect {
|
||||||
rect,
|
rect,
|
||||||
corner_radius,
|
corner_radius,
|
||||||
fill: Some(fill_color.into()),
|
fill: fill_color.into(),
|
||||||
outline: None,
|
outline: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -178,8 +178,8 @@ impl Painter {
|
||||||
self.add(PaintCmd::Rect {
|
self.add(PaintCmd::Rect {
|
||||||
rect,
|
rect,
|
||||||
corner_radius,
|
corner_radius,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
outline: Some(outline.into()),
|
outline: outline.into(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -139,11 +139,11 @@ impl Interacted {
|
||||||
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
#[cfg_attr(feature = "serde", derive(serde::Deserialize, serde::Serialize))]
|
||||||
pub struct WidgetVisuals {
|
pub struct WidgetVisuals {
|
||||||
/// Background color of widget
|
/// Background color of widget
|
||||||
pub bg_fill: Option<Srgba>,
|
pub bg_fill: Srgba,
|
||||||
|
|
||||||
/// 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 bg_outline: Option<LineStyle>,
|
pub bg_outline: LineStyle,
|
||||||
|
|
||||||
/// Button frames etc
|
/// Button frames etc
|
||||||
pub corner_radius: f32,
|
pub corner_radius: f32,
|
||||||
|
@ -226,32 +226,32 @@ impl Default for Interacted {
|
||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
active: WidgetVisuals {
|
active: WidgetVisuals {
|
||||||
bg_fill: Some(Srgba::black_alpha(128)),
|
bg_fill: Srgba::black_alpha(128),
|
||||||
bg_outline: Some(LineStyle::new(2.0, WHITE)),
|
bg_outline: LineStyle::new(2.0, WHITE),
|
||||||
corner_radius: 0.0,
|
corner_radius: 0.0,
|
||||||
main_fill: srgba(120, 120, 200, 255),
|
main_fill: srgba(120, 120, 200, 255),
|
||||||
stroke_color: WHITE,
|
stroke_color: WHITE,
|
||||||
stroke_width: 2.0,
|
stroke_width: 2.0,
|
||||||
},
|
},
|
||||||
hovered: WidgetVisuals {
|
hovered: WidgetVisuals {
|
||||||
bg_fill: None,
|
bg_fill: TRANSPARENT,
|
||||||
bg_outline: Some(LineStyle::new(1.0, WHITE)),
|
bg_outline: LineStyle::new(1.0, WHITE),
|
||||||
corner_radius: 2.0,
|
corner_radius: 2.0,
|
||||||
main_fill: srgba(100, 100, 150, 255),
|
main_fill: srgba(100, 100, 150, 255),
|
||||||
stroke_color: Srgba::gray(240),
|
stroke_color: Srgba::gray(240),
|
||||||
stroke_width: 1.5,
|
stroke_width: 1.5,
|
||||||
},
|
},
|
||||||
inactive: WidgetVisuals {
|
inactive: WidgetVisuals {
|
||||||
bg_fill: None,
|
bg_fill: TRANSPARENT,
|
||||||
bg_outline: Some(LineStyle::new(1.0, Srgba::gray(128))),
|
bg_outline: LineStyle::new(1.0, Srgba::gray(128)),
|
||||||
corner_radius: 4.0,
|
corner_radius: 4.0,
|
||||||
main_fill: srgba(60, 60, 80, 255),
|
main_fill: srgba(60, 60, 80, 255),
|
||||||
stroke_color: Srgba::gray(200), // Mustn't look grayed out!
|
stroke_color: Srgba::gray(200), // Mustn't look grayed out!
|
||||||
stroke_width: 1.0,
|
stroke_width: 1.0,
|
||||||
},
|
},
|
||||||
disabled: WidgetVisuals {
|
disabled: WidgetVisuals {
|
||||||
bg_fill: None,
|
bg_fill: TRANSPARENT,
|
||||||
bg_outline: Some(LineStyle::new(0.5, Srgba::gray(128))),
|
bg_outline: LineStyle::new(0.5, Srgba::gray(128)),
|
||||||
corner_radius: 4.0,
|
corner_radius: 4.0,
|
||||||
main_fill: srgba(50, 50, 50, 255),
|
main_fill: srgba(50, 50, 50, 255),
|
||||||
stroke_color: Srgba::gray(128), // Should look grayed out
|
stroke_color: Srgba::gray(128), // Should look grayed out
|
||||||
|
@ -361,8 +361,8 @@ impl WidgetVisuals {
|
||||||
stroke_width,
|
stroke_width,
|
||||||
} = self;
|
} = self;
|
||||||
|
|
||||||
let _ = bg_fill; // ui_color(ui, bg_fill, "bg_fill"); // TODO
|
ui_color(ui, bg_fill, "bg_fill");
|
||||||
let _ = bg_outline; // bg_outline.ui(ui, "bg_outline");// TODO
|
bg_outline.ui(ui, "bg_outline");
|
||||||
ui.add(Slider::f32(corner_radius, 0.0..=10.0).text("corner_radius"));
|
ui.add(Slider::f32(corner_radius, 0.0..=10.0).text("corner_radius"));
|
||||||
ui_color(ui, main_fill, "main_fill");
|
ui_color(ui, main_fill, "main_fill");
|
||||||
ui_color(ui, stroke_color, "stroke_color");
|
ui_color(ui, stroke_color, "stroke_color");
|
||||||
|
@ -417,7 +417,7 @@ impl LineStyle {
|
||||||
let Self { width, color } = self;
|
let Self { width, color } = self;
|
||||||
ui.horizontal_centered(|ui| {
|
ui.horizontal_centered(|ui| {
|
||||||
ui.label(format!("{}: ", text));
|
ui.label(format!("{}: ", text));
|
||||||
ui.add(Slider::f32(width, 0.0..=10.0));
|
ui.add(Slider::f32(width, 0.0..=10.0).text("width"));
|
||||||
ui_color(ui, color, "color");
|
ui_color(ui, color, "color");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -233,7 +233,7 @@ impl Button {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
text_color: None,
|
text_color: None,
|
||||||
text_style: TextStyle::Button,
|
text_style: TextStyle::Button,
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
sense: Sense::click(),
|
sense: Sense::click(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -289,11 +289,11 @@ impl Widget for Button {
|
||||||
let rect = ui.allocate_space(size);
|
let rect = ui.allocate_space(size);
|
||||||
let response = ui.interact(rect, id, sense);
|
let response = ui.interact(rect, id, sense);
|
||||||
let text_cursor = response.rect.left_center() + vec2(padding.x, -0.5 * galley.size.y);
|
let text_cursor = response.rect.left_center() + vec2(padding.x, -0.5 * galley.size.y);
|
||||||
let bg_fill = fill.or(ui.style().interact(&response).bg_fill);
|
let fill = fill.unwrap_or(ui.style().interact(&response).bg_fill);
|
||||||
ui.painter().add(PaintCmd::Rect {
|
ui.painter().add(PaintCmd::Rect {
|
||||||
rect: response.rect,
|
rect: response.rect,
|
||||||
corner_radius: ui.style().interact(&response).corner_radius,
|
corner_radius: ui.style().interact(&response).corner_radius,
|
||||||
fill: bg_fill,
|
fill,
|
||||||
outline: ui.style().interact(&response).bg_outline,
|
outline: ui.style().interact(&response).bg_outline,
|
||||||
});
|
});
|
||||||
let stroke_color = ui.style().interact(&response).stroke_color;
|
let stroke_color = ui.style().interact(&response).stroke_color;
|
||||||
|
@ -372,8 +372,8 @@ impl<'a> Widget for Checkbox<'a> {
|
||||||
pos2(small_icon_rect.right(), small_icon_rect.top()),
|
pos2(small_icon_rect.right(), small_icon_rect.top()),
|
||||||
]),
|
]),
|
||||||
closed: false,
|
closed: false,
|
||||||
outline: Some(LineStyle::new(ui.style().visuals.line_width, stroke_color)),
|
outline: LineStyle::new(ui.style().visuals.line_width, stroke_color),
|
||||||
fill: None,
|
fill: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,8 +448,8 @@ impl Widget for RadioButton {
|
||||||
painter.add(PaintCmd::Circle {
|
painter.add(PaintCmd::Circle {
|
||||||
center: small_icon_rect.center(),
|
center: small_icon_rect.center(),
|
||||||
radius: small_icon_rect.width() / 3.0,
|
radius: small_icon_rect.width() / 3.0,
|
||||||
fill: Some(stroke_color),
|
fill: stroke_color,
|
||||||
outline: None,
|
outline: Default::default(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -515,10 +515,6 @@ impl Widget for Separator {
|
||||||
|
|
||||||
let available_space = ui.available_finite().size();
|
let available_space = ui.available_finite().size();
|
||||||
|
|
||||||
// TODO: only allocate `spacing`, but not our full width/height
|
|
||||||
// as that would make the false impression that we *need* all that space,
|
|
||||||
// which would prevent regions from auto-shrinking
|
|
||||||
|
|
||||||
let (points, rect) = match ui.layout().dir() {
|
let (points, rect) = match ui.layout().dir() {
|
||||||
Direction::Horizontal => {
|
Direction::Horizontal => {
|
||||||
let rect = ui.allocate_space(vec2(spacing, available_space.y));
|
let rect = ui.allocate_space(vec2(spacing, available_space.y));
|
||||||
|
|
|
@ -164,18 +164,18 @@ impl<'a> Slider<'a> {
|
||||||
ui.painter().add(PaintCmd::Rect {
|
ui.painter().add(PaintCmd::Rect {
|
||||||
rect: rail_rect,
|
rect: rail_rect,
|
||||||
corner_radius: rail_radius,
|
corner_radius: rail_radius,
|
||||||
fill: Some(ui.style().visuals.background_fill),
|
fill: ui.style().visuals.background_fill,
|
||||||
outline: Some(LineStyle::new(1.0, Srgba::gray(200))), // TODO
|
outline: LineStyle::new(1.0, Srgba::gray(200)), // TODO
|
||||||
});
|
});
|
||||||
|
|
||||||
ui.painter().add(PaintCmd::Circle {
|
ui.painter().add(PaintCmd::Circle {
|
||||||
center: pos2(marker_center_x, rail_rect.center().y),
|
center: pos2(marker_center_x, rail_rect.center().y),
|
||||||
radius: handle_radius(rect),
|
radius: handle_radius(rect),
|
||||||
fill: Some(ui.style().interact(response).main_fill),
|
fill: ui.style().interact(response).main_fill,
|
||||||
outline: Some(LineStyle::new(
|
outline: LineStyle::new(
|
||||||
ui.style().interact(response).stroke_width,
|
ui.style().interact(response).stroke_width,
|
||||||
ui.style().interact(response).stroke_color,
|
ui.style().interact(response).stroke_color,
|
||||||
)),
|
),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -183,7 +183,7 @@ impl<'t> Widget for TextEdit<'t> {
|
||||||
painter.add(PaintCmd::Rect {
|
painter.add(PaintCmd::Rect {
|
||||||
rect: bg_rect,
|
rect: bg_rect,
|
||||||
corner_radius: ui.style().interact(&response).corner_radius,
|
corner_radius: ui.style().interact(&response).corner_radius,
|
||||||
fill: Some(ui.style().visuals.dark_bg_color),
|
fill: ui.style().visuals.dark_bg_color,
|
||||||
outline: ui.style().interact(&response).bg_outline,
|
outline: ui.style().interact(&response).bg_outline,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue