Trying different strategies for non-blocking UI

This commit is contained in:
Luke D. Jones
2024-02-25 23:21:11 +13:00
parent 91b1456d06
commit 7b0f037cba
5 changed files with 301 additions and 183 deletions

106
Cargo.lock generated
View File

@@ -128,7 +128,7 @@ dependencies = [
"asusd", "asusd",
"cargo-husky", "cargo-husky",
"dmi_id", "dmi_id",
"gif", "gif 0.12.0",
"glam", "glam",
"gumdrop", "gumdrop",
"rog_anime", "rog_anime",
@@ -682,9 +682,9 @@ checksum = "7b02b629252fe8ef6460461409564e2c21d0c8e77e0944f3d189ff06c4e932ad"
[[package]] [[package]]
name = "cc" name = "cc"
version = "1.0.86" version = "1.0.87"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f9fa1897e4325be0d68d48df6aa1a71ac2ed4d27723887e7754192705350730" checksum = "3286b845d0fccbdd15af433f61c5970e711987036cb468f437ff6badd70f4e24"
dependencies = [ dependencies = [
"libc", "libc",
] ]
@@ -879,7 +879,7 @@ dependencies = [
[[package]] [[package]]
name = "const-field-offset" name = "const-field-offset"
version = "0.1.4" version = "0.1.4"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"const-field-offset-macro", "const-field-offset-macro",
"field-offset", "field-offset",
@@ -888,7 +888,7 @@ dependencies = [
[[package]] [[package]]
name = "const-field-offset-macro" name = "const-field-offset-macro"
version = "0.1.4" version = "0.1.4"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -1835,6 +1835,16 @@ dependencies = [
"weezl", "weezl",
] ]
[[package]]
name = "gif"
version = "0.13.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3fb2d69b19215e18bb912fa30f7ce15846e301408695e44e0ef719f1da9e19f2"
dependencies = [
"color_quant",
"weezl",
]
[[package]] [[package]]
name = "gimli" name = "gimli"
version = "0.28.1" version = "0.28.1"
@@ -2134,9 +2144,9 @@ checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8"
[[package]] [[package]]
name = "hermit-abi" name = "hermit-abi"
version = "0.3.6" version = "0.3.8"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd5256b483761cd23699d0da46cc6fd2ee3be420bbe6d020ae4a091e70b7e9fd" checksum = "379dada1584ad501b383485dd706b8afb7a70fcbc7f4da7d780638a5a6124a60"
[[package]] [[package]]
name = "hex" name = "hex"
@@ -2162,7 +2172,7 @@ checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]] [[package]]
name = "i-slint-backend-linuxkms" name = "i-slint-backend-linuxkms"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"calloop", "calloop",
"drm", "drm",
@@ -2181,7 +2191,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-backend-qt" name = "i-slint-backend-qt"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"const-field-offset", "const-field-offset",
"i-slint-common", "i-slint-common",
@@ -2193,7 +2203,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-backend-selector" name = "i-slint-backend-selector"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"i-slint-backend-linuxkms", "i-slint-backend-linuxkms",
@@ -2206,7 +2216,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-backend-winit" name = "i-slint-backend-winit"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cfg-if", "cfg-if",
@@ -2240,7 +2250,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-common" name = "i-slint-common"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"derive_more", "derive_more",
@@ -2251,7 +2261,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-compiler" name = "i-slint-compiler"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"by_address", "by_address",
"codemap", "codemap",
@@ -2280,7 +2290,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-core" name = "i-slint-core"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"auto_enums", "auto_enums",
"bytemuck", "bytemuck",
@@ -2323,7 +2333,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-core-macros" name = "i-slint-core-macros"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"quote", "quote",
"syn 2.0.50", "syn 2.0.50",
@@ -2332,7 +2342,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-renderer-femtovg" name = "i-slint-renderer-femtovg"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"cfg-if", "cfg-if",
"const-field-offset", "const-field-offset",
@@ -2364,7 +2374,7 @@ dependencies = [
[[package]] [[package]]
name = "i-slint-renderer-skia" name = "i-slint-renderer-skia"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"cfg-if", "cfg-if",
@@ -2440,15 +2450,15 @@ dependencies = [
[[package]] [[package]]
name = "image" name = "image"
version = "0.24.8" version = "0.24.9"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "034bbe799d1909622a74d1193aa50147769440040ff36cb2baa947609b0a4e23" checksum = "5690139d2f55868e080017335e4b94cb7414274c74f1669c84fb5feba2c9f69d"
dependencies = [ dependencies = [
"bytemuck", "bytemuck",
"byteorder", "byteorder",
"color_quant", "color_quant",
"exr", "exr",
"gif", "gif 0.13.1",
"jpeg-decoder", "jpeg-decoder",
"num-traits", "num-traits",
"png", "png",
@@ -2848,9 +2858,9 @@ dependencies = [
[[package]] [[package]]
name = "lru" name = "lru"
version = "0.12.2" version = "0.12.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db2c024b41519440580066ba82aab04092b333e09066a5eb86c7c4890df31f22" checksum = "d3262e75e648fce39813cb56ac41f3c3e3f65217ebf3844d818d1f9398cfb0dc"
[[package]] [[package]]
name = "lyon_algorithms" name = "lyon_algorithms"
@@ -3132,7 +3142,7 @@ version = "0.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b" checksum = "681030a937600a36906c185595136d26abfebb4aa9c65701cefcaf8578bb982b"
dependencies = [ dependencies = [
"proc-macro-crate 1.3.1", "proc-macro-crate 3.1.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 2.0.50", "syn 2.0.50",
@@ -3459,6 +3469,15 @@ dependencies = [
"toml_edit 0.20.7", "toml_edit 0.20.7",
] ]
[[package]]
name = "proc-macro-crate"
version = "3.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6d37c51ca738a55da99dc0c4a34860fd675453b8b36209178c2249bb13651284"
dependencies = [
"toml_edit 0.21.1",
]
[[package]] [[package]]
name = "proc-macro-error" name = "proc-macro-error"
version = "1.0.4" version = "1.0.4"
@@ -3714,7 +3733,7 @@ version = "5.0.8"
dependencies = [ dependencies = [
"cargo-husky", "cargo-husky",
"dmi_id", "dmi_id",
"gif", "gif 0.12.0",
"glam", "glam",
"log", "log",
"pix", "pix",
@@ -4151,7 +4170,7 @@ dependencies = [
[[package]] [[package]]
name = "slint" name = "slint"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"const-field-offset", "const-field-offset",
"i-slint-backend-selector", "i-slint-backend-selector",
@@ -4167,7 +4186,7 @@ dependencies = [
[[package]] [[package]]
name = "slint-build" name = "slint-build"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"i-slint-compiler", "i-slint-compiler",
"spin_on", "spin_on",
@@ -4178,7 +4197,7 @@ dependencies = [
[[package]] [[package]]
name = "slint-macros" name = "slint-macros"
version = "1.5.0" version = "1.5.0"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"i-slint-compiler", "i-slint-compiler",
"proc-macro2", "proc-macro2",
@@ -4275,12 +4294,12 @@ dependencies = [
[[package]] [[package]]
name = "socket2" name = "socket2"
version = "0.5.5" version = "0.5.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7b5fac59a5cb5dd637972e5fca70daf0523c9067fcdc4842f053dae04a18f8e9" checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871"
dependencies = [ dependencies = [
"libc", "libc",
"windows-sys 0.48.0", "windows-sys 0.52.0",
] ]
[[package]] [[package]]
@@ -4621,7 +4640,7 @@ dependencies = [
"mio", "mio",
"num_cpus", "num_cpus",
"pin-project-lite", "pin-project-lite",
"socket2 0.5.5", "socket2 0.5.6",
"tokio-macros", "tokio-macros",
"windows-sys 0.48.0", "windows-sys 0.48.0",
] ]
@@ -4689,6 +4708,17 @@ dependencies = [
"winnow 0.5.40", "winnow 0.5.40",
] ]
[[package]]
name = "toml_edit"
version = "0.21.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8534fd7f78b5405e860340ad6575217ce99f38d4d5c8f2442cb5ecb50090e1"
dependencies = [
"indexmap",
"toml_datetime",
"winnow 0.5.40",
]
[[package]] [[package]]
name = "toml_edit" name = "toml_edit"
version = "0.22.6" version = "0.22.6"
@@ -4965,7 +4995,7 @@ dependencies = [
[[package]] [[package]]
name = "vtable" name = "vtable"
version = "0.1.11" version = "0.1.11"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"const-field-offset", "const-field-offset",
"portable-atomic", "portable-atomic",
@@ -4976,7 +5006,7 @@ dependencies = [
[[package]] [[package]]
name = "vtable-macro" name = "vtable-macro"
version = "0.1.10" version = "0.1.10"
source = "git+https://github.com/slint-ui/slint.git#fa2cf8c28aec3d15e8ba542cb603ef188e01ee94" source = "git+https://github.com/flukejones/sixtyfps.git#f63c4e3b8510e88a8496328a47e8a8dccdb1bcf3"
dependencies = [ dependencies = [
"proc-macro2", "proc-macro2",
"quote", "quote",
@@ -5812,9 +5842,9 @@ dependencies = [
[[package]] [[package]]
name = "zvariant" name = "zvariant"
version = "4.0.0" version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e09e8be97d44eeab994d752f341e67b3b0d80512a8b315a0671d47232ef1b65" checksum = "a660524eaa9f4a65c673006b034d2167a9a3ef821e9bd7311b2f1c77b904e312"
dependencies = [ dependencies = [
"endi", "endi",
"enumflags2", "enumflags2",
@@ -5825,11 +5855,11 @@ dependencies = [
[[package]] [[package]]
name = "zvariant_derive" name = "zvariant_derive"
version = "4.0.0" version = "4.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "72a5857e2856435331636a9fbb415b09243df4521a267c5bedcd5289b4d5799e" checksum = "55b1565fbb82205a83de0bd1293fb2b5c9e34d4e74250fd4aed54903545b1fa2"
dependencies = [ dependencies = [
"proc-macro-crate 1.3.1", "proc-macro-crate 3.1.0",
"proc-macro2", "proc-macro2",
"quote", "quote",
"syn 1.0.109", "syn 1.0.109",

View File

@@ -42,18 +42,18 @@ versions.workspace = true
nix = "^0.26.1" nix = "^0.26.1"
tempfile = "3.3.0" tempfile = "3.3.0"
i-slint-backend-selector = { git = "https://github.com/slint-ui/slint.git" } i-slint-backend-selector = { git = "https://github.com/flukejones/sixtyfps.git" }
i-slint-core = { git = "https://github.com/slint-ui/slint.git" } i-slint-core = { git = "https://github.com/flukejones/sixtyfps.git" }
i-slint-backend-winit = { git = "https://github.com/slint-ui/slint.git" } i-slint-backend-winit = { git = "https://github.com/flukejones/sixtyfps.git" }
winit = "*" winit = "*"
[dependencies.slint] [dependencies.slint]
git = "https://github.com/slint-ui/slint.git" git = "https://github.com/flukejones/sixtyfps.git"
default-features = false default-features = false
features = ["std", "compat-1-0", "backend-winit-wayland", "backend-linuxkms", "renderer-femtovg"] features = ["std", "compat-1-0", "backend-winit-wayland", "backend-linuxkms", "renderer-femtovg"]
[build-dependencies.slint-build] [build-dependencies.slint-build]
git = "https://github.com/slint-ui/slint.git" git = "https://github.com/flukejones/sixtyfps.git"
[dev-dependencies] [dev-dependencies]
cargo-husky.workspace = true cargo-husky.workspace = true

View File

@@ -19,6 +19,7 @@ use rog_control_center::{
get_ipc_file, on_tmp_dir_exists, print_versions, AvailableSystemProperties, MainWindow, get_ipc_file, on_tmp_dir_exists, print_versions, AvailableSystemProperties, MainWindow,
RogDbusClientBlocking, SystemPage, QUIT_APP, SHOWING_GUI, SHOW_GUI, RogDbusClientBlocking, SystemPage, QUIT_APP, SHOWING_GUI, SHOW_GUI,
}; };
use rog_dbus::zbus_platform::{PlatformProxy, PlatformProxyBlocking};
use tokio::runtime::Runtime; use tokio::runtime::Runtime;
// use winit::monitor::VideoMode; // use winit::monitor::VideoMode;
// use winit::window::{Fullscreen, WindowLevel}; // use winit::window::{Fullscreen, WindowLevel};
@@ -176,37 +177,77 @@ fn setup_window(_states: Arc<Mutex<SystemState>>) -> MainWindow {
// slint::platform::set_platform(Box::new(i_slint_backend_winit::Backend::new(). // slint::platform::set_platform(Box::new(i_slint_backend_winit::Backend::new().
// unwrap())).unwrap(); // unwrap())).unwrap();
let ui = MainWindow::new().unwrap(); let ui = MainWindow::new().unwrap();
// Example of how to do work in another thread.
// The thread itself can keep its own state, and then update vars in the UI let handle = ui.as_weak();
// when required. ui.global::<SystemPage>().on_cancelled(move || {
let ui_handle = ui.as_weak(); handle.upgrade_in_event_loop(|_handle| {}).ok();
spawn(move || loop {
sleep(Duration::from_secs(1));
// This is where the actual update happens
ui_handle
.upgrade_in_event_loop(move |handle| {
// handle.set_counter(handle.get_counter() + 1);
use i_slint_backend_winit::WinitWindowAccessor;
handle
.window()
.with_winit_window(|winit_window: &winit::window::Window| {
// winit_window.set_fullscreen(Some(Fullscreen::Borderless(None)));
if !winit_window.has_focus() {
// slint::quit_event_loop().unwrap();
// handle.hide().unwrap();
}
});
})
.ok();
}); });
ui.global::<SystemPage>().on_set_charge(|v1, v2| { // TODO: macro
if v1 != v2 { let conn = zbus::blocking::Connection::system().unwrap();
dbg!(v1); let proxy = PlatformProxyBlocking::new(&conn).unwrap();
dbg!(v2); let proxy2 = proxy.clone();
} ui.global::<SystemPage>().on_set_charge_limit(move |limit| {
dbg!(limit);
proxy.set_charge_control_end_threshold(limit as u8).unwrap();
}); });
ui.global::<SystemPage>().on_set_panel_od(move |od| {
dbg!(od);
proxy2.set_panel_od(od).unwrap();
});
// let handle = ui.as_weak();
// ui.global::<SystemPage>().on_applied(move || {
// handle
// .upgrade_in_event_loop(|handle| {
// let data = handle.global::<SystemPage>();
// let charge_changed = data.get_charge_limit() as i32 !=
// data.get_last_charge_limit(); let charge =
// data.get_charge_limit() as u8; tokio::spawn(async move {
// let conn = zbus::Connection::system().await.unwrap();
// let proxy = PlatformProxy::new(&conn).await.unwrap();
// if charge_changed {
// proxy
// .set_charge_control_end_threshold(charge)
// .await
// .unwrap();
// }
// });
// })
// .ok();
// });
// or
// let handle = ui.as_weak();
// tokio::spawn(async move {
// // TODO: macro
// let conn = zbus::Connection::system().await.unwrap();
// let proxy = PlatformProxy::new(&conn).await.unwrap();
// let proxy2 = proxy.clone();
// handle.upgrade_in_event_loop(move |handle| {
// handle
// .global::<SystemPage>()
// .on_set_charge_limit(move |limit| {
// let proxy = proxy.clone();
// tokio::spawn(async move {
// dbg!(limit);
// proxy
// .set_charge_control_end_threshold(limit as u8)
// .await
// .unwrap();
// });
// });
// handle.global::<SystemPage>().on_set_panel_od(move |od| {
// let proxy2 = proxy2.clone();
// tokio::spawn(async move {
// dbg!(od);
// proxy2.set_panel_od(od).await.unwrap();
// });
// });
// }).ok();
// });
let props = AvailableSystemProperties { let props = AvailableSystemProperties {
ac_command: true, ac_command: true,
bat_command: true, bat_command: true,

View File

@@ -2,8 +2,6 @@ import { VerticalBox , StandardButton, Button} from "std-widgets.slint";
import { Theme } from "globals.slint"; import { Theme } from "globals.slint";
export component SquareImageButton inherits Rectangle { export component SquareImageButton inherits Rectangle {
// if (AppConsts.sdfsdf.length < 0): Rectangle { background: red; }
callback clicked; callback clicked;
in-out property <image> img; in-out property <image> img;
border-radius: 7px; border-radius: 7px;
@@ -13,7 +11,7 @@ export component SquareImageButton inherits Rectangle {
touch := TouchArea { touch := TouchArea {
clicked => { clicked => {
root.clicked(); root.clicked();
} }
} }
@@ -41,7 +39,7 @@ export component RoundImageButton inherits Rectangle {
touch := TouchArea { touch := TouchArea {
clicked => { clicked => {
root.clicked(); root.clicked();
} }
} }
@@ -66,7 +64,7 @@ export component SquareCharButton inherits Rectangle {
touch := TouchArea { touch := TouchArea {
clicked => { clicked => {
root.clicked(); root.clicked();
} }
} }
@@ -94,26 +92,26 @@ export component ValueBar inherits Rectangle {
// do a percentage of each half as 0-50% // do a percentage of each half as 0-50%
if (value >= max + min) { if (value >= max + min) {
return (value - (max + min) / 2) / (max - min); return (value - (max + min) / 2) / (max - min);
} }
return 0.50 - (value - (min - max) / 2) / (max - min); return 0.50 - (value - (min - max) / 2) / (max - min);
} }
return (value - min) / (max - min); return (value - min) / (max - min);
} }
function set_x(min: float, max: float, value: float, width: length) -> length{ function set_x(min: float, max: float, value: float, width: length) -> length{
if (min < 0.0 && max > 0.0) { if (min < 0.0 && max > 0.0) {
if (value < max + min) { if (value < max + min) {
return width / 2 - width * (percentage(min, max, value)); return width / 2 - width * (percentage(min, max, value));
} }
return width / 2; return width / 2;
} }
return 0; return 0;
} }
Rectangle { Rectangle {
@@ -152,7 +150,7 @@ export component SpinBoxUni inherits Rectangle {
clicked => { clicked => {
if (root.value > root.minimum) { if (root.value > root.minimum) {
root.value -= 1; root.value -= 1;
} }
} }
} }
@@ -178,7 +176,7 @@ export component SpinBoxUni inherits Rectangle {
clicked => { clicked => {
if (root.value < root.maximum) { if (root.value < root.maximum) {
root.value += 1; root.value += 1;
} }
} }
} }
@@ -240,7 +238,7 @@ export component PopupNotification {
public function show() { public function show() {
_p.show(); _p.show();
} }
} }

View File

@@ -1,6 +1,6 @@
import { ValueBar } from "../common_widgets.slint"; import { ValueBar, SquareCharButton } from "../common_widgets.slint";
import { Theme } from "../globals.slint"; import { Theme } from "../globals.slint";
import { HorizontalBox , VerticalBox, ScrollView, Slider} from "std-widgets.slint"; import { HorizontalBox , VerticalBox, ScrollView, Slider, Button, Switch} from "std-widgets.slint";
export struct AvailableSystemProperties { export struct AvailableSystemProperties {
charge_limit: bool, charge_limit: bool,
@@ -28,126 +28,175 @@ export struct SystemValues {
} }
export global SystemPage { export global SystemPage {
in-out property <int> charge-limit; in-out property <float> charge_limit;
callback set_charge(/* charge limit */ int, /* last limit */ int); in-out property <int> last_charge_limit;
callback set_charge_limit(/* charge limit */ int);
in-out property <bool> panel_od;
in-out property <bool> last_panel_od;
callback set_panel_od(/* panel_od */ bool);
callback applied();
callback cancelled();
in-out property <AvailableSystemProperties> available; in-out property <AvailableSystemProperties> available;
in-out property <SystemValues> values;
} }
export component PageSystem inherits Rectangle { export component PageSystem inherits Rectangle {
background: Theme.background-color; background: Theme.background-color;
ScrollView {
VerticalLayout { VerticalLayout {
// padding: 10px; ScrollView {
VerticalLayout {
// padding: 10px;
spacing: 10px; spacing: 10px;
min-height: root.height; min-height: root.height;
if SystemPage.available.charge-limit: Rectangle {
background: Theme.background-color;
VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("ChargeMode" => "Charging mode");
}
Text { if SystemPage.available.charge-limit: Rectangle {
color: Theme.text-foreground-color; background: Theme.background-color;
text: @tr("ChargeLimit" => "Charge limit"); VerticalBox {
}
charge_slider := Slider { HorizontalBox {
value: SystemPage.values.charge_limit; alignment: LayoutAlignment.start;
changed => { Text {
if SystemPage.values.last_charge_limit != charge_slider.value { color: Theme.text-foreground-color;
SystemPage.set_charge(charge_slider.value, SystemPage.values.last_charge_limit); text: @tr("ChargeLimit" => "Charge limit");
SystemPage.values.last_charge_limit = charge_slider.value; }
Text {
color: Theme.text-foreground-color;
text: "\{Math.floor(SystemPage.charge_limit)}";
}
}
HorizontalBox {
TouchArea { }
charge_slider := Slider {
maximum: 100;
minimum: 20;
value <=> SystemPage.charge_limit;
released => {
SystemPage.set_charge_limit(SystemPage.charge_limit)
}
} }
} }
} }
} }
}
if SystemPage.available.panel-od: Rectangle { if SystemPage.available.panel-od: Rectangle {
background: Theme.background-color; background: Theme.background-color;
VerticalBox { VerticalBox {
Text { HorizontalBox {
color: Theme.text-foreground-color; alignment: LayoutAlignment.start;
text: @tr("PanelOverdrive" => "Panel Overdrive"); Text {
color: Theme.text-foreground-color;
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Switch {
checked <=> SystemPage.panel_od;
toggled => {
SystemPage.set_panel_od(SystemPage.panel_od)
}
}
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
} }
}
Text { Rectangle {
color: Theme.text-foreground-color; background: Theme.background-color;
text: @tr("PerformanceProfile" => "Performance Profile"); VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("nv_dynamic_boost" => "nv_dynamic_boost");
}
Text {
color: Theme.text-foreground-color;
text: @tr("nv_temp_target" => "nv_temp_target");
}
Text {
color: Theme.text-foreground-color;
text: @tr("ppt_pl1_spl" => "ppt_pl1_spl");
}
Text {
color: Theme.text-foreground-color;
text: @tr("ppt_pl2_sppt" => "ppt_pl2_sppt");
}
}
}
Rectangle {
background: Theme.background-color;
VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
}
}
Rectangle {
background: Theme.background-color;
VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
}
}
Rectangle {
background: Theme.background-color;
VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
} }
} }
} }
}
Rectangle { HorizontalLayout {
background: Theme.background-color; Button {
VerticalBox { text: "Apply";
Text { clicked => {
color: Theme.text-foreground-color; if SystemPage.last_charge_limit != Math.floor(SystemPage.charge_limit) {
text: @tr("nv_dynamic_boost" => "nv_dynamic_boost"); SystemPage.set_charge_limit(SystemPage.charge_limit);
} SystemPage.last_charge_limit = Math.floor(SystemPage.charge_limit);
Text {
color: Theme.text-foreground-color;
text: @tr("nv_temp_target" => "nv_temp_target");
}
Text {
color: Theme.text-foreground-color;
text: @tr("ppt_pl1_spl" => "ppt_pl1_spl");
}
Text {
color: Theme.text-foreground-color;
text: @tr("ppt_pl2_sppt" => "ppt_pl2_sppt");
} }
SystemPage.applied();
} }
} }
Rectangle { Button {
background: Theme.background-color; text: "Cancel";
VerticalBox { clicked => {
Text { SystemPage.charge_limit = SystemPage.last_charge_limit;
color: Theme.text-foreground-color; SystemPage.cancelled();
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
}
}
Rectangle {
background: Theme.background-color;
VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
}
}
Rectangle {
background: Theme.background-color;
VerticalBox {
Text {
color: Theme.text-foreground-color;
text: @tr("PanelOverdrive" => "Panel Overdrive");
}
Text {
color: Theme.text-foreground-color;
text: @tr("PerformanceProfile" => "Performance Profile");
}
} }
} }
} }