Use f32 for border_width and border_radius
This commit is contained in:
parent
ea1a7248d2
commit
f41eacc3dc
32 changed files with 134 additions and 134 deletions
|
|
@ -16,11 +16,11 @@ mod circle {
|
|||
};
|
||||
|
||||
pub struct Circle {
|
||||
radius: u16,
|
||||
radius: f32,
|
||||
}
|
||||
|
||||
impl Circle {
|
||||
pub fn new(radius: u16) -> Self {
|
||||
pub fn new(radius: f32) -> Self {
|
||||
Self { radius }
|
||||
}
|
||||
}
|
||||
|
|
@ -42,16 +42,13 @@ mod circle {
|
|||
_renderer: &Renderer<B>,
|
||||
_limits: &layout::Limits,
|
||||
) -> layout::Node {
|
||||
layout::Node::new(Size::new(
|
||||
f32::from(self.radius) * 2.0,
|
||||
f32::from(self.radius) * 2.0,
|
||||
))
|
||||
layout::Node::new(Size::new(self.radius * 2.0, self.radius * 2.0))
|
||||
}
|
||||
|
||||
fn hash_layout(&self, state: &mut Hasher) {
|
||||
use std::hash::Hash;
|
||||
|
||||
self.radius.hash(state);
|
||||
self.radius.to_bits().hash(state);
|
||||
}
|
||||
|
||||
fn draw(
|
||||
|
|
@ -67,7 +64,7 @@ mod circle {
|
|||
bounds: layout.bounds(),
|
||||
background: Background::Color(Color::BLACK),
|
||||
border_radius: self.radius,
|
||||
border_width: 0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
mouse::Interaction::default(),
|
||||
|
|
@ -96,7 +93,7 @@ pub fn main() -> iced::Result {
|
|||
}
|
||||
|
||||
struct Example {
|
||||
radius: u16,
|
||||
radius: f32,
|
||||
slider: slider::State,
|
||||
}
|
||||
|
||||
|
|
@ -110,7 +107,7 @@ impl Sandbox for Example {
|
|||
|
||||
fn new() -> Self {
|
||||
Example {
|
||||
radius: 50,
|
||||
radius: 50.0,
|
||||
slider: slider::State::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -122,7 +119,7 @@ impl Sandbox for Example {
|
|||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::RadiusChanged(radius) => {
|
||||
self.radius = radius.round() as u16;
|
||||
self.radius = radius;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -134,13 +131,16 @@ impl Sandbox for Example {
|
|||
.max_width(500)
|
||||
.align_items(Align::Center)
|
||||
.push(Circle::new(self.radius))
|
||||
.push(Text::new(format!("Radius: {}", self.radius.to_string())))
|
||||
.push(Slider::new(
|
||||
&mut self.slider,
|
||||
1.0..=100.0,
|
||||
f32::from(self.radius),
|
||||
Message::RadiusChanged,
|
||||
));
|
||||
.push(Text::new(format!("Radius: {:.2}", self.radius)))
|
||||
.push(
|
||||
Slider::new(
|
||||
&mut self.slider,
|
||||
1.0..=100.0,
|
||||
self.radius,
|
||||
Message::RadiusChanged,
|
||||
)
|
||||
.step(0.01),
|
||||
);
|
||||
|
||||
Container::new(content)
|
||||
.width(Length::Fill)
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ impl button::StyleSheet for Button {
|
|||
fn active(&self) -> button::Style {
|
||||
button::Style {
|
||||
background: Some(Background::Color(ACTIVE)),
|
||||
border_radius: 3,
|
||||
border_radius: 3.0,
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
}
|
||||
|
|
@ -60,7 +60,7 @@ impl button::StyleSheet for Button {
|
|||
|
||||
fn pressed(&self) -> button::Style {
|
||||
button::Style {
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: Color::WHITE,
|
||||
..self.hovered()
|
||||
}
|
||||
|
|
@ -73,7 +73,7 @@ impl button::StyleSheet for Clear {
|
|||
fn active(&self) -> button::Style {
|
||||
button::Style {
|
||||
background: Some(Background::Color(DESTRUCTIVE)),
|
||||
border_radius: 3,
|
||||
border_radius: 3.0,
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
}
|
||||
|
|
@ -92,7 +92,7 @@ impl button::StyleSheet for Clear {
|
|||
|
||||
fn pressed(&self) -> button::Style {
|
||||
button::Style {
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: Color::WHITE,
|
||||
..self.hovered()
|
||||
}
|
||||
|
|
@ -106,9 +106,9 @@ impl slider::StyleSheet for Slider {
|
|||
slider::Style {
|
||||
rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }),
|
||||
handle: slider::Handle {
|
||||
shape: slider::HandleShape::Circle { radius: 9 },
|
||||
shape: slider::HandleShape::Circle { radius: 9.0 },
|
||||
color: ACTIVE,
|
||||
border_width: 0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
}
|
||||
|
|
@ -146,7 +146,7 @@ impl pick_list::StyleSheet for PickList {
|
|||
pick_list::Menu {
|
||||
text_color: Color::WHITE,
|
||||
background: BACKGROUND.into(),
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: Color {
|
||||
a: 0.7,
|
||||
..Color::BLACK
|
||||
|
|
@ -164,12 +164,12 @@ impl pick_list::StyleSheet for PickList {
|
|||
pick_list::Style {
|
||||
text_color: Color::WHITE,
|
||||
background: BACKGROUND.into(),
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: Color {
|
||||
a: 0.6,
|
||||
..Color::BLACK
|
||||
},
|
||||
border_radius: 2,
|
||||
border_radius: 2.0,
|
||||
icon_size: 0.5,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ mod style {
|
|||
fn style(&self) -> container::Style {
|
||||
container::Style {
|
||||
background: Some(Background::Color(SURFACE)),
|
||||
border_width: 2,
|
||||
border_width: 2.0,
|
||||
border_color: if self.is_focused {
|
||||
Color::BLACK
|
||||
} else {
|
||||
|
|
@ -346,7 +346,7 @@ mod style {
|
|||
button::Style {
|
||||
text_color,
|
||||
background: background.map(Background::Color),
|
||||
border_radius: 5,
|
||||
border_radius: 5.0,
|
||||
shadow_offset: Vector::new(0.0, 0.0),
|
||||
..button::Style::default()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -251,7 +251,7 @@ mod style {
|
|||
background: Some(Background::Color(match self {
|
||||
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),
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ mod dark {
|
|||
radio::Style {
|
||||
background: SURFACE.into(),
|
||||
dot_color: ACTIVE,
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: ACTIVE,
|
||||
}
|
||||
}
|
||||
|
|
@ -137,13 +137,13 @@ mod dark {
|
|||
..SCROLLBAR
|
||||
}
|
||||
.into(),
|
||||
border_radius: 2,
|
||||
border_width: 0,
|
||||
border_radius: 2.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
scroller: scrollable::Scroller {
|
||||
color: Color { a: 0.7, ..SCROLLER },
|
||||
border_radius: 2,
|
||||
border_width: 0,
|
||||
border_radius: 2.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
}
|
||||
|
|
@ -182,7 +182,7 @@ mod dark {
|
|||
rule::Style {
|
||||
color: SURFACE,
|
||||
width: 2,
|
||||
radius: 1,
|
||||
radius: 1.0,
|
||||
fill_mode: rule::FillMode::Percent(30.0),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ mod style {
|
|||
Button::Secondary => Color::from_rgb(0.5, 0.5, 0.5),
|
||||
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),
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
|
|
|
|||
|
|
@ -249,7 +249,7 @@ mod style {
|
|||
fn active(&self) -> button::Style {
|
||||
button::Style {
|
||||
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),
|
||||
text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE),
|
||||
..button::Style::default()
|
||||
|
|
@ -315,7 +315,7 @@ mod style {
|
|||
radio::Style {
|
||||
background: SURFACE.into(),
|
||||
dot_color: ACTIVE,
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: ACTIVE,
|
||||
}
|
||||
}
|
||||
|
|
@ -334,15 +334,15 @@ mod style {
|
|||
fn active(&self) -> text_input::Style {
|
||||
text_input::Style {
|
||||
background: SURFACE.into(),
|
||||
border_radius: 2,
|
||||
border_width: 0,
|
||||
border_radius: 2.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
}
|
||||
}
|
||||
|
||||
fn focused(&self) -> text_input::Style {
|
||||
text_input::Style {
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: ACCENT,
|
||||
..self.active()
|
||||
}
|
||||
|
|
@ -350,7 +350,7 @@ mod style {
|
|||
|
||||
fn hovered(&self) -> text_input::Style {
|
||||
text_input::Style {
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: Color { a: 0.3, ..ACCENT },
|
||||
..self.focused()
|
||||
}
|
||||
|
|
@ -375,7 +375,7 @@ mod style {
|
|||
fn active(&self) -> button::Style {
|
||||
button::Style {
|
||||
background: ACTIVE.into(),
|
||||
border_radius: 3,
|
||||
border_radius: 3.0,
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
}
|
||||
|
|
@ -391,7 +391,7 @@ mod style {
|
|||
|
||||
fn pressed(&self) -> button::Style {
|
||||
button::Style {
|
||||
border_width: 1,
|
||||
border_width: 1.0,
|
||||
border_color: Color::WHITE,
|
||||
..self.hovered()
|
||||
}
|
||||
|
|
@ -404,13 +404,13 @@ mod style {
|
|||
fn active(&self) -> scrollable::Scrollbar {
|
||||
scrollable::Scrollbar {
|
||||
background: SURFACE.into(),
|
||||
border_radius: 2,
|
||||
border_width: 0,
|
||||
border_radius: 2.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
scroller: scrollable::Scroller {
|
||||
color: ACTIVE,
|
||||
border_radius: 2,
|
||||
border_width: 0,
|
||||
border_radius: 2.0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
}
|
||||
|
|
@ -449,9 +449,9 @@ mod style {
|
|||
slider::Style {
|
||||
rail_colors: (ACTIVE, Color { a: 0.1, ..ACTIVE }),
|
||||
handle: slider::Handle {
|
||||
shape: slider::HandleShape::Circle { radius: 9 },
|
||||
shape: slider::HandleShape::Circle { radius: 9.0 },
|
||||
color: ACTIVE,
|
||||
border_width: 0,
|
||||
border_width: 0.0,
|
||||
border_color: Color::TRANSPARENT,
|
||||
},
|
||||
}
|
||||
|
|
@ -489,7 +489,7 @@ mod style {
|
|||
progress_bar::Style {
|
||||
background: SURFACE.into(),
|
||||
bar: ACTIVE.into(),
|
||||
border_radius: 10,
|
||||
border_radius: 10.0,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -502,8 +502,8 @@ mod style {
|
|||
background: if is_checked { ACTIVE } else { SURFACE }
|
||||
.into(),
|
||||
checkmark_color: Color::WHITE,
|
||||
border_radius: 2,
|
||||
border_width: 1,
|
||||
border_radius: 2.0,
|
||||
border_width: 1.0,
|
||||
border_color: ACTIVE,
|
||||
}
|
||||
}
|
||||
|
|
@ -527,7 +527,7 @@ mod style {
|
|||
rule::Style {
|
||||
color: SURFACE,
|
||||
width: 2,
|
||||
radius: 1,
|
||||
radius: 1.0,
|
||||
fill_mode: rule::FillMode::Padded(15),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -611,7 +611,7 @@ mod style {
|
|||
background: Some(Background::Color(
|
||||
Color::from_rgb(0.2, 0.2, 0.7),
|
||||
)),
|
||||
border_radius: 10,
|
||||
border_radius: 10.0,
|
||||
text_color: Color::WHITE,
|
||||
..button::Style::default()
|
||||
}
|
||||
|
|
@ -627,7 +627,7 @@ mod style {
|
|||
background: Some(Background::Color(Color::from_rgb(
|
||||
0.8, 0.2, 0.2,
|
||||
))),
|
||||
border_radius: 5,
|
||||
border_radius: 5.0,
|
||||
text_color: Color::WHITE,
|
||||
shadow_offset: Vector::new(1.0, 1.0),
|
||||
..button::Style::default()
|
||||
|
|
|
|||
|
|
@ -769,7 +769,7 @@ mod style {
|
|||
Button::Primary => Color::from_rgb(0.11, 0.42, 0.87),
|
||||
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),
|
||||
text_color: Color::from_rgb8(0xEE, 0xEE, 0xEE),
|
||||
..button::Style::default()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue