diff options
author | 2025-01-24 21:44:00 +0100 | |
---|---|---|
committer | 2025-01-24 21:44:00 +0100 | |
commit | b7dd0bfda53e7f00e63477890bb20c8953fb928d (patch) | |
tree | 284b8443374a634362b8f9085ad4230ec200ac35 /widget | |
parent | a22d96aae9af62b8aacc3132914c3f92a47c8c18 (diff) | |
download | iced-b7dd0bfda53e7f00e63477890bb20c8953fb928d.tar.gz iced-b7dd0bfda53e7f00e63477890bb20c8953fb928d.tar.bz2 iced-b7dd0bfda53e7f00e63477890bb20c8953fb928d.zip |
Fix missing reactive rendering logic for `vertical_slider`
Diffstat (limited to 'widget')
-rw-r--r-- | widget/src/vertical_slider.rs | 39 |
1 files changed, 24 insertions, 15 deletions
diff --git a/widget/src/vertical_slider.rs b/widget/src/vertical_slider.rs index c1af142b..2ed9419a 100644 --- a/widget/src/vertical_slider.rs +++ b/widget/src/vertical_slider.rs @@ -42,6 +42,7 @@ use crate::core::mouse; use crate::core::renderer; use crate::core::touch; use crate::core::widget::tree::{self, Tree}; +use crate::core::window; use crate::core::{ self, Clipboard, Element, Event, Length, Pixels, Point, Rectangle, Shell, Size, Widget, @@ -98,6 +99,7 @@ where width: f32, height: Length, class: Theme::Class<'a>, + status: Option<Status>, } impl<'a, T, Message, Theme> VerticalSlider<'a, T, Message, Theme> @@ -144,6 +146,7 @@ where width: Self::DEFAULT_WIDTH, height: Length::Fill, class: Theme::default(), + status: None, } } @@ -390,7 +393,9 @@ where shell.capture_event(); } } - Event::Keyboard(keyboard::Event::KeyPressed { key, .. }) => { + Event::Keyboard(keyboard::Event::KeyPressed { + ref key, .. + }) => { if cursor.is_over(layout.bounds()) { match key { Key::Named(key::Named::ArrowUp) => { @@ -410,32 +415,36 @@ where } _ => {} } + + let current_status = if state.is_dragging { + Status::Dragged + } else if cursor.is_over(layout.bounds()) { + Status::Hovered + } else { + Status::Active + }; + + if let Event::Window(window::Event::RedrawRequested(_now)) = event { + self.status = Some(current_status); + } else if self.status.is_some_and(|status| status != current_status) { + shell.request_redraw(); + } } fn draw( &self, - tree: &Tree, + _tree: &Tree, renderer: &mut Renderer, theme: &Theme, _style: &renderer::Style, layout: Layout<'_>, - cursor: mouse::Cursor, + _cursor: mouse::Cursor, _viewport: &Rectangle, ) { - let state = tree.state.downcast_ref::<State>(); let bounds = layout.bounds(); - let is_mouse_over = cursor.is_over(bounds); - let style = theme.style( - &self.class, - if state.is_dragging { - Status::Dragged - } else if is_mouse_over { - Status::Hovered - } else { - Status::Active - }, - ); + let style = + theme.style(&self.class, self.status.unwrap_or(Status::Active)); let (handle_width, handle_height, handle_border_radius) = match style.handle.shape { |