[refactor] rename LineStyle to Stroke
This commit is contained in:
parent
e7b098ac56
commit
9d4021d703
19 changed files with 126 additions and 126 deletions
|
@ -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(),
|
||||
},
|
||||
);
|
||||
|
||||
|
|
|
@ -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,
|
||||
},
|
||||
);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
@ -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(),
|
||||
});
|
||||
}
|
||||
|
|
|
@ -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));
|
||||
});
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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::*,
|
||||
|
|
|
@ -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<R>(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)
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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<Pos2>,
|
||||
|
@ -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<Color> From<(f32, Color)> for LineStyle
|
||||
impl<Color> From<(f32, Color)> for Stroke
|
||||
where
|
||||
Color: Into<Srgba>,
|
||||
{
|
||||
fn from((width, color): (f32, Color)) -> LineStyle {
|
||||
LineStyle::new(width, color)
|
||||
fn from((width, color): (f32, Color)) -> Stroke {
|
||||
Stroke::new(width, color)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<PathPoint>);
|
||||
|
@ -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,
|
||||
|
|
|
@ -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<String>) {
|
||||
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<LineStyle>) {
|
||||
pub fn line_segment(&self, points: [Pos2; 2], stroke: impl Into<Stroke>) {
|
||||
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<LineStyle>) {
|
||||
pub fn circle_stroke(&self, center: Pos2, radius: f32, stroke: impl Into<Stroke>) {
|
||||
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<LineStyle>) {
|
||||
pub fn rect_stroke(&self, rect: Rect, corner_radius: f32, stroke: impl Into<Stroke>) {
|
||||
self.add(PaintCmd::Rect {
|
||||
rect,
|
||||
corner_radius,
|
||||
fill: Default::default(),
|
||||
outline: outline.into(),
|
||||
stroke: stroke.into(),
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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| {
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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(),
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -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,
|
||||
),
|
||||
|
|
|
@ -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,
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue