diff options
author | 2020-11-23 00:31:50 +0100 | |
---|---|---|
committer | 2020-11-23 00:31:50 +0100 | |
commit | f41eacc3dcc849f43c875872259ef8106e10be03 (patch) | |
tree | b3aafbca00d799842e56eb3bbfc4a9292248f816 /examples | |
parent | ea1a7248d257c7c9e4a1f3989e68b58a6bc0c4ff (diff) | |
download | iced-f41eacc3dcc849f43c875872259ef8106e10be03.tar.gz iced-f41eacc3dcc849f43c875872259ef8106e10be03.tar.bz2 iced-f41eacc3dcc849f43c875872259ef8106e10be03.zip |
Use `f32` for `border_width` and `border_radius`
Diffstat (limited to 'examples')
-rw-r--r-- | examples/custom_widget/src/main.rs | 36 | ||||
-rw-r--r-- | examples/game_of_life/src/style.rs | 18 | ||||
-rw-r--r-- | examples/pane_grid/src/main.rs | 4 | ||||
-rw-r--r-- | examples/pokedex/src/main.rs | 2 | ||||
-rw-r--r-- | examples/scrollable/src/style.rs | 12 | ||||
-rw-r--r-- | examples/stopwatch/src/main.rs | 2 | ||||
-rw-r--r-- | examples/styling/src/main.rs | 36 | ||||
-rw-r--r-- | examples/todos/src/main.rs | 4 | ||||
-rw-r--r-- | examples/tour/src/main.rs | 2 |
9 files changed, 58 insertions, 58 deletions
diff --git a/examples/custom_widget/src/main.rs b/examples/custom_widget/src/main.rs index a0003d65..36f468c7 100644 --- a/examples/custom_widget/src/main.rs +++ b/examples/custom_widget/src/main.rs @@ -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) diff --git a/examples/game_of_life/src/style.rs b/examples/game_of_life/src/style.rs index 308ce43c..6605826f 100644 --- a/examples/game_of_life/src/style.rs +++ b/examples/game_of_life/src/style.rs @@ -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, } } diff --git a/examples/pane_grid/src/main.rs b/examples/pane_grid/src/main.rs index f986cc8d..3c3256cf 100644 --- a/examples/pane_grid/src/main.rs +++ b/examples/pane_grid/src/main.rs @@ -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() } diff --git a/examples/pokedex/src/main.rs b/examples/pokedex/src/main.rs index 30674fa0..187e5dee 100644 --- a/examples/pokedex/src/main.rs +++ b/examples/pokedex/src/main.rs @@ -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() diff --git a/examples/scrollable/src/style.rs b/examples/scrollable/src/style.rs index 24d711ac..ae449141 100644 --- a/examples/scrollable/src/style.rs +++ b/examples/scrollable/src/style.rs @@ -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), } } diff --git a/examples/stopwatch/src/main.rs b/examples/stopwatch/src/main.rs index 5a69aa9a..983cf3e6 100644 --- a/examples/stopwatch/src/main.rs +++ b/examples/stopwatch/src/main.rs @@ -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() diff --git a/examples/styling/src/main.rs b/examples/styling/src/main.rs index ef302e61..8975fd9a 100644 --- a/examples/styling/src/main.rs +++ b/examples/styling/src/main.rs @@ -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), } } diff --git a/examples/todos/src/main.rs b/examples/todos/src/main.rs index f88e9869..ccee2703 100644 --- a/examples/todos/src/main.rs +++ b/examples/todos/src/main.rs @@ -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() diff --git a/examples/tour/src/main.rs b/examples/tour/src/main.rs index 560d67e2..e8755d39 100644 --- a/examples/tour/src/main.rs +++ b/examples/tour/src/main.rs @@ -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() |