status-area: Factor out duplicated icon button code to function
This commit is contained in:
parent
9b979ccf74
commit
080f07e0b4
1 changed files with 17 additions and 19 deletions
|
|
@ -95,14 +95,7 @@ impl App {
|
|||
let overflow_index = self.overflow_index().unwrap_or(0);
|
||||
let children = self.menus.iter().skip(overflow_index).map(|(id, menu)| {
|
||||
mouse_area(
|
||||
match menu.icon_pixmap() {
|
||||
Some(icon) if menu.icon_name() == "" => self
|
||||
.core
|
||||
.applet
|
||||
.icon_button_from_handle(icon.clone().symbolic(true)),
|
||||
_ => self.core.applet.icon_button(menu.icon_name()),
|
||||
}
|
||||
.on_press_down(Msg::TogglePopup(*id)),
|
||||
menu_icon_button(&self.core.applet, &menu).on_press_down(Msg::TogglePopup(*id)),
|
||||
)
|
||||
.on_enter(Msg::Hovered(*id))
|
||||
.into()
|
||||
|
|
@ -452,20 +445,13 @@ impl cosmic::Application for App {
|
|||
.iter()
|
||||
.take(overflow_index.unwrap_or(self.menus.len()))
|
||||
.map(|(id, menu)| {
|
||||
mouse_area(
|
||||
match menu.icon_pixmap() {
|
||||
Some(icon) if menu.icon_name() == "" => self
|
||||
.core
|
||||
.applet
|
||||
.icon_button_from_handle(icon.clone().symbolic(true)),
|
||||
_ => self.core.applet.icon_button(menu.icon_name()),
|
||||
}
|
||||
.on_press_down(if menu.item.menu_proxy().is_some() {
|
||||
mouse_area(menu_icon_button(&self.core.applet, &menu).on_press_down(
|
||||
if menu.item.menu_proxy().is_some() {
|
||||
Msg::TogglePopup(*id)
|
||||
} else {
|
||||
Msg::StatusMenu((*id, status_menu::Msg::Click(0, true)))
|
||||
}),
|
||||
)
|
||||
},
|
||||
))
|
||||
.on_enter(Msg::Hovered(*id))
|
||||
.into()
|
||||
});
|
||||
|
|
@ -534,6 +520,18 @@ impl cosmic::Application for App {
|
|||
}
|
||||
}
|
||||
|
||||
fn menu_icon_button<'a>(
|
||||
applet: &'a cosmic::applet::Context,
|
||||
menu: &'a status_menu::State,
|
||||
) -> cosmic::widget::Button<'a, Msg> {
|
||||
match menu.icon_pixmap() {
|
||||
Some(icon) if menu.icon_name() == "" => {
|
||||
applet.icon_button_from_handle(icon.clone().symbolic(true))
|
||||
}
|
||||
_ => applet.icon_button(menu.icon_name()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
cosmic::applet::run::<App>(())
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue