fix: responsive menu layout

This commit is contained in:
Ashley Wulber 2026-02-22 20:48:11 -05:00
parent 0d37dc69e3
commit 71e2c7c99e
5 changed files with 45 additions and 13 deletions

View file

@ -11,8 +11,9 @@ wayland = ["libcosmic/wayland"]
env_logger = "0.11"
[dependencies.libcosmic]
git = "https://github.com/pop-os/libcosmic"
branch = "iced-rebase"
# git = "https://github.com/pop-os/libcosmic"
# branch = "iced-rebase"
path = "../.."
features = [
"debug",
"winit",

View file

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

View file

@ -95,7 +95,7 @@ where
limits: &layout::Limits,
) -> layout::Node {
let state = tree.state.downcast_mut::<State>();
let unrestricted_size = self.size.unwrap_or_else(|| {
let mut unrestricted_size = self.size.unwrap_or_else(|| {
let node =
self.content
.as_widget_mut()
@ -103,21 +103,45 @@ where
node.size()
});
let max_size = limits.max();
let old_max = state.limits.max();
state.needs_update = (unrestricted_size.width > max_size.width)
^ (state.size.width > old_max.width)
|| (unrestricted_size.height > max_size.height) ^ (state.size.height > old_max.height);
if state.needs_update {
state.limits = *limits;
state.size = unrestricted_size;
}
let cur_unrestricted_size = {
let node =
self.content
.as_widget_mut()
.layout(&mut tree.children[0], renderer, &Limits::NONE);
node.size()
};
let max_size = limits.max();
let old_max = state.limits.max();
state.needs_update = (cur_unrestricted_size.width > max_size.width)
|| (cur_unrestricted_size.width > old_max.width)
|| (cur_unrestricted_size.height > max_size.height)
|| (cur_unrestricted_size.height > old_max.height)
|| ((unrestricted_size.width <= max_size.width)
&& (unrestricted_size.height <= max_size.height)
&& (unrestricted_size.width - cur_unrestricted_size.width > 1.
|| unrestricted_size.height - cur_unrestricted_size.height > 1.));
if unrestricted_size.width < cur_unrestricted_size.width {
state.needs_update = true;
unrestricted_size.width = cur_unrestricted_size.width;
} else if unrestricted_size.height < cur_unrestricted_size.height {
state.needs_update = true;
unrestricted_size.height = cur_unrestricted_size.height;
}
let node = self
.content
.as_widget_mut()
.layout(&mut tree.children[0], renderer, limits);
let size = node.size();
if state.needs_update {
state.limits = *limits;
state.size = unrestricted_size;
}
layout::Node::with_children(size, vec![node])
}

View file

@ -139,6 +139,11 @@ impl<'a, Message> Toggler<'a, Message> {
self
}
pub fn on_toggle_maybe(mut self, on_toggle: Option<impl Fn(bool) -> Message + 'a>) -> Self {
self.on_toggle = on_toggle.map(|t| Box::new(t) as _);
self
}
/// Sets the label of the [`Button`].
pub fn label(mut self, label: impl Into<Option<String>>) -> Self {
self.label = label.into();

View file

@ -263,7 +263,7 @@ impl<'a, Message: 'static + Clone, TopLevelMessage: 'static + Clone>
shell: &mut Shell<'_, Message>,
viewport: &Rectangle,
) {
let status = update(
update(
self.id.clone(),
event.clone(),
layout,