Skip to content

Commit

Permalink
Merge pull request #239 from airblast-dev/main
Browse files Browse the repository at this point in the history
Allow disabling scroll events for NumberInput.
  • Loading branch information
genusistimelord authored May 7, 2024
2 parents 6d2c4bf + ee949bd commit 477dbf8
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/widgets/number_input.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ where
font: Renderer::Font,
/// The Width to use for the ``NumberBox`` Default is ``Length::Fill``
width: Length,
/// Ignore mouse scroll events for the [`NumberInput`] Default is ``false``.
ignore_scroll_events: bool,
}

impl<'a, T, Message, Theme, Renderer> NumberInput<'a, T, Message, Theme, Renderer>
Expand Down Expand Up @@ -128,6 +130,7 @@ where
style: <Theme as number_input::StyleSheet>::Style::default(),
font: Renderer::Font::default(),
width: Length::Shrink,
ignore_scroll_events: false,
}
}

Expand Down Expand Up @@ -222,6 +225,14 @@ where
self
}

/// Enable or disable mouse scrolling events of the [`NumberInput`], by default this is set to
/// ``false``.
#[must_use]
pub fn ignore_scroll(mut self, ignore: bool) -> Self {
self.ignore_scroll_events = ignore;
self
}

/// Decrease current value by step of the [`NumberInput`].
fn decrease_val(&mut self, shell: &mut Shell<Message>) {
if self.bounds.1 - self.bounds.0 < self.step || self.value < self.bounds.0 + self.step {
Expand Down Expand Up @@ -516,7 +527,9 @@ where
}
}
}
Event::Mouse(mouse::Event::WheelScrolled { delta }) if mouse_over_widget => {
Event::Mouse(mouse::Event::WheelScrolled { delta })
if mouse_over_widget && !self.ignore_scroll_events =>
{
match delta {
mouse::ScrollDelta::Lines { y, .. } | mouse::ScrollDelta::Pixels { y, .. } => {
if y.is_sign_positive() {
Expand Down

0 comments on commit 477dbf8

Please sign in to comment.