diff --git a/src/modules/custom/box.rs b/src/modules/custom/box.rs index af541e6..13a6781 100644 --- a/src/modules/custom/box.rs +++ b/src/modules/custom/box.rs @@ -21,7 +21,7 @@ impl CustomWidget for BoxWidget { if let Some(orientation) = self.orientation { container.set_orientation( try_get_orientation(&orientation).unwrap_or(Orientation::Horizontal), - ) + ); } if let Some(widgets) = self.widgets { diff --git a/src/modules/custom/mod.rs b/src/modules/custom/mod.rs index 1ba97a6..5c9bfb5 100644 --- a/src/modules/custom/mod.rs +++ b/src/modules/custom/mod.rs @@ -109,12 +109,12 @@ impl Widget { /// Creates this widget and adds it to the parent container fn add_to(self, parent: >k::Box, context: CustomWidgetContext) { match self { - Widget::Box(widget) => parent.add(&widget.into_widget(context)), - Widget::Label(widget) => parent.add(&widget.into_widget(context)), - Widget::Button(widget) => parent.add(&widget.into_widget(context)), - Widget::Image(widget) => parent.add(&widget.into_widget(context)), - Widget::Slider(widget) => parent.add(&widget.into_widget(context)), - Widget::Progress(widget) => parent.add(&widget.into_widget(context)), + Self::Box(widget) => parent.add(&widget.into_widget(context)), + Self::Label(widget) => parent.add(&widget.into_widget(context)), + Self::Button(widget) => parent.add(&widget.into_widget(context)), + Self::Image(widget) => parent.add(&widget.into_widget(context)), + Self::Slider(widget) => parent.add(&widget.into_widget(context)), + Self::Progress(widget) => parent.add(&widget.into_widget(context)), } } } @@ -147,7 +147,7 @@ impl Module for CustomModule { debug!("executing command: '{}'", script.cmd); - let args = event.args.unwrap_or(vec![]); + let args = event.args.unwrap_or_default(); if let Err(err) = script.get_output(Some(&args)).await { error!("{err:?}"); diff --git a/src/modules/custom/slider.rs b/src/modules/custom/slider.rs index 030053d..0b2f946 100644 --- a/src/modules/custom/slider.rs +++ b/src/modules/custom/slider.rs @@ -60,7 +60,7 @@ impl CustomWidget for SliderWidget { scale.connect_change_value(move |scale, _, val| { // GTK will send values outside min/max range - let val = clamp(val, min, max); + let val = val.clamp(min, max); if val != prev_value.get() { try_send!( @@ -106,14 +106,3 @@ impl CustomWidget for SliderWidget { scale } } - -/// Ensures `num` is between `min` and `max` (inclusive). -fn clamp(num: f64, min: f64, max: f64) -> f64 { - if num < min { - min - } else if num > max { - max - } else { - num - } -}