From f173996f1234b9a810dfc0233f5877e573e7166d Mon Sep 17 00:00:00 2001 From: Bryan Hyland Date: Mon, 18 Nov 2024 11:16:31 -0800 Subject: [PATCH] Resolved vertical vs vertical_spin_button function API --- examples/spin-button/src/main.rs | 10 +++++----- src/widget/mod.rs | 2 +- src/widget/spin_button/mod.rs | 18 +++++++----------- 3 files changed, 13 insertions(+), 17 deletions(-) diff --git a/examples/spin-button/src/main.rs b/examples/spin-button/src/main.rs index 88adc151..092401b3 100644 --- a/examples/spin-button/src/main.rs +++ b/examples/spin-button/src/main.rs @@ -1,4 +1,4 @@ -use cosmic::widget::{button, container, text, spin_button, vertical_spin_button, /*spin_button::Orientation*/}; +use cosmic::widget::{button, container, text, spin_button, vertical}; use cosmic::{ app::{Core, Task}, iced::{ @@ -85,7 +85,7 @@ impl Application for SpinButtonExamplApp { fn view(&self) -> Element { let vert_spinner_row = row![ - vertical_spin_button( + vertical( "i8", // label: displayed above the widget no matter the orientation 1, // step: how much to increment/decrement by self.i8_num, // current value, this is also what's displayed in the center of the widget @@ -93,7 +93,7 @@ impl Application for SpinButtonExamplApp { 5, // maximum value, if incremented above this the widget's current value rolls to the min value SpinBtnMessages::UpdateI8Num // message to send to the application's update function ), - vertical_spin_button( + vertical( "i16", 1, self.i16_num, @@ -101,7 +101,7 @@ impl Application for SpinButtonExamplApp { 10, SpinBtnMessages::UpdateI16Num ), - vertical_spin_button( + vertical( "i32", 1, self.i32_num, @@ -109,7 +109,7 @@ impl Application for SpinButtonExamplApp { 12, SpinBtnMessages::UpdateI32Num ), - vertical_spin_button( + vertical( "i64", 10, self.i64_num, diff --git a/src/widget/mod.rs b/src/widget/mod.rs index 661a52fa..7f474ac1 100644 --- a/src/widget/mod.rs +++ b/src/widget/mod.rs @@ -311,7 +311,7 @@ pub mod settings; pub mod spin_button; #[doc(inline)] -pub use spin_button::{spin_button, vertical_spin_button, SpinButton}; +pub use spin_button::{spin_button, vertical}; pub mod tab_bar; diff --git a/src/widget/spin_button/mod.rs b/src/widget/spin_button/mod.rs index 85edcf63..60c96064 100644 --- a/src/widget/spin_button/mod.rs +++ b/src/widget/spin_button/mod.rs @@ -48,8 +48,8 @@ where /// The maximum value permitted. /// If the value is incremented above this value the current value will rollover to the min value. max: T, - /// The direction that the spin button is laid out; Horizontal (default) or Vertical - orientation: Option, + /// The direction that the spin button is laid out; Orientation::Horizontal or Orientation::Vertical + orientation: Orientation, /// The message that the spin button emits to the application's update function. on_press: Box M>, phantom_data: PhantomData<&'a M>, @@ -66,7 +66,7 @@ where value: T, min: T, max: T, - orientation: Option, + orientation: Orientation, on_press: impl Fn(T) -> M + 'static, ) -> Self { Self { @@ -94,11 +94,11 @@ pub fn spin_button<'a, T, M>( where T: Add + Sub + PartialEq + PartialOrd + Display + Copy { - SpinButton::new(label, step, value, min, max, None, on_press) + SpinButton::new(label, step, value, min, max, Orientation::Horizontal, on_press) } /// Shorthand to create a standard (horizontal) spin button widget -pub fn vertical_spin_button<'a, T, M>( +pub fn vertical<'a, T, M>( label: impl Into, step: T, value: T, @@ -109,7 +109,7 @@ pub fn vertical_spin_button<'a, T, M>( where T: Add + Sub + PartialEq + PartialOrd + Display + Copy { - SpinButton::new(label, step, value, min, max, Some(Orientation::Vertical), on_press) + SpinButton::new(label, step, value, min, max, Orientation::Vertical, on_press) } fn increment(step: T, value: T, min: T, max: T) -> T @@ -145,12 +145,8 @@ where // Matching on the direction enum given by the developer when the // widget is initially created in the application's view function. match this.orientation { - Some(orien) => match orien { Orientation::Horizontal => create_horizontal_spin_button(&this), - Orientation::Vertical => create_vertical_spin_button(&this) - } - // Default behavior is to create a horizontal spin button widget - None => create_horizontal_spin_button(&this), + Orientation::Vertical => create_vertical_spin_button(&this), } } }