diff options
author | 2020-11-23 00:31:50 +0100 | |
---|---|---|
committer | 2020-11-23 00:31:50 +0100 | |
commit | f41eacc3dcc849f43c875872259ef8106e10be03 (patch) | |
tree | b3aafbca00d799842e56eb3bbfc4a9292248f816 /examples/custom_widget | |
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/custom_widget')
-rw-r--r-- | examples/custom_widget/src/main.rs | 36 |
1 files changed, 18 insertions, 18 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) |