fix: toggler width fixes & cleanup

This commit is contained in:
Ashley Wulber 2026-02-25 11:10:34 -05:00
parent dd02296f99
commit a501fcab34
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
6 changed files with 12 additions and 9 deletions

View file

@ -128,8 +128,7 @@ impl cosmic::Application for Window {
"Example row", "Example row",
cosmic::widget::container( cosmic::widget::container(
toggler(state.example_row) toggler(state.example_row)
.on_toggle(Message::ToggleExampleRow) .on_toggle(Message::ToggleExampleRow),
.width(Length::Fill),
), ),
)) ))
.add(popup_dropdown( .add(popup_dropdown(

View file

@ -234,7 +234,6 @@ impl Context {
}) })
.width(Length::Fixed(suggested.0 as f32)) .width(Length::Fixed(suggested.0 as f32))
.height(Length::Fixed(suggested.1 as f32)); .height(Length::Fixed(suggested.1 as f32));
dbg!(suggested);
self.button_from_element(icon, symbolic) self.button_from_element(icon, symbolic)
} }
@ -251,7 +250,6 @@ impl Context {
(applet_padding_minor_axis, applet_padding_major_axis) (applet_padding_minor_axis, applet_padding_major_axis)
}; };
dbg!(suggested.0 + 2 * horizontal_padding);
crate::widget::button::custom(layer_container(content).center(Length::Fill)) crate::widget::button::custom(layer_container(content).center(Length::Fill))
.width(Length::Fixed((suggested.0 + 2 * horizontal_padding) as f32)) .width(Length::Fixed((suggested.0 + 2 * horizontal_padding) as f32))
.height(Length::Fixed((suggested.1 + 2 * vertical_padding) as f32)) .height(Length::Fixed((suggested.1 + 2 * vertical_padding) as f32))

View file

@ -85,7 +85,7 @@ impl<Message: Clone + 'static> ContextMenu<'_, Message> {
// close existing popups // close existing popups
state.menu_states.clear(); state.menu_states.clear();
state.active_root.clear(); state.active_root.clear();
dbg!("closing existing popups");
shell.publish(self.on_surface_action.as_ref().unwrap()(destroy_popup(id))); shell.publish(self.on_surface_action.as_ref().unwrap()(destroy_popup(id)));
state.view_cursor = view_cursor; state.view_cursor = view_cursor;
( (

View file

@ -350,7 +350,7 @@ pub use toaster::{Toast, ToastId, Toasts, toaster};
mod toggler; mod toggler;
#[doc(inline)] #[doc(inline)]
pub use toggler::toggler; pub use toggler::{Toggler, toggler};
#[doc(inline)] #[doc(inline)]
pub use tooltip::{Tooltip, tooltip}; pub use tooltip::{Tooltip, tooltip};

View file

@ -41,6 +41,7 @@ pub fn item_row<Message>(children: Vec<Element<Message>>) -> Row<Message> {
row::with_children(children) row::with_children(children)
.spacing(theme::spacing().space_xs) .spacing(theme::spacing().space_xs)
.align_y(iced::Alignment::Center) .align_y(iced::Alignment::Center)
.width(Length::Fill)
} }
/// A settings item aligned in a flex row /// A settings item aligned in a flex row
@ -59,8 +60,9 @@ pub fn flex_item<'a, Message: 'static>(
.wrapping(Wrapping::Word) .wrapping(Wrapping::Word)
.width(Length::Fill) .width(Length::Fill)
.into(), .into(),
container(widget).into(), container(widget).width(Length::Shrink).into(),
]) ])
.width(Length::Fill)
} }
inner(title.into(), widget.into()) inner(title.into(), widget.into())
@ -141,6 +143,10 @@ impl<'a, Message: 'static> Item<'a, Message> {
is_checked: bool, is_checked: bool,
message: impl Fn(bool) -> Message + 'static, message: impl Fn(bool) -> Message + 'static,
) -> Row<'a, Message> { ) -> Row<'a, Message> {
self.control(crate::widget::toggler(is_checked).on_toggle(message)) self.control(
crate::widget::toggler(is_checked)
.width(Length::Shrink)
.on_toggle(message),
)
} }
} }

View file

@ -55,7 +55,7 @@ impl<'a, Message> Toggler<'a, Message> {
is_toggled, is_toggled,
on_toggle: None, on_toggle: None,
label: None, label: None,
width: Length::Fill, width: Length::Shrink,
size: Self::DEFAULT_SIZE, size: Self::DEFAULT_SIZE,
text_size: None, text_size: None,
text_line_height: text::LineHeight::default(), text_line_height: text::LineHeight::default(),