Basic UI work

This commit is contained in:
Lucy 2022-02-01 16:46:25 -05:00
parent ba677af0f4
commit 9ed29eab94
No known key found for this signature in database
GPG key ID: EBC517FAD666BBF1
6 changed files with 77 additions and 7 deletions

5
Cargo.lock generated
View file

@ -183,9 +183,9 @@ checksum = "22a9137b95ea06864e018375b72adfb7db6e6f68cfc8df5a04d00288050485ee"
[[package]]
name = "cfg-expr"
version = "0.9.0"
version = "0.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "edae0b9625d1fce32f7d64b71784d9b1bf8469ec1a9c417e44aaf16a9cbd7571"
checksum = "3431df59f28accaf4cb4eed4a9acc66bea3f3c3753aa6cdc2f024174ef232af7"
dependencies = [
"smallvec",
]
@ -224,6 +224,7 @@ version = "0.1.0"
dependencies = [
"cosmic-dbus-networkmanager",
"gtk4",
"once_cell",
"relm4-macros",
"tokio",
"zbus",

View file

@ -7,6 +7,7 @@ license = "LGPL-3.0-or-later"
[dependencies]
cosmic-dbus-networkmanager = { git = "https://github.com/pop-os/dbus-settings-bindings" }
gtk4 = "0.4.6"
once_cell = "1.9.0"
relm4-macros = "0.4.1"
tokio = { version = "1.15.0", features = ["full"] }
zbus = "2.0.1"

View file

@ -1,7 +1,16 @@
use gtk4::{
gdk::Display, gio::ApplicationFlags, prelude::*, CssProvider, StyleContext,
STYLE_PROVIDER_PRIORITY_APPLICATION,
};
// SPDX-License-Identifier: LGPL-3.0-or-later
#[macro_use]
extern crate relm4_macros;
pub mod task;
pub mod ui;
use gtk4::{gio::ApplicationFlags, prelude::*, Orientation};
use once_cell::sync::Lazy;
use tokio::runtime::Runtime;
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("failed to build tokio runtime"));
fn main() {
let application = gtk4::Application::new(
@ -17,6 +26,21 @@ fn build_ui(application: &gtk4::Application) {
.application(application)
.title("COSMIC Network Applet")
.default_width(400)
.default_height(600)
.default_height(300)
.build();
view! {
main_box = gtk4::Box {
set_orientation: Orientation::Vertical,
set_spacing: 20,
set_margin_top: 20,
set_margin_bottom: 20,
set_margin_start: 24,
set_margin_end: 24
}
}
ui::toggles::add_toggles(&main_box);
window.set_child(Some(&main_box));
window.show();
}

View file

@ -0,0 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
use std::future::Future;
pub fn spawn<O, F>(future: F) -> tokio::task::JoinHandle<O>
where
F: Future<Output = O> + Send + 'static,
O: Send + 'static,
{
crate::RT.spawn(future)
}
pub fn spawn_local<F: Future<Output = ()> + 'static>(future: F) {
gtk4::glib::MainContext::default().spawn_local(future);
}

View file

@ -0,0 +1,3 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
pub mod toggles;

View file

@ -0,0 +1,27 @@
use gtk4::{prelude::*, Align, Label, Orientation, Separator, Switch};
pub fn add_toggles(target: &gtk4::Box) {
view! {
airplane_mode_box = gtk4::Box {
append: airplane_mode_label = &Label {
set_markup: "<b>Airplane Mode</b>",
set_halign: Align::Start
},
append: airplane_mode_switch = &Switch {}
}
}
view! {
wifi_box = gtk4::Box {
append: wifi_label = &Label {
set_markup: "<b>WiFi</b>",
set_halign: Align::Start
},
append: wifi_switch = &Switch {}
}
}
target.append(&airplane_mode_box);
target.append(&Separator::new(Orientation::Horizontal));
target.append(&wifi_box);
target.append(&Separator::new(Orientation::Horizontal));
}