diff options
Diffstat (limited to 'native')
-rw-r--r-- | native/src/user_interface.rs | 2 | ||||
-rw-r--r-- | native/src/widget/checkbox.rs | 24 | ||||
-rw-r--r-- | native/src/widget/pane_grid.rs | 31 | ||||
-rw-r--r-- | native/src/widget/slider.rs | 22 |
4 files changed, 56 insertions, 23 deletions
diff --git a/native/src/user_interface.rs b/native/src/user_interface.rs index 39cac559..f44ed1fb 100644 --- a/native/src/user_interface.rs +++ b/native/src/user_interface.rs @@ -409,7 +409,7 @@ where let overlay_bounds = layer.layout.bounds(); - renderer.with_layer(viewport, |renderer| { + renderer.with_layer(overlay_bounds, |renderer| { overlay.draw( renderer, &renderer::Style::default(), diff --git a/native/src/widget/checkbox.rs b/native/src/widget/checkbox.rs index 0d4a43ec..81611426 100644 --- a/native/src/widget/checkbox.rs +++ b/native/src/widget/checkbox.rs @@ -216,24 +216,24 @@ where let mut children = layout.children(); + let custom_style = if is_mouse_over { + self.style_sheet.hovered(self.is_checked) + } else { + self.style_sheet.active(self.is_checked) + }; + { let layout = children.next().unwrap(); let bounds = layout.bounds(); - let style = if is_mouse_over { - self.style_sheet.hovered(self.is_checked) - } else { - self.style_sheet.active(self.is_checked) - }; - renderer.fill_quad( renderer::Quad { bounds, - border_radius: style.border_radius, - border_width: style.border_width, - border_color: style.border_color, + border_radius: custom_style.border_radius, + border_width: custom_style.border_width, + border_color: custom_style.border_color, }, - style.background, + custom_style.background, ); if self.is_checked { @@ -246,7 +246,7 @@ where y: bounds.center_y(), ..bounds }, - color: style.checkmark_color, + color: custom_style.checkmark_color, horizontal_alignment: alignment::Horizontal::Center, vertical_alignment: alignment::Vertical::Center, }); @@ -263,7 +263,7 @@ where &self.label, self.font, self.text_size, - self.text_color, + self.text_color.or(Some(custom_style.text_color)), alignment::Horizontal::Left, alignment::Vertical::Center, ); diff --git a/native/src/widget/pane_grid.rs b/native/src/widget/pane_grid.rs index 20616ed4..3637822b 100644 --- a/native/src/widget/pane_grid.rs +++ b/native/src/widget/pane_grid.rs @@ -481,10 +481,33 @@ where return mouse::Interaction::Grab; } - if let Some((_, axis)) = self.state.picked_split() { - return match axis { - Axis::Horizontal => mouse::Interaction::ResizingHorizontally, - Axis::Vertical => mouse::Interaction::ResizingVertically, + let resize_axis = + self.state.picked_split().map(|(_, axis)| axis).or_else(|| { + self.on_resize.as_ref().and_then(|(leeway, _)| { + let bounds = layout.bounds(); + + let splits = self + .state + .split_regions(f32::from(self.spacing), bounds.size()); + + let relative_cursor = Point::new( + cursor_position.x - bounds.x, + cursor_position.y - bounds.y, + ); + + hovered_split( + splits.iter(), + f32::from(self.spacing + leeway), + relative_cursor, + ) + .map(|(_, axis, _)| axis) + }) + }); + + if let Some(resize_axis) = resize_axis { + return match resize_axis { + Axis::Horizontal => mouse::Interaction::ResizingVertically, + Axis::Vertical => mouse::Interaction::ResizingHorizontally, }; } diff --git a/native/src/widget/slider.rs b/native/src/widget/slider.rs index 49bafab4..3ce53f6c 100644 --- a/native/src/widget/slider.rs +++ b/native/src/widget/slider.rs @@ -193,12 +193,14 @@ where _clipboard: &mut dyn Clipboard, messages: &mut Vec<Message>, ) -> event::Status { + let is_dragging = self.state.is_dragging; + let mut change = || { let bounds = layout.bounds(); - if cursor_position.x <= bounds.x { - messages.push((self.on_change)(*self.range.start())); + let new_value = if cursor_position.x <= bounds.x { + *self.range.start() } else if cursor_position.x >= bounds.x + bounds.width { - messages.push((self.on_change)(*self.range.end())); + *self.range.end() } else { let step = self.step.into(); let start = (*self.range.start()).into(); @@ -211,8 +213,16 @@ where let value = steps * step + start; if let Some(value) = T::from_f64(value) { - messages.push((self.on_change)(value)); + value + } else { + return; } + }; + + if (self.value.into() - new_value.into()).abs() > f64::EPSILON { + messages.push((self.on_change)(new_value)); + + self.value = new_value; } }; @@ -229,7 +239,7 @@ where Event::Mouse(mouse::Event::ButtonReleased(mouse::Button::Left)) | Event::Touch(touch::Event::FingerLifted { .. }) | Event::Touch(touch::Event::FingerLost { .. }) => { - if self.state.is_dragging { + if is_dragging { if let Some(on_release) = self.on_release.clone() { messages.push(on_release); } @@ -240,7 +250,7 @@ where } Event::Mouse(mouse::Event::CursorMoved { .. }) | Event::Touch(touch::Event::FingerMoved { .. }) => { - if self.state.is_dragging { + if is_dragging { change(); return event::Status::Captured; |