Use f32 for border_width and border_radius

This commit is contained in:
Héctor Ramón Jiménez 2020-11-23 00:31:50 +01:00
parent ea1a7248d2
commit f41eacc3dc
32 changed files with 134 additions and 134 deletions

View file

@ -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)