Basic UI work
This commit is contained in:
parent
ba677af0f4
commit
9ed29eab94
6 changed files with 77 additions and 7 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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"
|
||||
|
|
|
|||
|
|
@ -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: >k4::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();
|
||||
}
|
||||
|
|
|
|||
14
applets/cosmic-applet-network/src/task.rs
Normal file
14
applets/cosmic-applet-network/src/task.rs
Normal 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);
|
||||
}
|
||||
3
applets/cosmic-applet-network/src/ui.rs
Normal file
3
applets/cosmic-applet-network/src/ui.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
// SPDX-License-Identifier: LGPL-3.0-or-later
|
||||
|
||||
pub mod toggles;
|
||||
27
applets/cosmic-applet-network/src/ui/toggles.rs
Normal file
27
applets/cosmic-applet-network/src/ui/toggles.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
use gtk4::{prelude::*, Align, Label, Orientation, Separator, Switch};
|
||||
|
||||
pub fn add_toggles(target: >k4::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));
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue