From df144ea487e17ebd9d2e8880158eb4b303ee03c5 Mon Sep 17 00:00:00 2001 From: Avii Date: Thu, 6 Aug 2026 17:44:56 +0200 Subject: [PATCH] 1786031096 --- src/main.rs | 22 ++++++--- ui/main.slint | 133 +++++--------------------------------------------- 2 files changed, 27 insertions(+), 128 deletions(-) diff --git a/src/main.rs b/src/main.rs index 383c3f1..0766ff5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,8 @@ +use std::{ + thread::{self, sleep}, + time::Duration, +}; + mod rgba; #[cfg(not(feature = "dev"))] mod trekstor; @@ -9,13 +14,16 @@ fn main() -> Result<(), slint::PlatformError> { slint::platform::set_platform(Box::new(crate::trekstor::Trekstor::new())) .expect("set platform"); - let ui = MainWindow::new()?; + let main_window = MainWindow::new()?; - // let ui_handle = ui.as_weak(); - // ui.on_request_increase_value(move || { - // let ui = ui_handle.unwrap(); - // ui.set_counter(ui.get_counter() + 1); - // }); + let weak_window = main_window.as_weak(); + thread::spawn(move || { + sleep(Duration::from_secs(3)); + println!("Goodbye!"); + weak_window.upgrade_in_event_loop(move |ui| { + ui.set_text("GoodBye!".into()); + }) + }); - ui.run() + main_window.run() } diff --git a/ui/main.slint b/ui/main.slint index d21ec17..7ab00d0 100644 --- a/ui/main.slint +++ b/ui/main.slint @@ -1,130 +1,21 @@ // Copyright © SixtyFPS GmbH // SPDX-License-Identifier: MIT -export global AppState { - out property totalLights: 35; - property degreesFilledWithLights: 360deg - (startAngle - endAngle); - out property volume: (normalizeAngle(angle - startAngle) / degreesFilledWithLights) * (totalLights + 1); - out property startAngle: 120deg; - out property endAngle: 60deg; - out property angleGap: startAngle - endAngle; - in-out property angle: startAngle; - out property elementRadius: 185px; - - pure public function normalizeAngle(angle: angle) -> angle { - return (angle + 360deg).mod(360deg); - } -} - -export component Light { - in property index; - property gap: (360deg - (AppState.startAngle - AppState.endAngle)) / AppState.totalLights; - property angle: (index * gap) + AppState.startAngle; - property lightOn: index <= AppState.volume; - - x: AppState.elementRadius * angle.cos(); - y: AppState.elementRadius * angle.sin(); - width: 0; - height: 0; - - states [ - lightOn when root.lightOn: { - blueLed.opacity: 0.6; - in { - animate blueLed.opacity { - duration: 100ms; - easing: ease-in-sine; - } - } - out { - animate blueLed.opacity { - duration: 600ms; - easing: ease-out-sine; - } - } - } - ] - - Image { - source: @image-url("images/light-hole.png"); - } - - blueLed := Image { - source: @image-url("images/light.png"); - opacity: 0; - } -} +import { LineEdit } from "std-widgets.slint"; +// The window the user interacts with. Edits to the inputs propagate to +// the SystemTrayIcon instance via the host language's callbacks. export component MainWindow inherits Window { - preferred-width: 500px; - preferred-height: 500px; - background: #1e1d27; + title: "Dashboard"; + preferred-width: 1024px; + preferred-height: 600px; - base := Image { - source: @image-url("images/dial-frame.png"); + in property text: "Hello World"; + + callback set-label(string); + + Text { + text: text; } - ta := TouchArea { - property centerX: self.width / 2; - property centerY: self.height / 2; - property relativeX: ta.mouse-x - centerX; - property relativeY: ta.mouse-y - centerY; - property lastAngle; - property hovering: Math.pow(relativeX / 1px, 2) + Math.pow(relativeY / 1px, 2) < metalKnob.width / 2px * metalKnob.height / 2px; - property touching: false; - width: base.width; - height: base.height; - - mouse-cursor: touching ? grabbing : hovering ? grab : default; - - pointer-event(event) => { - let newAngle = AppState.normalizeAngle(atan2(relativeY / 1px, relativeX / 1px)); - if event.kind == PointerEventKind.down { - if hovering { - touching = true; - lastAngle = newAngle; - } - } else if event.kind == PointerEventKind.up { - touching = false; - } else if event.kind == PointerEventKind.move { - if touching { - let nextAngle = AppState.normalizeAngle(AppState.angle - lastAngle + newAngle); - // Check if the new angle is within the start and end angles - if nextAngle >= AppState.startAngle || nextAngle <= AppState.endAngle { - AppState.angle = nextAngle; - } - lastAngle = newAngle; - } - } - } - } - - metalKnob := Image { - source: @image-url("images/metal-dial.png"); - transform-rotation: AppState.angle; - } - - Image { - source: @image-url("images/metal-lights.png"); - } - - Image { - source: @image-url("images/dial-trim.png"); - } - - Rectangle { - x: parent.width / 2; - y: parent.height / 2; - - Image { - property r: 0.5; - x: r * root.width / 2 * AppState.angle.cos(); - y: r * root.height / 2 * AppState.angle.sin(); - source: @image-url("images/indicator.png"); - } - - for i in AppState.totalLights + 1: Light { - index: i; - } - } }