Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions widget/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ where
width: Length,
height: f32,
class: Theme::Class<'a>,
mouse_interaction: SliderMouseInteraction,
}

impl<'a, T, Message, Theme> Slider<'a, T, Message, Theme>
Expand Down Expand Up @@ -141,6 +142,7 @@ where
width: Length::Fill,
height: Self::DEFAULT_HEIGHT,
class: Theme::default(),
mouse_interaction: Default::default()
}
}

Expand Down Expand Up @@ -189,6 +191,13 @@ where
self
}

/// Sets the mouse interaction of the [`Slider`].
pub fn mouse_interaction(mut self, interaction: SliderMouseInteraction) -> Self
{
self.mouse_interaction = interaction;
self
}

/// Sets the style of the [`Slider`].
#[must_use]
pub fn style(mut self, style: impl Fn(&Theme, Status) -> Style + 'a) -> Self
Expand All @@ -208,6 +217,24 @@ where
}
}

/// Configuration of the [`mouse::Interaction`] displayed by a [`Slider`]
#[derive(Debug)]
pub struct SliderMouseInteraction {
/// [`mouse::Interaction`] when dragging the [`Slider`]
pub dragging: mouse::Interaction,
/// [`mouse::Interaction`] when hovering over the [`Slider`]
pub mouse_over: mouse::Interaction,
}

impl Default for SliderMouseInteraction {
fn default() -> Self {
Self {
dragging: mouse::Interaction::Grabbing,
mouse_over: mouse::Interaction::Grab,
}
}
}

impl<'a, T, Message, Theme, Renderer> Widget<Message, Theme, Renderer>
for Slider<'a, T, Message, Theme>
where
Expand Down Expand Up @@ -520,9 +547,9 @@ where
let is_mouse_over = cursor.is_over(bounds);

if state.is_dragging {
mouse::Interaction::Grabbing
self.mouse_interaction.dragging
} else if is_mouse_over {
mouse::Interaction::Grab
self.mouse_interaction.mouse_over
} else {
mouse::Interaction::default()
}
Expand Down