refactor: power applet popover and icon button~

This commit is contained in:
Ashley Wulber 2022-05-26 12:52:34 -04:00
parent d6b7b9fcd1
commit 1958341a72
2 changed files with 35 additions and 5 deletions

View file

@ -13,3 +13,4 @@ once_cell = "1.9.0"
relm4-macros = "0.4.1"
tokio = { version = "1.15.0", features = ["full"] }
zbus = "2.0.1"
cosmic-panel-config = {git = "https://github.com/pop-os/cosmic-panel", features = ["gtk4"]}

View file

@ -6,9 +6,10 @@ extern crate relm4_macros;
pub mod session_manager;
pub mod ui;
use gtk4::{gio::ApplicationFlags, prelude::*, Orientation, Separator};
use gtk4::{glib, gio::ApplicationFlags, prelude::*, Orientation, Separator};
use once_cell::sync::Lazy;
use tokio::runtime::Runtime;
use cosmic_panel_config::config::CosmicPanelConfig;
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
@ -25,10 +26,36 @@ fn build_ui(application: &gtk4::Application) {
let window = gtk4::ApplicationWindow::builder()
.application(application)
.title("COSMIC Power Applet")
.default_width(400)
.default_height(300)
.default_width(1)
.default_height(1)
.decorated(false)
.build();
let config = CosmicPanelConfig::load_from_env().unwrap_or_default();
let popover = gtk4::builders::PopoverBuilder::new()
.autohide(true)
.has_arrow(false)
.build();
let button = gtk4::Button::new();
button.add_css_class("panel_icon");
button.connect_clicked(glib::clone!(@weak popover => move |_| {
popover.show();
}));
// TODO cleanup
// TODO adjust battery icon based on charge
let image = gtk4::Image::from_icon_name("battery-full-symbolic");
image.add_css_class("panel_icon");
image.set_pixel_size(config.get_applet_icon_size().try_into().unwrap());
view! {
icon_box = gtk4::Box {
set_orientation: Orientation::Vertical,
set_spacing: 0,
}
}
button.set_child(Some(&image));
let session_section = ui::session::build();
let system_section = ui::system::build();
view! {
@ -39,13 +66,15 @@ fn build_ui(application: &gtk4::Application) {
set_margin_bottom: 20,
set_margin_start: 24,
set_margin_end: 24,
append: first_separator = &Separator {},
append: &session_section,
append: second_separator = &Separator {},
append: &system_section
}
}
window.set_child(Some(&main_box));
popover.set_child(Some(&main_box));
icon_box.append(&button);
icon_box.append(&popover);
window.set_child(Some(&icon_box));
window.show();
}