diff options
Diffstat (limited to 'native/src/widget')
-rw-r--r-- | native/src/widget/image/viewer.rs | 13 | ||||
-rw-r--r-- | native/src/widget/pane_grid.rs | 4 | ||||
-rw-r--r-- | native/src/widget/progress_bar.rs | 2 | ||||
-rw-r--r-- | native/src/widget/scrollable.rs | 5 | ||||
-rw-r--r-- | native/src/widget/toggler.rs | 4 |
5 files changed, 12 insertions, 16 deletions
diff --git a/native/src/widget/image/viewer.rs b/native/src/widget/image/viewer.rs index 9c83287e..fdbd3216 100644 --- a/native/src/widget/image/viewer.rs +++ b/native/src/widget/image/viewer.rs @@ -170,8 +170,7 @@ where } else { state.scale / (1.0 + self.scale_step) }) - .max(self.min_scale) - .min(self.max_scale); + .clamp(self.min_scale, self.max_scale); let image_size = image_size( renderer, @@ -251,16 +250,14 @@ where let x = if bounds.width < image_size.width { (state.starting_offset.x - delta.x) - .min(hidden_width) - .max(-hidden_width) + .clamp(-hidden_width, hidden_width) } else { 0.0 }; let y = if bounds.height < image_size.height { (state.starting_offset.y - delta.y) - .min(hidden_height) - .max(-hidden_height) + .clamp(-hidden_height, hidden_height) } else { 0.0 }; @@ -374,8 +371,8 @@ impl State { (image_size.height - bounds.height / 2.0).max(0.0).round(); Vector::new( - self.current_offset.x.min(hidden_width).max(-hidden_width), - self.current_offset.y.min(hidden_height).max(-hidden_height), + self.current_offset.x.clamp(-hidden_width, hidden_width), + self.current_offset.y.clamp(-hidden_height, hidden_height), ) } diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 5de95c65..61597921 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -630,13 +630,13 @@ pub fn update<'a, Message, T: Draggable>( let position = cursor_position.y - bounds.y - rectangle.y; - (position / rectangle.height).max(0.1).min(0.9) + (position / rectangle.height).clamp(0.1, 0.9) } Axis::Vertical => { let position = cursor_position.x - bounds.x - rectangle.x; - (position / rectangle.width).max(0.1).min(0.9) + (position / rectangle.width).clamp(0.1, 0.9) } }; diff --git a/native/src/widget/progress_bar.rs b/native/src/widget/progress_bar.rs index f059026f..7d5d5be5 100644 --- a/native/src/widget/progress_bar.rs +++ b/native/src/widget/progress_bar.rs @@ -47,7 +47,7 @@ where /// * the current value of the [`ProgressBar`] pub fn new(range: RangeInclusive<f32>, value: f32) -> Self { ProgressBar { - value: value.max(*range.start()).min(*range.end()), + value: value.clamp(*range.start(), *range.end()), range, width: Length::Fill, height: None, diff --git a/native/src/widget/scrollable.rs b/native/src/widget/scrollable.rs index a5e0e0e3..1af0a6ab 100644 --- a/native/src/widget/scrollable.rs +++ b/native/src/widget/scrollable.rs @@ -881,8 +881,7 @@ impl State { self.offset = Offset::Absolute( (self.offset.absolute(bounds, content_bounds) - delta_y) - .max(0.0) - .min((content_bounds.height - bounds.height) as f32), + .clamp(0.0, content_bounds.height - bounds.height), ); } @@ -905,7 +904,7 @@ impl State { /// `0` represents scrollbar at the top, while `1` represents scrollbar at /// the bottom. pub fn snap_to(&mut self, percentage: f32) { - self.offset = Offset::Relative(percentage.max(0.0).min(1.0)); + self.offset = Offset::Relative(percentage.clamp(0.0, 1.0)); } /// Unsnaps the current scroll position, if snapped, given the bounds of the diff --git a/native/src/widget/toggler.rs b/native/src/widget/toggler.rs index 37cafd92..1ae65ba6 100644 --- a/native/src/widget/toggler.rs +++ b/native/src/widget/toggler.rs @@ -265,8 +265,8 @@ where theme.active(&self.style, self.is_active) }; - let border_radius = bounds.height as f32 / BORDER_RADIUS_RATIO; - let space = SPACE_RATIO * bounds.height as f32; + let border_radius = bounds.height / BORDER_RADIUS_RATIO; + let space = SPACE_RATIO * bounds.height; let toggler_background_bounds = Rectangle { x: bounds.x + space, |