Compare commits

1 Commits

Author SHA1 Message Date
af6b40ff50 Testing slint_interpreter (for hot reload) Makes code realy ugly 2023-08-06 14:28:40 +02:00
6 changed files with 69 additions and 217 deletions

197
Cargo.lock generated
View File

@@ -391,12 +391,6 @@ dependencies = [
"which",
]
[[package]]
name = "bit_field"
version = "0.10.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
[[package]]
name = "bitflags"
version = "1.3.2"
@@ -882,12 +876,6 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "crunchy"
version = "0.2.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a81dae078cea95a014a339291cec439d2f232ebe854a9d672b796c6afafa9b7"
[[package]]
name = "crypto-common"
version = "0.1.6"
@@ -1130,22 +1118,6 @@ version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "exr"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d1e481eb11a482815d3e9d618db8c42a93207134662873809335a92327440c18"
dependencies = [
"bit_field",
"flume",
"half",
"lebe",
"miniz_oxide",
"rayon-core",
"smallvec",
"zune-inflate",
]
[[package]]
name = "fastrand"
version = "1.9.0"
@@ -1229,19 +1201,6 @@ version = "0.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "98de4bbd547a563b716d8dfa9aad1cb19bfab00f4fa09a6a4ed21dbcf44ce9c4"
[[package]]
name = "flume"
version = "0.10.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1657b4441c3403d9f7b3409e47575237dac27b1b5726df654a6ecbf92f0f7577"
dependencies = [
"futures-core",
"futures-sink",
"nanorand",
"pin-project",
"spin 0.9.8",
]
[[package]]
name = "fnv"
version = "1.0.7"
@@ -1391,6 +1350,12 @@ dependencies = [
"cfg-if",
]
[[package]]
name = "generativity"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5589a5c7c30674a175be65b67baec4b6af25cfa4e96c1ff1d630ab43d67ac5ae"
[[package]]
name = "generic-array"
version = "0.14.7"
@@ -1428,20 +1393,8 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
dependencies = [
"cfg-if",
"js-sys",
"libc",
"wasi",
"wasm-bindgen",
]
[[package]]
name = "gif"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "80792593675e051cf94a4b111980da2ba60d4a83e43e0048c5693baab3977045"
dependencies = [
"color_quant",
"weezl",
]
[[package]]
@@ -1537,15 +1490,6 @@ dependencies = [
"gl_generator",
]
[[package]]
name = "half"
version = "2.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "02b4af3693f1b705df946e9fe5631932443781d0aabb423b62fcd4d73f6d2fd0"
dependencies = [
"crunchy",
]
[[package]]
name = "hashbrown"
version = "0.12.3"
@@ -1700,9 +1644,7 @@ dependencies = [
"css-color-parser2",
"derive_more",
"dunce",
"fontdue",
"i-slint-common",
"image",
"itertools",
"linked_hash_set",
"lyon_extra",
@@ -1711,7 +1653,6 @@ dependencies = [
"once_cell",
"proc-macro2",
"quote",
"resvg",
"rowan",
"smol_str",
"strum",
@@ -1856,14 +1797,10 @@ dependencies = [
"bytemuck",
"byteorder",
"color_quant",
"exr",
"gif",
"jpeg-decoder",
"num-rational",
"num-traits",
"png",
"qoi",
"tiff",
]
[[package]]
@@ -1989,9 +1926,6 @@ name = "jpeg-decoder"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bc0000e42512c92e31c2252315bda326620a4e034105e900c98ec492fa077b3e"
dependencies = [
"rayon",
]
[[package]]
name = "js-sys"
@@ -2035,12 +1969,6 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "830d08ce1d1d941e6b30645f1a0eb5643013d835ce3779a5fc208261dbe10f55"
[[package]]
name = "lebe"
version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "03087c2bad5e1034e8cace5926dec053fb3790248370865f5117a7d0213354c8"
[[package]]
name = "lib"
version = "0.1.0"
@@ -2144,16 +2072,6 @@ version = "0.4.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "57bcfdad1b858c2db7c38303a6d2ad4dfaf5eb53dfeb0910128b2c26d6158503"
[[package]]
name = "lock_api"
version = "0.4.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c1cc9717a20b1bb222f333e6a92fd32f7d8a18ddc5a3191a11af45dcbf4dcd16"
dependencies = [
"autocfg",
"scopeguard",
]
[[package]]
name = "log"
version = "0.4.19"
@@ -2326,15 +2244,6 @@ dependencies = [
"windows-sys 0.48.0",
]
[[package]]
name = "nanorand"
version = "0.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a51313c5820b0b02bd422f4b44776fbf47961755c74ce64afc73bfad10226c3"
dependencies = [
"getrandom",
]
[[package]]
name = "ndk"
version = "0.7.0"
@@ -2444,16 +2353,6 @@ dependencies = [
"libm",
]
[[package]]
name = "num_cpus"
version = "1.16.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4161fcb6d602d4d2081af7c3a45852d875a03dd337a6bfdd6e06407b61342a43"
dependencies = [
"hermit-abi",
"libc",
]
[[package]]
name = "num_enum"
version = "0.5.11"
@@ -2737,15 +2636,6 @@ dependencies = [
"unicode-ident",
]
[[package]]
name = "qoi"
version = "0.4.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7f6d64c71eb498fe9eae14ce4ec935c555749aef511cca85b5568910d6e48001"
dependencies = [
"bytemuck",
]
[[package]]
name = "qttypes"
version = "0.2.9"
@@ -2811,28 +2701,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2ff9a1f06a88b01621b7ae906ef0211290d1c8a168a15542486a8f61c0833b9"
[[package]]
name = "rayon"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d2df5196e37bcc87abebc0053e20787d73847bb33134a69841207dd0a47f03b"
dependencies = [
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4b8f95bd6966f5c87776639160a66bd8ab9895d9d4ab01ddba9fc60661aebe8d"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"num_cpus",
]
[[package]]
name = "rctree"
version = "0.5.0"
@@ -2896,7 +2764,8 @@ dependencies = [
"lib",
"log",
"slint",
"slint-build",
"slint-interpreter",
"spin_on",
]
[[package]]
@@ -2931,7 +2800,7 @@ dependencies = [
"cc",
"libc",
"once_cell",
"spin 0.5.2",
"spin",
"untrusted",
"web-sys",
"winapi",
@@ -3300,14 +3169,21 @@ dependencies = [
]
[[package]]
name = "slint-build"
name = "slint-interpreter"
version = "1.2.0"
source = "git+https://github.com/slint-ui/slint#f301e3d8c9dab91c6595b0a279d5b46839dbd1ce"
dependencies = [
"derive_more",
"generativity",
"i-slint-backend-selector",
"i-slint-backend-winit",
"i-slint-common",
"i-slint-compiler",
"spin_on",
"i-slint-core",
"lyon_path",
"once_cell",
"thiserror",
"toml_edit",
"vtable",
]
[[package]]
@@ -3425,15 +3301,6 @@ version = "0.5.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e63cff320ae2c57904679ba7cb63280a3dc4613885beafb148ee7bf9aa9042d"
[[package]]
name = "spin"
version = "0.9.8"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67"
dependencies = [
"lock_api",
]
[[package]]
name = "spin_on"
version = "0.1.1"
@@ -3577,17 +3444,6 @@ dependencies = [
"syn 2.0.28",
]
[[package]]
name = "tiff"
version = "0.8.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7449334f9ff2baf290d55d73983a7d6fa15e01198faef72af07e2a8db851e471"
dependencies = [
"flate2",
"jpeg-decoder",
"weezl",
]
[[package]]
name = "tiny-skia"
version = "0.8.4"
@@ -4169,12 +4025,6 @@ dependencies = [
"rustls-webpki 0.100.1",
]
[[package]]
name = "weezl"
version = "0.1.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9193164d4de03a926d909d3bc7c30543cecb35400c02114792c2cae20d5e2dbb"
[[package]]
name = "which"
version = "4.4.0"
@@ -4634,15 +4484,6 @@ dependencies = [
"zvariant",
]
[[package]]
name = "zune-inflate"
version = "0.2.54"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "73ab332fe2f6680068f3582b16a24f90ad7096d5d39b974d1c0aff0125116f02"
dependencies = [
"simd-adler32",
]
[[package]]
name = "zvariant"
version = "3.15.0"

View File

@@ -17,8 +17,10 @@ anyhow = "1.0"
log = "0.4"
env_logger = "0.10"
slint-interpreter = {git = "https://github.com/slint-ui/slint", features = ["display-diagnostics"]}
spin_on = "0.1"
slint = { git = "https://github.com/slint-ui/slint" }
[build-dependencies]
slint-build = { git = "https://github.com/slint-ui/slint" }
# slint-build = { git = "https://github.com/slint-ui/slint" }
coop_widgets = { git = "https://codeberg.org/flovansl/co_sl" }

View File

@@ -1,4 +1,4 @@
fn main() {
coop_widgets::generate_import().unwrap();
slint_build::compile("ui/app.slint").unwrap();
// slint_build::compile("ui/app.slint").unwrap();
}

View File

@@ -2,26 +2,28 @@ use std::{thread, time::Duration};
use lib::{ClientMessage, MessageFromServer, MessageToServer, ServerMessage};
use log::info;
use slint::SharedString;
use slint_interpreter::{ComponentInstance, Value, ComponentHandle};
use slint::ComponentHandle;
use crate::{App,MediaLogic};
pub fn init(app: &App, sender_co: MessageToServer, receiver_s: MessageFromServer) {
pub fn init(app: &ComponentInstance, sender_co: MessageToServer, receiver_s: MessageFromServer) {
let sender_c = sender_co.clone();
app.global::<MediaLogic>().on_play_pause(move || {
app.set_global_callback("MediaLogic","play_pause",move |_: &[Value]| {
sender_c.send(ClientMessage::PlayPause).unwrap();
});
Value::default()
}).unwrap();
let sender_c = sender_co.clone();
app.global::<MediaLogic>().on_next(move || {
app.set_global_callback("MediaLogic","next", move |_: &[Value]| {
sender_c.send(ClientMessage::Next).unwrap();
});
Value::default()
}).unwrap();
let sender_c = sender_co.clone();
app.global::<MediaLogic>().on_previous(move || {
app.set_global_callback("MediaLogic","previous", move |_: &[Value]| {
sender_c.send(ClientMessage::Previous).unwrap();
});
Value::default()
}).unwrap();
let app_handle = app.as_weak();
thread::spawn(move || loop {
@@ -34,12 +36,12 @@ pub fn init(app: &App, sender_co: MessageToServer, receiver_s: MessageFromServer
match msg {
ServerMessage::NowPlaying(title) => app_handle
.upgrade_in_event_loop(move |handle| {
handle.global::<MediaLogic>().set_now_playing(title.into())
handle.set_global_property("MediaLogic","now_playing",Value::String(SharedString::from(title))).unwrap();
})
.unwrap(),
ServerMessage::Playing(bool) => app_handle
.upgrade_in_event_loop(move |handle| {
handle.global::<MediaLogic>().set_playing(bool)
handle.set_global_property("MediaLogic","playing",Value::Bool(bool)).unwrap();
})
.unwrap(),
};

View File

@@ -1,16 +1,14 @@
use slint::*;
use crate::{App,VirtualKeyboardHandler};
use slint::SharedString;
use slint_interpreter::{ComponentInstance, Value, ComponentHandle};
pub fn init(app: &App) {
let weak = app.as_weak();
app.global::<VirtualKeyboardHandler>().on_key_pressed({
move |key| {
weak.unwrap()
.window()
.dispatch_event(slint::platform::WindowEvent::KeyPressed { text: key.clone() });
weak.unwrap()
.window()
.dispatch_event(slint::platform::WindowEvent::KeyReleased { text: key });
pub fn init(app: &ComponentInstance) {
let app_weak = app.as_weak();
app.set_global_callback("VirtualKeyboardHandler","key_pressed",
move |args: &[Value]| {
let arg: SharedString = args[0].clone().try_into().unwrap();
app_weak.unwrap().window().dispatch_event(slint::platform::WindowEvent::KeyPressed { text: arg.clone() });
app_weak.unwrap().window().dispatch_event(slint::platform::WindowEvent::KeyReleased { text: arg.clone() });
Value::default()
}
});
).unwrap();
}

View File

@@ -1,27 +1,36 @@
mod controller;
mod link;
use crate::{
controller::{virtual_keyboard, media},
link::init_tcp,
};
use log::info;
use crate::{controller::{media,virtual_keyboard}, link::init_tcp};
slint::include_modules!();
// slint::include_modules!();
use slint_interpreter::{ComponentCompiler, ComponentHandle};
fn main() -> Result<(), slint::PlatformError> {
fn main() -> Result<(), slint_interpreter::PlatformError> {
env_logger::init_from_env(
env_logger::Env::default().filter_or(env_logger::DEFAULT_FILTER_ENV, "info"),
);
let (messages_to_server, message_from_server) = init_tcp();
let app = App::new()?;
let mut compiler = ComponentCompiler::default();
let definition = spin_on::spin_on(compiler.build_from_path("/home/jika/IdeaProjects/deckui/remote/ui/app.slint"));
slint_interpreter::print_diagnostics(&compiler.diagnostics());
if let Some(definition) = definition {
let app = definition.create()?;
app.global::<ColorReload>().invoke_reload_color();
app.invoke_global("ColorReload","reload_color",&[]).unwrap();
media::init(&app, messages_to_server, message_from_server);
virtual_keyboard::init(&app);
media::init(&app, messages_to_server, message_from_server);
info!("Launching UI");
app.run()
virtual_keyboard::init(&app);
info!("Launching UI");
return app.run()
}
Ok(())
}