fix: better button sizing so there are no gaps

This commit is contained in:
Ashley Wulber 2024-03-28 19:10:59 -04:00 committed by Ashley Wulber
parent a18d64add7
commit 71cb9e64ec
3 changed files with 116 additions and 74 deletions

View file

@ -1,4 +1,7 @@
use cosmic::iced_widget::text;
use cosmic::applet::cosmic_panel_config::PanelAnchor;
use cosmic::iced::Length;
use cosmic::iced_widget::{row, text};
use cosmic::widget::vertical_space;
use cosmic::{app, iced, iced_style::application, theme::Theme};
use freedesktop_desktop_entry::DesktopEntry;
use std::{env, fs, process::Command};
@ -52,10 +55,29 @@ impl cosmic::Application for Button {
}
fn view(&self) -> cosmic::Element<Msg> {
cosmic::widget::button(text(&self.desktop.name).size(14.0))
.style(cosmic::theme::Button::AppletIcon)
.on_press(Msg::Press)
.into()
if matches!(
self.core.applet.anchor,
PanelAnchor::Left | PanelAnchor::Right
) && self.desktop.icon.is_some()
{
self.core
.applet
.icon_button(self.desktop.icon.as_ref().unwrap())
} else {
let content = row!(
text(&self.desktop.name).size(14.0),
vertical_space(Length::Fixed(
(self.core.applet.suggested_size().1 + 2 * self.core.applet.suggested_padding())
as f32
))
)
.align_items(iced::Alignment::Center);
cosmic::widget::button(content)
.padding([0, self.core.applet.suggested_padding()])
.style(cosmic::theme::Button::AppletIcon)
}
.on_press(Msg::Press)
.into()
}
}