Merge pull request #628 from hecrj/improvement/float-border-radius

Use `f32` for `border_width` and `border_radius`
This commit is contained in:
Héctor Ramón 2020-11-24 00:17:30 +01:00 committed by GitHub
commit 5615643c52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
35 changed files with 144 additions and 134 deletions

View File

@ -16,11 +16,11 @@ mod circle {
}; };
pub struct Circle { pub struct Circle {
radius: u16, radius: f32,
} }
impl Circle { impl Circle {
pub fn new(radius: u16) -> Self { pub fn new(radius: f32) -> Self {
Self { radius } Self { radius }
} }
} }
@ -42,16 +42,13 @@ mod circle {
_renderer: &Renderer<B>, _renderer: &Renderer<B>,
_limits: &layout::Limits, _limits: &layout::Limits,
) -> layout::Node { ) -> layout::Node {
layout::Node::new(Size::new( layout::Node::new(Size::new(self.radius * 2.0, self.radius * 2.0))
f32::from(self.radius) * 2.0,
f32::from(self.radius) * 2.0,
))
} }
fn hash_layout(&self, state: &mut Hasher) { fn hash_layout(&self, state: &mut Hasher) {
use std::hash::Hash; use std::hash::Hash;
self.radius.hash(state); self.radius.to_bits().hash(state);
} }
fn draw( fn draw(
@ -67,7 +64,7 @@ mod circle {
bounds: layout.bounds(), bounds: layout.bounds(),
background: Background::Color(Color::BLACK), background: Background::Color(Color::BLACK),
border_radius: self.radius, border_radius: self.radius,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
mouse::Interaction::default(), mouse::Interaction::default(),
@ -96,7 +93,7 @@ pub fn main() -> iced::Result {
} }
struct Example { struct Example {
radius: u16, radius: f32,
slider: slider::State, slider: slider::State,
} }
@ -110,7 +107,7 @@ impl Sandbox for Example {
fn new() -> Self { fn new() -> Self {
Example { Example {
radius: 50, radius: 50.0,
slider: slider::State::new(), slider: slider::State::new(),
} }
} }
@ -122,7 +119,7 @@ impl Sandbox for Example {
fn update(&mut self, message: Message) { fn update(&mut self, message: Message) {
match message { match message {
Message::RadiusChanged(radius) => { Message::RadiusChanged(radius) => {
self.radius = radius.round() as u16; self.radius = radius;
} }
} }
} }
@ -134,13 +131,16 @@ impl Sandbox for Example {
.max_width(500) .max_width(500)
.align_items(Align::Center) .align_items(Align::Center)
.push(Circle::new(self.radius)) .push(Circle::new(self.radius))
.push(Text::new(format!("Radius: {}", self.radius.to_string()))) .push(Text::new(format!("Radius: {:.2}", self.radius)))
.push(Slider::new( .push(
&mut self.slider, Slider::new(
1.0..=100.0, &mut self.slider,
f32::from(self.radius), 1.0..=100.0,
Message::RadiusChanged, self.radius,
)); Message::RadiusChanged,
)
.step(0.01),
);
Container::new(content) Container::new(content)
.width(Length::Fill) .width(Length::Fill)

View File

@ -44,7 +44,7 @@ impl button::StyleSheet for Button {
fn active(&self) -> button::Style { fn active(&self) -> button::Style {
button::Style { button::Style {
background: Some(Background::Color(ACTIVE)), background: Some(Background::Color(ACTIVE)),
border_radius: 3, border_radius: 3.0,
text_color: Color::WHITE, text_color: Color::WHITE,
..button::Style::default() ..button::Style::default()
} }
@ -60,7 +60,7 @@ impl button::StyleSheet for Button {
fn pressed(&self) -> button::Style { fn pressed(&self) -> button::Style {
button::Style { button::Style {
border_width: 1, border_width: 1.0,
border_color: Color::WHITE, border_color: Color::WHITE,
..self.hovered() ..self.hovered()
} }
@ -73,7 +73,7 @@ impl button::StyleSheet for Clear {
fn active(&self) -> button::Style { fn active(&self) -> button::Style {
button::Style { button::Style {
background: Some(Background::Color(DESTRUCTIVE)), background: Some(Background::Color(DESTRUCTIVE)),
border_radius: 3, border_radius: 3.0,
text_color: Color::WHITE, text_color: Color::WHITE,
..button::Style::default() ..button::Style::default()
} }
@ -92,7 +92,7 @@ impl button::StyleSheet for Clear {
fn pressed(&self) -> button::Style { fn pressed(&self) -> button::Style {
button::Style { button::Style {
border_width: 1, border_width: 1.0,
border_color: Color::WHITE, border_color: Color::WHITE,
..self.hovered() ..self.hovered()
} }
@ -106,9 +106,9 @@ impl slider::StyleSheet for Slider {
slider::Style { slider::Style {
rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }), rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }),
handle: slider::Handle { handle: slider::Handle {
shape: slider::HandleShape::Circle { radius: 9 }, shape: slider::HandleShape::Circle { radius: 9.0 },
color: ACTIVE, color: ACTIVE,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
} }
@ -146,7 +146,7 @@ impl pick_list::StyleSheet for PickList {
pick_list::Menu { pick_list::Menu {
text_color: Color::WHITE, text_color: Color::WHITE,
background: BACKGROUND.into(), background: BACKGROUND.into(),
border_width: 1, border_width: 1.0,
border_color: Color { border_color: Color {
a: 0.7, a: 0.7,
..Color::BLACK ..Color::BLACK
@ -164,12 +164,12 @@ impl pick_list::StyleSheet for PickList {
pick_list::Style { pick_list::Style {
text_color: Color::WHITE, text_color: Color::WHITE,
background: BACKGROUND.into(), background: BACKGROUND.into(),
border_width: 1, border_width: 1.0,
border_color: Color { border_color: Color {
a: 0.6, a: 0.6,
..Color::BLACK ..Color::BLACK
}, },
border_radius: 2, border_radius: 2.0,
icon_size: 0.5, icon_size: 0.5,
} }
} }

View File

@ -318,7 +318,7 @@ mod style {
fn style(&self) -> container::Style { fn style(&self) -> container::Style {
container::Style { container::Style {
background: Some(Background::Color(SURFACE)), background: Some(Background::Color(SURFACE)),
border_width: 2, border_width: 2.0,
border_color: if self.is_focused { border_color: if self.is_focused {
Color::BLACK Color::BLACK
} else { } else {
@ -346,7 +346,7 @@ mod style {
button::Style { button::Style {
text_color, text_color,
background: background.map(Background::Color), background: background.map(Background::Color),
border_radius: 5, border_radius: 5.0,
shadow_offset: Vector::new(0.0, 0.0), shadow_offset: Vector::new(0.0, 0.0),
..button::Style::default() ..button::Style::default()
} }

View File

@ -251,7 +251,7 @@ mod style {
background: Some(Background::Color(match self { background: Some(Background::Color(match self {
Button::Primary => Color::from_rgb(0.11, 0.42, 0.87), Button::Primary => Color::from_rgb(0.11, 0.42, 0.87),
})), })),
border_radius: 12, border_radius: 12.0,
shadow_offset: Vector::new(1.0, 1.0), shadow_offset: Vector::new(1.0, 1.0),
text_color: Color::WHITE, text_color: Color::WHITE,
..button::Style::default() ..button::Style::default()

View File

@ -114,7 +114,7 @@ mod dark {
radio::Style { radio::Style {
background: SURFACE.into(), background: SURFACE.into(),
dot_color: ACTIVE, dot_color: ACTIVE,
border_width: 1, border_width: 1.0,
border_color: ACTIVE, border_color: ACTIVE,
} }
} }
@ -137,13 +137,13 @@ mod dark {
..SCROLLBAR ..SCROLLBAR
} }
.into(), .into(),
border_radius: 2, border_radius: 2.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
scroller: scrollable::Scroller { scroller: scrollable::Scroller {
color: Color { a: 0.7, ..SCROLLER }, color: Color { a: 0.7, ..SCROLLER },
border_radius: 2, border_radius: 2.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
} }
@ -182,7 +182,7 @@ mod dark {
rule::Style { rule::Style {
color: SURFACE, color: SURFACE,
width: 2, width: 2,
radius: 1, radius: 1.0,
fill_mode: rule::FillMode::Percent(30.0), fill_mode: rule::FillMode::Percent(30.0),
} }
} }

View File

@ -161,7 +161,7 @@ mod style {
Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5), Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5),
Button::Destructive => Color::from_rgb(0.8, 0.2, 0.2), Button::Destructive => Color::from_rgb(0.8, 0.2, 0.2),
})), })),
border_radius: 12, border_radius: 12.0,
shadow_offset: Vector::new(1.0, 1.0), shadow_offset: Vector::new(1.0, 1.0),
text_color: Color::WHITE, text_color: Color::WHITE,
..button::Style::default() ..button::Style::default()

View File

@ -249,7 +249,7 @@ mod style {
fn active(&self) -> button::Style { fn active(&self) -> button::Style {
button::Style { button::Style {
background: Color::from_rgb(0.11, 0.42, 0.87).into(), background: Color::from_rgb(0.11, 0.42, 0.87).into(),
border_radius: 12, border_radius: 12.0,
shadow_offset: Vector::new(1.0, 1.0), shadow_offset: Vector::new(1.0, 1.0),
text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE), text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE),
..button::Style::default() ..button::Style::default()
@ -315,7 +315,7 @@ mod style {
radio::Style { radio::Style {
background: SURFACE.into(), background: SURFACE.into(),
dot_color: ACTIVE, dot_color: ACTIVE,
border_width: 1, border_width: 1.0,
border_color: ACTIVE, border_color: ACTIVE,
} }
} }
@ -334,15 +334,15 @@ mod style {
fn active(&self) -> text_input::Style { fn active(&self) -> text_input::Style {
text_input::Style { text_input::Style {
background: SURFACE.into(), background: SURFACE.into(),
border_radius: 2, border_radius: 2.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
} }
} }
fn focused(&self) -> text_input::Style { fn focused(&self) -> text_input::Style {
text_input::Style { text_input::Style {
border_width: 1, border_width: 1.0,
border_color: ACCENT, border_color: ACCENT,
..self.active() ..self.active()
} }
@ -350,7 +350,7 @@ mod style {
fn hovered(&self) -> text_input::Style { fn hovered(&self) -> text_input::Style {
text_input::Style { text_input::Style {
border_width: 1, border_width: 1.0,
border_color: Color { a: 0.3, ..ACCENT }, border_color: Color { a: 0.3, ..ACCENT },
..self.focused() ..self.focused()
} }
@ -375,7 +375,7 @@ mod style {
fn active(&self) -> button::Style { fn active(&self) -> button::Style {
button::Style { button::Style {
background: ACTIVE.into(), background: ACTIVE.into(),
border_radius: 3, border_radius: 3.0,
text_color: Color::WHITE, text_color: Color::WHITE,
..button::Style::default() ..button::Style::default()
} }
@ -391,7 +391,7 @@ mod style {
fn pressed(&self) -> button::Style { fn pressed(&self) -> button::Style {
button::Style { button::Style {
border_width: 1, border_width: 1.0,
border_color: Color::WHITE, border_color: Color::WHITE,
..self.hovered() ..self.hovered()
} }
@ -404,13 +404,13 @@ mod style {
fn active(&self) -> scrollable::Scrollbar { fn active(&self) -> scrollable::Scrollbar {
scrollable::Scrollbar { scrollable::Scrollbar {
background: SURFACE.into(), background: SURFACE.into(),
border_radius: 2, border_radius: 2.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
scroller: scrollable::Scroller { scroller: scrollable::Scroller {
color: ACTIVE, color: ACTIVE,
border_radius: 2, border_radius: 2.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
} }
@ -449,9 +449,9 @@ mod style {
slider::Style { slider::Style {
rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }), rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }),
handle: slider::Handle { handle: slider::Handle {
shape: slider::HandleShape::Circle { radius: 9 }, shape: slider::HandleShape::Circle { radius: 9.0 },
color: ACTIVE, color: ACTIVE,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
} }
@ -489,7 +489,7 @@ mod style {
progress_bar::Style { progress_bar::Style {
background: SURFACE.into(), background: SURFACE.into(),
bar: ACTIVE.into(), bar: ACTIVE.into(),
border_radius: 10, border_radius: 10.0,
} }
} }
} }
@ -502,8 +502,8 @@ mod style {
background: if is_checked { ACTIVE } else { SURFACE } background: if is_checked { ACTIVE } else { SURFACE }
.into(), .into(),
checkmark_color: Color::WHITE, checkmark_color: Color::WHITE,
border_radius: 2, border_radius: 2.0,
border_width: 1, border_width: 1.0,
border_color: ACTIVE, border_color: ACTIVE,
} }
} }
@ -527,7 +527,7 @@ mod style {
rule::Style { rule::Style {
color: SURFACE, color: SURFACE,
width: 2, width: 2,
radius: 1, radius: 1.0,
fill_mode: rule::FillMode::Padded(15), fill_mode: rule::FillMode::Padded(15),
} }
} }

View File

@ -611,7 +611,7 @@ mod style {
background: Some(Background::Color( background: Some(Background::Color(
Color::from_rgb(0.2, 0.2, 0.7), Color::from_rgb(0.2, 0.2, 0.7),
)), )),
border_radius: 10, border_radius: 10.0,
text_color: Color::WHITE, text_color: Color::WHITE,
..button::Style::default() ..button::Style::default()
} }
@ -627,7 +627,7 @@ mod style {
background: Some(Background::Color(Color::from_rgb( background: Some(Background::Color(Color::from_rgb(
0.8, 0.2, 0.2, 0.8, 0.2, 0.2,
))), ))),
border_radius: 5, border_radius: 5.0,
text_color: Color::WHITE, text_color: Color::WHITE,
shadow_offset: Vector::new(1.0, 1.0), shadow_offset: Vector::new(1.0, 1.0),
..button::Style::default() ..button::Style::default()

View File

@ -769,7 +769,7 @@ mod style {
Button::Primary => Color::from_rgb(0.11, 0.42, 0.87), Button::Primary => Color::from_rgb(0.11, 0.42, 0.87),
Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5), Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5),
})), })),
border_radius: 12, border_radius: 12.0,
shadow_offset: Vector::new(1.0, 1.0), shadow_offset: Vector::new(1.0, 1.0),
text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE), text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE),
..button::Style::default() ..button::Style::default()

View File

@ -29,6 +29,11 @@ void main() {
vec2 p_Pos = i_Pos * u_Scale; vec2 p_Pos = i_Pos * u_Scale;
vec2 p_Scale = i_Scale * u_Scale; vec2 p_Scale = i_Scale * u_Scale;
float i_BorderRadius = min(
i_BorderRadius,
min(i_Scale.x, i_Scale.y) / 2.0
);
mat4 i_Transform = mat4( mat4 i_Transform = mat4(
vec4(p_Scale.x + 1.0, 0.0, 0.0, 0.0), vec4(p_Scale.x + 1.0, 0.0, 0.0, 0.0),
vec4(0.0, p_Scale.y + 1.0, 0.0, 0.0), vec4(0.0, p_Scale.y + 1.0, 0.0, 0.0),

View File

@ -156,8 +156,8 @@ impl<'a> Layer<'a> {
color: match background { color: match background {
Background::Color(color) => color.into_linear(), Background::Color(color) => color.into_linear(),
}, },
border_radius: *border_radius as f32, border_radius: *border_radius,
border_width: *border_width as f32, border_width: *border_width,
border_color: border_color.into_linear(), border_color: border_color.into_linear(),
}); });
} }

View File

@ -29,7 +29,7 @@ where
background: style.background, background: style.background,
border_color: style.border_color, border_color: style.border_color,
border_width: style.border_width, border_width: style.border_width,
border_radius: 0, border_radius: 0.0,
}, },
primitives, primitives,
], ],
@ -80,8 +80,8 @@ where
bounds, bounds,
background: style.selected_background, background: style.selected_background,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
border_width: 0, border_width: 0.0,
border_radius: 0, border_radius: 0.0,
}); });
} }

View File

@ -40,9 +40,9 @@ pub enum Primitive {
/// The background of the quad /// The background of the quad
background: Background, background: Background,
/// The border radius of the quad /// The border radius of the quad
border_radius: u16, border_radius: f32,
/// The border width of the quad /// The border width of the quad
border_width: u16, border_width: f32,
/// The border color of the quad /// The border color of the quad
border_color: Color, border_color: Color,
}, },

View File

@ -119,8 +119,8 @@ fn explain_layout(
primitives.push(Primitive::Quad { primitives.push(Primitive::Quad {
bounds: layout.bounds(), bounds: layout.bounds(),
background: Background::Color(Color::TRANSPARENT), background: Background::Color(Color::TRANSPARENT),
border_radius: 0, border_radius: 0.0,
border_width: 1, border_width: 1.0,
border_color: [0.6, 0.6, 0.6, 0.5].into(), border_color: [0.6, 0.6, 0.6, 0.5].into(),
}); });

View File

@ -66,7 +66,7 @@ where
); );
( (
if styling.background.is_some() || styling.border_width > 0 { if styling.background.is_some() || styling.border_width > 0.0 {
let background = Primitive::Quad { let background = Primitive::Quad {
bounds, bounds,
background: styling background: styling
@ -93,7 +93,7 @@ where
[0.0, 0.0, 0.0, 0.5].into(), [0.0, 0.0, 0.0, 0.5].into(),
), ),
border_radius: styling.border_radius, border_radius: styling.border_radius,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}; };

View File

@ -62,7 +62,7 @@ pub(crate) fn background(
bounds: Rectangle, bounds: Rectangle,
style: &container::Style, style: &container::Style,
) -> Option<Primitive> { ) -> Option<Primitive> {
if style.background.is_some() || style.border_width > 0 { if style.background.is_some() || style.border_width > 0.0 {
Some(Primitive::Quad { Some(Primitive::Quad {
bounds, bounds,
background: style background: style

View File

@ -43,7 +43,7 @@ where
bounds: Rectangle { ..bounds }, bounds: Rectangle { ..bounds },
background: style.background, background: style.background,
border_radius: style.border_radius, border_radius: style.border_radius,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}], }],
}; };
@ -57,7 +57,7 @@ where
}, },
background: style.bar, background: style.bar,
border_radius: style.border_radius, border_radius: style.border_radius,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}; };

View File

@ -42,7 +42,7 @@ where
let radio = Primitive::Quad { let radio = Primitive::Quad {
bounds, bounds,
background: style.background, background: style.background,
border_radius: (size / 2.0) as u16, border_radius: size / 2.0,
border_width: style.border_width, border_width: style.border_width,
border_color: style.border_color, border_color: style.border_color,
}; };
@ -58,8 +58,8 @@ where
height: bounds.height - dot_size, height: bounds.height - dot_size,
}, },
background: Background::Color(style.dot_color), background: Background::Color(style.dot_color),
border_radius: (dot_size / 2.0) as u16, border_radius: dot_size / 2.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}; };

View File

@ -43,7 +43,7 @@ where
}, },
background: Background::Color(style.color), background: Background::Color(style.color),
border_radius: style.radius, border_radius: style.radius,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
} }
} else { } else {
@ -63,7 +63,7 @@ where
}, },
background: Background::Color(style.color), background: Background::Color(style.color),
border_radius: style.radius, border_radius: style.radius,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
} }
}; };

View File

@ -103,7 +103,7 @@ where
}; };
let is_scrollbar_visible = let is_scrollbar_visible =
style.background.is_some() || style.border_width > 0; style.background.is_some() || style.border_width > 0.0;
let scroller = if is_mouse_over let scroller = if is_mouse_over
|| state.is_scroller_grabbed() || state.is_scroller_grabbed()

View File

@ -57,8 +57,8 @@ where
height: 2.0, height: 2.0,
}, },
background: Background::Color(style.rail_colors.0), background: Background::Color(style.rail_colors.0),
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
Primitive::Quad { Primitive::Quad {
@ -69,8 +69,8 @@ where
height: 2.0, height: 2.0,
}, },
background: Background::Color(style.rail_colors.1), background: Background::Color(style.rail_colors.1),
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
); );
@ -82,7 +82,7 @@ where
.shape .shape
{ {
HandleShape::Circle { radius } => { HandleShape::Circle { radius } => {
(f32::from(radius * 2), f32::from(radius * 2), radius) (radius * 2.0, radius * 2.0, radius)
} }
HandleShape::Rectangle { HandleShape::Rectangle {
width, width,

View File

@ -149,8 +149,8 @@ where
background: Background::Color( background: Background::Color(
style_sheet.value_color(), style_sheet.value_color(),
), ),
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
offset, offset,
@ -193,8 +193,8 @@ where
background: Background::Color( background: Background::Color(
style_sheet.selection_color(), style_sheet.selection_color(),
), ),
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
if end == right { if end == right {

View File

@ -6,8 +6,8 @@ use iced_core::{Background, Color, Vector};
pub struct Style { pub struct Style {
pub shadow_offset: Vector, pub shadow_offset: Vector,
pub background: Option<Background>, pub background: Option<Background>,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
pub text_color: Color, pub text_color: Color,
} }
@ -17,8 +17,8 @@ impl std::default::Default for Style {
Self { Self {
shadow_offset: Vector::default(), shadow_offset: Vector::default(),
background: None, background: None,
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
text_color: Color::BLACK, text_color: Color::BLACK,
} }
@ -72,8 +72,8 @@ impl StyleSheet for Default {
Style { Style {
shadow_offset: Vector::new(0.0, 0.0), shadow_offset: Vector::new(0.0, 0.0),
background: Some(Background::Color([0.87, 0.87, 0.87].into())), background: Some(Background::Color([0.87, 0.87, 0.87].into())),
border_radius: 2, border_radius: 2.0,
border_width: 1, border_width: 1.0,
border_color: [0.7, 0.7, 0.7].into(), border_color: [0.7, 0.7, 0.7].into(),
text_color: Color::BLACK, text_color: Color::BLACK,
} }

View File

@ -6,8 +6,8 @@ use iced_core::{Background, Color};
pub struct Style { pub struct Style {
pub background: Background, pub background: Background,
pub checkmark_color: Color, pub checkmark_color: Color,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
@ -25,8 +25,8 @@ impl StyleSheet for Default {
Style { Style {
background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)),
checkmark_color: Color::from_rgb(0.3, 0.3, 0.3), checkmark_color: Color::from_rgb(0.3, 0.3, 0.3),
border_radius: 5, border_radius: 5.0,
border_width: 1, border_width: 1.0,
border_color: Color::from_rgb(0.6, 0.6, 0.6), border_color: Color::from_rgb(0.6, 0.6, 0.6),
} }
} }

View File

@ -6,8 +6,8 @@ use iced_core::{Background, Color};
pub struct Style { pub struct Style {
pub text_color: Option<Color>, pub text_color: Option<Color>,
pub background: Option<Background>, pub background: Option<Background>,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
@ -16,8 +16,8 @@ impl std::default::Default for Style {
Self { Self {
text_color: None, text_color: None,
background: None, background: None,
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
} }
} }
@ -36,8 +36,8 @@ impl StyleSheet for Default {
Style { Style {
text_color: None, text_color: None,
background: None, background: None,
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
} }
} }

View File

@ -5,7 +5,7 @@ use iced_core::{Background, Color};
pub struct Style { pub struct Style {
pub text_color: Color, pub text_color: Color,
pub background: Background, pub background: Background,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
pub selected_text_color: Color, pub selected_text_color: Color,
pub selected_background: Background, pub selected_background: Background,
@ -16,7 +16,7 @@ impl std::default::Default for Style {
Self { Self {
text_color: Color::BLACK, text_color: Color::BLACK,
background: Background::Color([0.87, 0.87, 0.87].into()), background: Background::Color([0.87, 0.87, 0.87].into()),
border_width: 1, border_width: 1.0,
border_color: [0.7, 0.7, 0.7].into(), border_color: [0.7, 0.7, 0.7].into(),
selected_text_color: Color::WHITE, selected_text_color: Color::WHITE,
selected_background: Background::Color([0.4, 0.4, 1.0].into()), selected_background: Background::Color([0.4, 0.4, 1.0].into()),

View File

@ -6,8 +6,8 @@ use iced_core::{Background, Color};
pub struct Style { pub struct Style {
pub text_color: Color, pub text_color: Color,
pub background: Background, pub background: Background,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
pub icon_size: f32, pub icon_size: f32,
} }
@ -17,8 +17,8 @@ impl std::default::Default for Style {
Self { Self {
text_color: Color::BLACK, text_color: Color::BLACK,
background: Background::Color([0.87, 0.87, 0.87].into()), background: Background::Color([0.87, 0.87, 0.87].into()),
border_radius: 0, border_radius: 0.0,
border_width: 1, border_width: 1.0,
border_color: [0.7, 0.7, 0.7].into(), border_color: [0.7, 0.7, 0.7].into(),
icon_size: 0.7, icon_size: 0.7,
} }

View File

@ -6,7 +6,7 @@ use iced_core::{Background, Color};
pub struct Style { pub struct Style {
pub background: Background, pub background: Background,
pub bar: Background, pub bar: Background,
pub border_radius: u16, pub border_radius: f32,
} }
/// A set of rules that dictate the style of a progress bar. /// A set of rules that dictate the style of a progress bar.
@ -21,7 +21,7 @@ impl StyleSheet for Default {
Style { Style {
background: Background::Color(Color::from_rgb(0.6, 0.6, 0.6)), background: Background::Color(Color::from_rgb(0.6, 0.6, 0.6)),
bar: Background::Color(Color::from_rgb(0.3, 0.9, 0.3)), bar: Background::Color(Color::from_rgb(0.3, 0.9, 0.3)),
border_radius: 5, border_radius: 5.0,
} }
} }
} }

View File

@ -6,7 +6,7 @@ use iced_core::{Background, Color};
pub struct Style { pub struct Style {
pub background: Background, pub background: Background,
pub dot_color: Color, pub dot_color: Color,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
@ -24,7 +24,7 @@ impl StyleSheet for Default {
Style { Style {
background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)), background: Background::Color(Color::from_rgb(0.95, 0.95, 0.95)),
dot_color: Color::from_rgb(0.3, 0.3, 0.3), dot_color: Color::from_rgb(0.3, 0.3, 0.3),
border_width: 1, border_width: 1.0,
border_color: Color::from_rgb(0.6, 0.6, 0.6), border_color: Color::from_rgb(0.6, 0.6, 0.6),
} }
} }

View File

@ -74,7 +74,7 @@ pub struct Style {
/// The width (thickness) of the rule line. /// The width (thickness) of the rule line.
pub width: u16, pub width: u16,
/// The radius of the line corners. /// The radius of the line corners.
pub radius: u16, pub radius: f32,
/// The [`FillMode`] of the rule. /// The [`FillMode`] of the rule.
/// ///
/// [`FillMode`]: enum.FillMode.html /// [`FillMode`]: enum.FillMode.html
@ -94,7 +94,7 @@ impl StyleSheet for Default {
Style { Style {
color: [0.6, 0.6, 0.6, 0.51].into(), color: [0.6, 0.6, 0.6, 0.51].into(),
width: 1, width: 1,
radius: 0, radius: 0.0,
fill_mode: FillMode::Percent(90.0), fill_mode: FillMode::Percent(90.0),
} }
} }

View File

@ -5,8 +5,8 @@ use iced_core::{Background, Color};
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Scrollbar { pub struct Scrollbar {
pub background: Option<Background>, pub background: Option<Background>,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
pub scroller: Scroller, pub scroller: Scroller,
} }
@ -15,8 +15,8 @@ pub struct Scrollbar {
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Scroller { pub struct Scroller {
pub color: Color, pub color: Color,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
@ -40,13 +40,13 @@ impl StyleSheet for Default {
fn active(&self) -> Scrollbar { fn active(&self) -> Scrollbar {
Scrollbar { Scrollbar {
background: None, background: None,
border_radius: 5, border_radius: 5.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
scroller: Scroller { scroller: Scroller {
color: [0.0, 0.0, 0.0, 0.7].into(), color: [0.0, 0.0, 0.0, 0.7].into(),
border_radius: 5, border_radius: 5.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
}, },
} }

View File

@ -13,15 +13,15 @@ pub struct Style {
pub struct Handle { pub struct Handle {
pub shape: HandleShape, pub shape: HandleShape,
pub color: Color, pub color: Color,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
/// The shape of the handle of a slider. /// The shape of the handle of a slider.
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub enum HandleShape { pub enum HandleShape {
Circle { radius: u16 }, Circle { radius: f32 },
Rectangle { width: u16, border_radius: u16 }, Rectangle { width: u16, border_radius: f32 },
} }
/// A set of rules that dictate the style of a slider. /// A set of rules that dictate the style of a slider.
@ -45,11 +45,11 @@ impl StyleSheet for Default {
handle: Handle { handle: Handle {
shape: HandleShape::Rectangle { shape: HandleShape::Rectangle {
width: 8, width: 8,
border_radius: 4, border_radius: 4.0,
}, },
color: Color::from_rgb(0.95, 0.95, 0.95), color: Color::from_rgb(0.95, 0.95, 0.95),
border_color: Color::from_rgb(0.6, 0.6, 0.6), border_color: Color::from_rgb(0.6, 0.6, 0.6),
border_width: 1, border_width: 1.0,
}, },
} }
} }

View File

@ -5,8 +5,8 @@ use iced_core::{Background, Color};
#[derive(Debug, Clone, Copy)] #[derive(Debug, Clone, Copy)]
pub struct Style { pub struct Style {
pub background: Background, pub background: Background,
pub border_radius: u16, pub border_radius: f32,
pub border_width: u16, pub border_width: f32,
pub border_color: Color, pub border_color: Color,
} }
@ -14,8 +14,8 @@ impl std::default::Default for Style {
fn default() -> Self { fn default() -> Self {
Self { Self {
background: Background::Color(Color::WHITE), background: Background::Color(Color::WHITE),
border_radius: 0, border_radius: 0.0,
border_width: 0, border_width: 0.0,
border_color: Color::TRANSPARENT, border_color: Color::TRANSPARENT,
} }
} }
@ -47,8 +47,8 @@ impl StyleSheet for Default {
fn active(&self) -> Style { fn active(&self) -> Style {
Style { Style {
background: Background::Color(Color::WHITE), background: Background::Color(Color::WHITE),
border_radius: 5, border_radius: 5.0,
border_width: 1, border_width: 1.0,
border_color: Color::from_rgb(0.7, 0.7, 0.7), border_color: Color::from_rgb(0.7, 0.7, 0.7),
} }
} }

View File

@ -24,6 +24,11 @@ void main() {
vec2 p_Pos = i_Pos * u_Scale; vec2 p_Pos = i_Pos * u_Scale;
vec2 p_Scale = i_Scale * u_Scale; vec2 p_Scale = i_Scale * u_Scale;
float i_BorderRadius = min(
i_BorderRadius,
min(i_Scale.x, i_Scale.y) / 2.0
);
mat4 i_Transform = mat4( mat4 i_Transform = mat4(
vec4(p_Scale.x + 1.0, 0.0, 0.0, 0.0), vec4(p_Scale.x + 1.0, 0.0, 0.0, 0.0),
vec4(0.0, p_Scale.y + 1.0, 0.0, 0.0), vec4(0.0, p_Scale.y + 1.0, 0.0, 0.0),

Binary file not shown.