From 47efaa2d0863a15c5de25948ce6a5ac00ffb8439 Mon Sep 17 00:00:00 2001 From: Candifloss Date: Wed, 19 Nov 2025 16:16:38 +0530 Subject: [PATCH] Dummy widget: Time widget - Time widget module - Configure layout and callback - Dummy: Not real time yet --- build.rs | 6 +++++- src/main.rs | 9 ++++++++- ui/time-widget.slint | 28 ++++++++++++++++++++++++++++ ui/topbar.slint | 26 +++++++++++++++++++++++--- 4 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 ui/time-widget.slint diff --git a/build.rs b/build.rs index 99576fc..fae0ac3 100644 --- a/build.rs +++ b/build.rs @@ -1,3 +1,7 @@ fn main() { - slint_build::compile("ui/topbar.slint").unwrap(); + slint_build::compile_with_config( + "ui/topbar.slint", + slint_build::CompilerConfiguration::new().with_style("fluent-dark".to_string()), + ) + .unwrap(); } diff --git a/src/main.rs b/src/main.rs index 6e26600..c478da9 100644 --- a/src/main.rs +++ b/src/main.rs @@ -24,7 +24,7 @@ fn main() -> Result<(), Box> { slint::platform::set_platform(Box::new(backend))?; // Bar dimensions. - let bar_height = 25; + let bar_height = 27; let bar_width = 1366; // Create the Slint UI component. @@ -33,6 +33,13 @@ fn main() -> Result<(), Box> { ui.set_bar_width(bar_width); ui.set_bar_height(bar_height); + let weak = ui.as_weak(); + ui.on_open_program(move || { + if let Some(_ui) = weak.upgrade() { + // Launch a program on click + std::process::Command::new("xclock").spawn().ok(); + } + }); // Size the window to match the bar. #[allow(clippy::cast_precision_loss)] ui.window() diff --git a/ui/time-widget.slint b/ui/time-widget.slint new file mode 100644 index 0000000..a1934f9 --- /dev/null +++ b/ui/time-widget.slint @@ -0,0 +1,28 @@ +export component TimeWidget { + in-out property time_text; + + callback open_program(); // Callback to execute things from Rust, because Slint can't + + Rectangle { + background: touch_area.pressed ? #555 : touch_area.has-hover ? #444 : #333; // Bg color based on click & hover + border-radius: 3px; + + HorizontalLayout { + padding-right: 3px; + padding-left: 3px; + + Text { + text: time_text; + color: white; + vertical-alignment: center; + } + } + + // Area to sense click and hover + touch_area:= TouchArea { + clicked => { + open_program(); + } + } + } +} diff --git a/ui/topbar.slint b/ui/topbar.slint index 6fa9b4d..e2f782b 100644 --- a/ui/topbar.slint +++ b/ui/topbar.slint @@ -1,16 +1,21 @@ +import { TimeWidget } from "time-widget.slint"; + export component TopBar inherits Window { in property bar_width; in property bar_height; + callback open_program(); + title: "chocobar"; width: bar_width *1px; height: bar_height *1px; always-on-top: true; no-frame: true; - //background: #999898a6; x: 0px; y: 0px; + default-font-family: "IosevkaTermSlab Nerd Font Mono"; + default-font-size: 14px; Rectangle { x: 0px; @@ -25,17 +30,32 @@ export component TopBar inherits Window { y: 0px; width: 100%; height: 100%; + alignment: space-between; + // Left side Rectangle { background: #79a9af7b; - } + width: parent.width/3; + } + // Middle Rectangle { background: #779e5c7a; - } + } + // Right side Rectangle { background: #c2779a7a; + width: parent.width/3; + + HorizontalLayout { + alignment: end; // RIght-align + + TimeWidget { + time_text: "11:43 AM"; // Fix this: Replace with time value + open_program => root.open_program(); // Forward the widget's callback to the root's to access from Rust + } + } } } }