refactor: use icon button and popup
This commit is contained in:
parent
6b56500a52
commit
045f3976a5
3 changed files with 51 additions and 11 deletions
|
|
@ -7,9 +7,10 @@ pub mod task;
|
|||
pub mod ui;
|
||||
pub mod widgets;
|
||||
|
||||
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"));
|
||||
|
||||
|
|
@ -26,8 +27,9 @@ fn build_ui(application: >k4::Application) {
|
|||
let window = gtk4::ApplicationWindow::builder()
|
||||
.application(application)
|
||||
.title("COSMIC Network Applet")
|
||||
.default_width(400)
|
||||
.default_height(300)
|
||||
.default_width(1)
|
||||
.default_height(1)
|
||||
.decorated(false)
|
||||
.build();
|
||||
|
||||
view! {
|
||||
|
|
@ -40,14 +42,44 @@ fn build_ui(application: >k4::Application) {
|
|||
set_margin_end: 24
|
||||
}
|
||||
}
|
||||
ui::current_networks::add_current_networks(&main_box);
|
||||
|
||||
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
|
||||
let image = gtk4::Image::from_icon_name("preferences-system-network");
|
||||
image.add_css_class("panel_icon");
|
||||
image.set_pixel_size(config.get_applet_icon_size().try_into().unwrap());
|
||||
button.set_child(Some(&image));
|
||||
|
||||
view! {
|
||||
icon_box = gtk4::Box {
|
||||
set_orientation: Orientation::Vertical,
|
||||
set_spacing: 0,
|
||||
}
|
||||
}
|
||||
|
||||
popover.set_child(Some(&main_box));
|
||||
|
||||
icon_box.append(&button);
|
||||
icon_box.append(&popover);
|
||||
|
||||
ui::current_networks::add_current_networks(&main_box, &image);
|
||||
main_box.append(&Separator::new(Orientation::Horizontal));
|
||||
ui::toggles::add_toggles(&main_box);
|
||||
let available_wifi_separator = Separator::new(Orientation::Horizontal);
|
||||
main_box.append(&available_wifi_separator);
|
||||
available_wifi_separator.hide();
|
||||
ui::available_wifi::add_available_wifi(&main_box, available_wifi_separator);
|
||||
window.set_child(Some(&main_box));
|
||||
|
||||
window.set_child(Some(&icon_box));
|
||||
window.show();
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue