feat: config changes

This commit is contained in:
Ashley Wulber 2022-07-27 00:37:00 -04:00
parent e24ef3fbbd
commit e87d101217
No known key found for this signature in database
GPG key ID: 5216D4F46A90A820
12 changed files with 129 additions and 159 deletions

View file

@ -1,4 +1,4 @@
use cosmic_panel_config::CosmicPanelConfig;
use cosmic_panel_config::{CosmicPanelConfig, PanelSize};
use gtk4::{glib, prelude::*, subclass::prelude::*};
use relm4_macros::view;
@ -52,8 +52,6 @@ impl ObjectImpl for AppletButtonInner {
self.menu_button.set(menu_button);
self.popover.set(popover);
self.panel_config
.set(CosmicPanelConfig::load_from_env().unwrap_or_default());
}
fn dispose(&self, _obj: &AppletButton) {
@ -96,23 +94,23 @@ impl AppletButton {
AppletButtonInner::from_instance(self)
}
// TODO: avoid multiple instances?
pub fn panel_config(&self) -> &CosmicPanelConfig {
&*self.inner().panel_config
}
pub fn set_button_child(&self, child: Option<&impl IsA<gtk4::Widget>>) {
self.inner().menu_button.set_child(child);
}
pub fn set_button_icon_name(&self, name: &str) {
let image = gtk4::Image::from_icon_name(name);
let pixels = std::env::var("COSMIC_PANEL_SIZE").ok().and_then(|size| match size.parse::<PanelSize>() {
Ok(PanelSize::XL) => Some(64),
Ok(PanelSize::L) => Some(48),
Ok(PanelSize::M) => Some(36),
Ok(PanelSize::S) => Some(24),
Ok(PanelSize::XS) => Some(18),
Err(_) => Some(36),
}).unwrap_or(36);
image.set_pixel_size(
self.panel_config()
.get_applet_icon_size()
.try_into()
.unwrap(),
); // XXX unwrap
pixels
);
self.set_button_child(Some(&image));
}