From a321b03ba45a9f16bf1bd66baefb55e7a10e6bd8 Mon Sep 17 00:00:00 2001 From: candifloss Date: Sat, 3 Jan 2026 13:53:04 +0530 Subject: [PATCH] Pass all properties from Rust - No more default values in Slint --- src/main.rs | 18 +++----- src/powermenu.rs | 102 ++++++++++++++++++++++++++++++++++++++++++++ ui/power-menu.slint | 60 +++++++++----------------- 3 files changed, 129 insertions(+), 51 deletions(-) create mode 100644 src/powermenu.rs diff --git a/src/main.rs b/src/main.rs index 05a36ef..642ce44 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,8 +5,8 @@ use i_slint_backend_winit::{ window::WindowAttributes, }, }; -use slint::{LogicalPosition, LogicalSize}; -slint::include_modules!(); + +mod powermenu; fn main() -> Result<(), Box> { // Configure X11 window attributes before Slint creates the window. @@ -22,17 +22,11 @@ fn main() -> Result<(), Box> { let backend = Backend::builder() .with_window_attributes_hook(window_attrs) .build()?; + slint::platform::set_platform(Box::new(backend))?; - let ui = PowerMenu::new()?; + let screen_width = 1920; + let screen_height = 1080; - let screen_width = 1366; - let screen_height = 768; - - ui.window().set_size(LogicalSize::new(screen_width as f32, screen_height as f32)); - ui.window().set_position(LogicalPosition::new(0.0, 0.0)); - - ui.run(); - - Ok(()) + powermenu::run_power_menu(screen_width, screen_height) } diff --git a/src/powermenu.rs b/src/powermenu.rs new file mode 100644 index 0000000..398472f --- /dev/null +++ b/src/powermenu.rs @@ -0,0 +1,102 @@ +use slint::{Color, LogicalPosition, LogicalSize, SharedString}; + +slint::include_modules!(); + +pub fn run_power_menu( + screen_width: i32, + screen_height: i32, +) -> Result<(), Box> { + let ui = PowerMenu::new()?; + + let screen_bg = Color::from_argb_encoded(0x20A3A3A3); + + let btn_width = 120; + let btn_height = 120; + let btn_border_radius = 20; + + let btn_bg_normal = Color::from_argb_encoded(0x75919191); + let btn_bg_hover = Color::from_argb_encoded(0x84929292); + let btn_bg_clicked = Color::from_argb_encoded(0xAB9B9B9B); + + let option_icon_height = btn_height * 75 / 100; + let icon_font_size = option_icon_height * 80 / 100; + let icon_font = SharedString::from("IosevkaTermSlab Nerd Font Mono"); + let icon_font_color = Color::from_argb_encoded(0xFFFFFFFF); + + let option_text_height = btn_height * 25 / 100; + let option_text_font_size = option_text_height * 45 / 100; + let option_text_font = SharedString::from("IosevkaTermSlab Nerd Font Mono"); + let option_text_color = Color::from_argb_encoded(0xFFFFFFFF); + + let button_style = ButtonStyle { + btn_width, + btn_height, + btn_border_radius, + + btn_bg_normal, + btn_bg_hover, + btn_bg_clicked, + + option_icon_height, + icon_font_size, + icon_font, + icon_font_color, + + option_text_height, + option_text_font_size, + option_text_font, + option_text_color, + }; + + let menu_padding_x = 20; + let menu_padding_y = menu_padding_x; + let menu_spacing = menu_padding_x; + let menu_border_radius = menu_padding_x; + + let menu_width = btn_width * 4 + menu_spacing * 3 + menu_padding_x * 2; + + let menu_height = btn_height + menu_padding_y * 2; + + let menu_pos_x = (screen_width - menu_width) / 2; + let menu_pos_y = (screen_height - menu_height) / 2; + + let menu_bg = Color::from_argb_encoded(0x287A7A7A); + + ui.set_screen_width(screen_width); + ui.set_screen_height(screen_height); + + ui.set_screen_bg(screen_bg); + + ui.set_menu_padding_x(menu_padding_x); + ui.set_menu_padding_y(menu_padding_y); + ui.set_menu_spacing(menu_spacing); + ui.set_menu_border_radius(menu_border_radius); + + ui.set_menu_width(menu_width); + ui.set_menu_height(menu_height); + + ui.set_menu_pos_x(menu_pos_x); + ui.set_menu_pos_y(menu_pos_y); + + ui.set_menu_bg(menu_bg); + + ui.set_ico_lockscreen(SharedString::from("")); + ui.set_ico_logout(SharedString::from("")); + ui.set_ico_reboot(SharedString::from("")); + ui.set_ico_poweroff(SharedString::from("")); + + ui.set_text_lockscreen(SharedString::from("Lock screen")); + ui.set_text_logout(SharedString::from("Log Out")); + ui.set_text_reboot(SharedString::from("Reboot")); + ui.set_text_poweroff(SharedString::from("Power Off")); + + ui.set_button_style(button_style); + + ui.window() + .set_size(LogicalSize::new(screen_width as f32, screen_height as f32)); + ui.window().set_position(LogicalPosition::new(0.0, 0.0)); + + ui.run(); + + Ok(()) +} diff --git a/ui/power-menu.slint b/ui/power-menu.slint index bc789ab..c5b03ab 100644 --- a/ui/power-menu.slint +++ b/ui/power-menu.slint @@ -71,51 +71,33 @@ component PowerMenuButton { } export component PowerMenu inherits Window { - in property screen_width: 1920; - in property screen_height: 1080; - in property screen_bg: #a3a3a320; + in property screen_width; + in property screen_height; + in property screen_bg; - in property button_style: { - btn_width: 120, - btn_height: 120, - btn_border_radius: 20, + in property button_style; - btn_bg_normal: #91919175, - btn_bg_hover: #92929284, - btn_bg_clicked: #9b9b9bab, + in property menu_padding_x; + in property menu_padding_y; + in property menu_spacing; + in property menu_border_radius; - option_icon_height: 90, - icon_font_size: 80, - icon_font: "IosevkaTermSlab Nerd Font Mono", - icon_font_color: #ffffff, + in property menu_width; + in property menu_height; + in property menu_pos_x; + in property menu_pos_y; - option_text_height: 30, - option_text_font_size: 14, - option_text_font: "IosevkaTermSlab Nerd Font Mono", - option_text_color: #ffffff, - }; + in property menu_bg; - in property menu_padding_x: 20; - in property menu_padding_y: menu_padding_x; - in property menu_spacing: menu_padding_x; - in property menu_border_radius: menu_padding_x; + in property ico_lockscreen; + in property ico_logout; + in property ico_reboot; + in property ico_poweroff; - in property menu_width: (button_style.btn_width*4 + menu_spacing*3 + menu_padding_x*2); - in property menu_height: (button_style.btn_height + menu_padding_y*2); - in property menu_pos_x: (screen_width - menu_width)/2; - in property menu_pos_y: (screen_height - menu_height)/2; - - in property menu_bg: #7a7a7a28; - - in property ico_lockscreen: ""; - in property ico_logout: ""; - in property ico_reboot: ""; - in property ico_poweroff: ""; - - in property text_lockscreen: "Lock screen"; - in property text_logout: "Log Out"; - in property text_reboot: "Reboot"; - in property text_poweroff: "Power Off"; + in property text_lockscreen; + in property text_logout; + in property text_reboot; + in property text_poweroff; no-frame: true; always-on-top: true;