Fix missing reactive rendering logic for vertical_slider

This commit is contained in:
Héctor Ramón Jiménez 2025-01-24 21:44:00 +01:00
parent a22d96aae9
commit b7dd0bfda5
No known key found for this signature in database
GPG key ID: 7CC46565708259A7

View file

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