fix: responsive menu layout
This commit is contained in:
parent
0d37dc69e3
commit
71e2c7c99e
5 changed files with 45 additions and 13 deletions
|
|
@ -11,8 +11,9 @@ wayland = ["libcosmic/wayland"]
|
||||||
env_logger = "0.11"
|
env_logger = "0.11"
|
||||||
|
|
||||||
[dependencies.libcosmic]
|
[dependencies.libcosmic]
|
||||||
git = "https://github.com/pop-os/libcosmic"
|
# git = "https://github.com/pop-os/libcosmic"
|
||||||
branch = "iced-rebase"
|
# branch = "iced-rebase"
|
||||||
|
path = "../.."
|
||||||
features = [
|
features = [
|
||||||
"debug",
|
"debug",
|
||||||
"winit",
|
"winit",
|
||||||
|
|
|
||||||
|
|
@ -234,6 +234,7 @@ 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)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -250,6 +251,7 @@ 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))
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ where
|
||||||
limits: &layout::Limits,
|
limits: &layout::Limits,
|
||||||
) -> layout::Node {
|
) -> layout::Node {
|
||||||
let state = tree.state.downcast_mut::<State>();
|
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 =
|
let node =
|
||||||
self.content
|
self.content
|
||||||
.as_widget_mut()
|
.as_widget_mut()
|
||||||
|
|
@ -103,21 +103,45 @@ where
|
||||||
node.size()
|
node.size()
|
||||||
});
|
});
|
||||||
|
|
||||||
let max_size = limits.max();
|
let cur_unrestricted_size = {
|
||||||
let old_max = state.limits.max();
|
let node =
|
||||||
state.needs_update = (unrestricted_size.width > max_size.width)
|
self.content
|
||||||
^ (state.size.width > old_max.width)
|
.as_widget_mut()
|
||||||
|| (unrestricted_size.height > max_size.height) ^ (state.size.height > old_max.height);
|
.layout(&mut tree.children[0], renderer, &Limits::NONE);
|
||||||
if state.needs_update {
|
node.size()
|
||||||
state.limits = *limits;
|
};
|
||||||
state.size = unrestricted_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
|
let node = self
|
||||||
.content
|
.content
|
||||||
.as_widget_mut()
|
.as_widget_mut()
|
||||||
.layout(&mut tree.children[0], renderer, limits);
|
.layout(&mut tree.children[0], renderer, limits);
|
||||||
let size = node.size();
|
let size = node.size();
|
||||||
|
|
||||||
|
if state.needs_update {
|
||||||
|
state.limits = *limits;
|
||||||
|
state.size = unrestricted_size;
|
||||||
|
}
|
||||||
|
|
||||||
layout::Node::with_children(size, vec![node])
|
layout::Node::with_children(size, vec![node])
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -139,6 +139,11 @@ impl<'a, Message> Toggler<'a, Message> {
|
||||||
self
|
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`].
|
/// Sets the label of the [`Button`].
|
||||||
pub fn label(mut self, label: impl Into<Option<String>>) -> Self {
|
pub fn label(mut self, label: impl Into<Option<String>>) -> Self {
|
||||||
self.label = label.into();
|
self.label = label.into();
|
||||||
|
|
|
||||||
|
|
@ -263,7 +263,7 @@ impl<'a, Message: 'static + Clone, TopLevelMessage: 'static + Clone>
|
||||||
shell: &mut Shell<'_, Message>,
|
shell: &mut Shell<'_, Message>,
|
||||||
viewport: &Rectangle,
|
viewport: &Rectangle,
|
||||||
) {
|
) {
|
||||||
let status = update(
|
update(
|
||||||
self.id.clone(),
|
self.id.clone(),
|
||||||
event.clone(),
|
event.clone(),
|
||||||
layout,
|
layout,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue