Skip to content

Commit

Permalink
Rename step_fine in slider to shift_step
Browse files Browse the repository at this point in the history
  • Loading branch information
hecrj committed Jan 31, 2024
1 parent 66f8cf8 commit cd03a0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 23 deletions.
25 changes: 13 additions & 12 deletions widget/src/slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ where
{
range: RangeInclusive<T>,
step: T,
step_fine: Option<T>,
shift_step: Option<T>,
value: T,
default: Option<T>,
on_change: Box<dyn Fn(T) -> Message + 'a>,
Expand All @@ -63,7 +63,7 @@ where

impl<'a, T, Message, Theme> Slider<'a, T, Message, Theme>
where
T: Copy + From<u8> + std::cmp::PartialOrd,
T: Copy + From<u8> + PartialOrd,
Message: Clone,
Theme: StyleSheet,
{
Expand Down Expand Up @@ -99,7 +99,7 @@ where
default: None,
range,
step: T::from(1),
step_fine: None,
shift_step: None,
on_change: Box::new(on_change),
on_release: None,
width: Length::Fill,
Expand Down Expand Up @@ -150,10 +150,11 @@ where
self
}

/// Sets the optional fine-grained step size for the [`Slider`].
/// If set, this value is used as the step size while shift is pressed.
pub fn step_fine(mut self, step_fine: impl Into<T>) -> Self {
self.step_fine = Some(step_fine.into());
/// Sets the optional "shift" step for the [`Slider`].
///
/// If set, this value is used as the step while the shift key is pressed.
pub fn shift_step(mut self, shift_step: impl Into<T>) -> Self {
self.shift_step = Some(shift_step.into());
self
}
}
Expand Down Expand Up @@ -211,7 +212,7 @@ where
self.default,
&self.range,
self.step,
self.step_fine,
self.shift_step,
self.on_change.as_ref(),
&self.on_release,
)
Expand Down Expand Up @@ -278,7 +279,7 @@ pub fn update<Message, T>(
default: Option<T>,
range: &RangeInclusive<T>,
step: T,
step_fine: Option<T>,
shift_step: Option<T>,
on_change: &dyn Fn(T) -> Message,
on_release: &Option<Message>,
) -> event::Status
Expand All @@ -297,7 +298,7 @@ where
Some(*range.end())
} else {
let step = if state.keyboard_modifiers.shift() {
step_fine.unwrap_or(step)
shift_step.unwrap_or(step)
} else {
step
}
Expand All @@ -320,7 +321,7 @@ where

let increment = |value: T| -> Option<T> {
let step = if state.keyboard_modifiers.shift() {
step_fine.unwrap_or(step)
shift_step.unwrap_or(step)
} else {
step
}
Expand All @@ -338,7 +339,7 @@ where

let decrement = |value: T| -> Option<T> {
let step = if state.keyboard_modifiers.shift() {
step_fine.unwrap_or(step)
shift_step.unwrap_or(step)
} else {
step
}
Expand Down
23 changes: 12 additions & 11 deletions widget/src/vertical_slider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ where
{
range: RangeInclusive<T>,
step: T,
step_fine: Option<T>,
shift_step: Option<T>,
value: T,
default: Option<T>,
on_change: Box<dyn Fn(T) -> Message + 'a>,
Expand Down Expand Up @@ -96,7 +96,7 @@ where
default: None,
range,
step: T::from(1),
step_fine: None,
shift_step: None,
on_change: Box::new(on_change),
on_release: None,
width: Self::DEFAULT_WIDTH,
Expand Down Expand Up @@ -147,10 +147,11 @@ where
self
}

/// Sets the optional fine-grained step size for the [`VerticalSlider`].
/// If set, this value is used as the step size while shift is pressed.
pub fn step_fine(mut self, step_fine: impl Into<T>) -> Self {
self.step_fine = Some(step_fine.into());
/// Sets the optional "shift" step for the [`VerticalSlider`].
///
/// If set, this value is used as the step while the shift key is pressed.
pub fn shift_step(mut self, shift_step: impl Into<T>) -> Self {
self.shift_step = Some(shift_step.into());
self
}
}
Expand Down Expand Up @@ -208,7 +209,7 @@ where
self.default,
&self.range,
self.step,
self.step_fine,
self.shift_step,
self.on_change.as_ref(),
&self.on_release,
)
Expand Down Expand Up @@ -276,7 +277,7 @@ pub fn update<Message, T>(
default: Option<T>,
range: &RangeInclusive<T>,
step: T,
step_fine: Option<T>,
shift_step: Option<T>,
on_change: &dyn Fn(T) -> Message,
on_release: &Option<Message>,
) -> event::Status
Expand All @@ -296,7 +297,7 @@ where
Some(*range.end())
} else {
let step = if state.keyboard_modifiers.shift() {
step_fine.unwrap_or(step)
shift_step.unwrap_or(step)
} else {
step
}
Expand All @@ -320,7 +321,7 @@ where

let increment = |value: T| -> Option<T> {
let step = if state.keyboard_modifiers.shift() {
step_fine.unwrap_or(step)
shift_step.unwrap_or(step)
} else {
step
}
Expand All @@ -338,7 +339,7 @@ where

let decrement = |value: T| -> Option<T> {
let step = if state.keyboard_modifiers.shift() {
step_fine.unwrap_or(step)
shift_step.unwrap_or(step)
} else {
step
}
Expand Down

0 comments on commit cd03a0d

Please sign in to comment.