Resovled issues with PR

This commit is contained in:
Bryan Hyland 2024-11-18 10:25:29 -08:00
parent 57aa3ad671
commit 6e0736dbfc
6 changed files with 18 additions and 33 deletions

View file

@ -3,13 +3,6 @@ name = "vertical-spin-button"
version = "0.1.0" version = "0.1.0"
edition = "2021" edition = "2021"
[features]
default = ["xdg-portal"]
rfd = ["libcosmic/rfd"]
xdg-portal = ["libcosmic/xdg-portal"]
[dependencies]
[dependencies.libcosmic] [dependencies.libcosmic]
features = ["debug", "winit", "wayland", "desktop", "tokio"] features = ["debug", "winit", "wayland", "desktop", "tokio"]
path ="../.." path ="../.."

View file

@ -1,4 +1,4 @@
use cosmic::widget::{button, container, text, spin_button, spin_button_standard, spin_button::Orientation}; use cosmic::widget::{button, container, text, spin_button, vertical_spin_button, /*spin_button::Orientation*/};
use cosmic::{ use cosmic::{
app::{Core, Task}, app::{Core, Task},
iced::{ iced::{
@ -85,40 +85,36 @@ impl Application for SpinButtonExamplApp {
fn view(&self) -> Element<Self::Message> { fn view(&self) -> Element<Self::Message> {
let vert_spinner_row = row![ let vert_spinner_row = row![
spin_button( vertical_spin_button(
"i8", // label: displayed above the widget no matter the orientation "i8", // label: displayed above the widget no matter the orientation
1, // step: how much to increment/decrement by 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 self.i8_num, // current value, this is also what's displayed in the center of the widget
-5, // minimum value, if decremented below this the widget's current value rolls to the max value -5, // minimum value, if decremented below this the widget's current value rolls to the max value
5, // maximum value, if incremented above this the widget's current value rolls to the min value 5, // maximum value, if incremented above this the widget's current value rolls to the min value
Some(Orientation::Vertical), // oreintation of the widget
SpinBtnMessages::UpdateI8Num // message to send to the application's update function SpinBtnMessages::UpdateI8Num // message to send to the application's update function
), ),
spin_button( vertical_spin_button(
"i16", "i16",
1, 1,
self.i16_num, self.i16_num,
0, 0,
10, 10,
Some(Orientation::Vertical),
SpinBtnMessages::UpdateI16Num SpinBtnMessages::UpdateI16Num
), ),
spin_button( vertical_spin_button(
"i32", "i32",
1, 1,
self.i32_num, self.i32_num,
0, 0,
12, 12,
Some(Orientation::Vertical),
SpinBtnMessages::UpdateI32Num SpinBtnMessages::UpdateI32Num
), ),
spin_button( vertical_spin_button(
"i64", "i64",
10, 10,
self.i64_num, self.i64_num,
15, 15,
35, 35,
Some(Orientation::Vertical),
SpinBtnMessages::UpdateI64Num SpinBtnMessages::UpdateI64Num
), ),
] ]
@ -126,13 +122,13 @@ impl Application for SpinButtonExamplApp {
let horiz_spinner_row = column![ let horiz_spinner_row = column![
row![ row![
// This function can be called instead if a Horizontal Spin Button is needed.
spin_button( spin_button(
"i128", "i128",
100, 100,
self.i128_num, self.i128_num,
-1000, -1000,
500, 500,
None, // Passing None gives a default of a Horizontal Spin Button widget
SpinBtnMessages::UpdateI128Num SpinBtnMessages::UpdateI128Num
), ),
], ],
@ -144,15 +140,12 @@ impl Application for SpinButtonExamplApp {
self.f32_num, self.f32_num,
-35.3, -35.3,
12.3, 12.3,
Some(Orientation::Horizontal), // It can also be explicitly passed as Orientation::Horizontal
SpinBtnMessages::UpdateF32Num SpinBtnMessages::UpdateF32Num
) )
], ],
vertical_space().height(5), vertical_space().height(5),
row![ row![
// This function can be called instead if a Horizontal Spin Button is needed. spin_button(
// This shortens up the API call for default/standard Spin Button widgets.
spin_button_standard(
"f64", "f64",
1.3, 1.3,
self.f64_num, self.f64_num,

2
iced

@ -1 +1 @@
Subproject commit d0c2a0371b476866cb0f7045fba0215425493d62 Subproject commit 256863574bacfb1d2797c2a48cba7a3388cbeb59

View file

@ -102,7 +102,7 @@ pub(crate) fn iced_settings<App: Application>(
iced.default_font = settings.default_font; iced.default_font = settings.default_font;
iced.default_text_size = iced::Pixels(settings.default_text_size); iced.default_text_size = iced::Pixels(settings.default_text_size);
let exit_on_close = settings.exit_on_close; let exit_on_close = settings.exit_on_close;
//iced.is_daemon = false; iced.is_daemon = false;
iced.exit_on_close_request = settings.is_daemon; iced.exit_on_close_request = settings.is_daemon;
let mut window_settings = iced::window::Settings::default(); let mut window_settings = iced::window::Settings::default();
window_settings.exit_on_close_request = exit_on_close; window_settings.exit_on_close_request = exit_on_close;

View file

@ -311,7 +311,7 @@ pub mod settings;
pub mod spin_button; pub mod spin_button;
#[doc(inline)] #[doc(inline)]
pub use spin_button::{spin_button, spin_button_standard, SpinButton}; pub use spin_button::{spin_button, vertical_spin_button, SpinButton};
pub mod tab_bar; pub mod tab_bar;

View file

@ -2,7 +2,7 @@
// SPDX-License-Identifier: MPL-2.0 // SPDX-License-Identifier: MPL-2.0
// Updated by Bryan Hyland <bryan.hyland32@gmail.com> // Updated by Bryan Hyland <bryan.hyland32@gmail.com>
// Updated on: 17Nov24 // Updated on: 18Nov24
//! A control for incremental adjustments of a value. //! A control for incremental adjustments of a value.
@ -89,17 +89,16 @@ pub fn spin_button<'a, T, M>(
value: T, value: T,
min: T, min: T,
max: T, max: T,
orientation: Option<Orientation>,
on_press: impl Fn(T) -> M + 'static, on_press: impl Fn(T) -> M + 'static,
) -> SpinButton<'a, T, M> ) -> SpinButton<'a, T, M>
where where
T: Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Display + Copy T: Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Display + Copy
{ {
SpinButton::new(label, step, value, min, max, orientation, on_press) SpinButton::new(label, step, value, min, max, None, on_press)
} }
/// Shorthand to create a standard (horizontal) spin button widget /// Shorthand to create a standard (horizontal) spin button widget
pub fn spin_button_standard<'a, T, M>( pub fn vertical_spin_button<'a, T, M>(
label: impl Into<String>, label: impl Into<String>,
step: T, step: T,
value: T, value: T,
@ -110,7 +109,7 @@ pub fn spin_button_standard<'a, T, M>(
where where
T: Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Display + Copy 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, Some(Orientation::Vertical), on_press)
} }
fn increment<T>(step: T, value: T, min: T, max: T) -> T fn increment<T>(step: T, value: T, min: T, max: T) -> T
@ -220,14 +219,14 @@ where
T: Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Display + Copy T: Add<Output = T> + Sub<Output = T> + PartialEq + PartialOrd + Display + Copy
{ {
// Create a text widget that holds the value // Create a text widget that holds the value
let val_text = text(format!("{}", spin_btn.value)).size(14); let val_text = text::title4(format!("{}", spin_btn.value));
// Create a spinner container variable that contains the column with all of // Create a spinner container variable that contains the column with all of
// the combined widgets that make up the widget. // the combined widgets that make up the widget.
let spinner_container = column::with_capacity(3) let spinner_container = column::with_capacity(3)
.push( .push(
// Use a button for the increment functionality // Use a button for the increment functionality
button::icon(icon::from_name("list-add-symbolic")) button::icon(icon::from_name("list-add-symbolic"))
.padding([0, 12]) .padding([5, 0])
.on_press((spin_btn.on_press)(increment::<T>( .on_press((spin_btn.on_press)(increment::<T>(
spin_btn.step, spin_btn.value, spin_btn.min, spin_btn.max, spin_btn.step, spin_btn.value, spin_btn.min, spin_btn.max,
))), ))),
@ -237,7 +236,7 @@ where
.push( .push(
// Use a button for the decrement functionality // Use a button for the decrement functionality
button::icon(icon::from_name("list-remove-symbolic")) button::icon(icon::from_name("list-remove-symbolic"))
.padding([0, 12]) .padding([5, 0])
.on_press((spin_btn.on_press)(decrement::<T>( .on_press((spin_btn.on_press)(decrement::<T>(
spin_btn.step, spin_btn.value, spin_btn.min, spin_btn.max, spin_btn.step, spin_btn.value, spin_btn.min, spin_btn.max,
))), ))),
@ -248,7 +247,7 @@ where
// First Row -> The label/title for the spin button. // First Row -> The label/title for the spin button.
// Second Row -> The spin button container from above. // Second Row -> The spin button container from above.
let content_list = column::with_children(vec![ let content_list = column::with_children(vec![
row::with_capacity(1).push(text(spin_btn.label.clone())).into(), row::with_capacity(1).push(text::title4(spin_btn.label.clone())).into(),
row::with_children(vec![Element::from(spinner_container)]).into(), row::with_children(vec![Element::from(spinner_container)]).into(),
]) ])
.width(75) .width(75)