Resolved vertical vs vertical_spin_button function API

This commit is contained in:
Bryan Hyland 2024-11-18 11:16:31 -08:00
parent 6e0736dbfc
commit f173996f12
3 changed files with 13 additions and 17 deletions

View file

@ -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<Self::Message> {
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,

View file

@ -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;

View file

@ -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<Orientation>,
/// 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<dyn Fn(T) -> M>,
phantom_data: PhantomData<&'a M>,
@ -66,7 +66,7 @@ where
value: T,
min: T,
max: T,
orientation: Option<Orientation>,
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<Output = T> + Sub<Output = T> + 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<String>,
step: T,
value: T,
@ -109,7 +109,7 @@ pub fn vertical_spin_button<'a, T, M>(
where
T: Add<Output = T> + Sub<Output = T> + 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<T>(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),
}
}
}