chocobar-x11/ui/topbar.slint
Candifloss 962bed3dad Add reusable SquareIconWidget
- Avoid code duplication
- Base square icon button component with common appearance, properties, callbacks
- Refactor BatteryWidget to inherit SquareIconWidget
2025-11-21 19:47:25 +05:30

99 lines
2.8 KiB
Plaintext

import { TimeWidget } from "time-widget.slint";
import { DateWidget } from "date-widget.slint";
import { BatteryWidget } from "battery-widget.slint";
export component TopBar inherits Window {
// Common properties
in property<int> bar_width;
in property<int> bar_height;
in property<int> def_font_size;
in property<string> def_font_fam;
// Time widget
in-out property <string> time_text;
callback show_clock();
// Date widget
in-out property <string> date_text;
callback show_calendar();
// Battery widget
in property <string> battery_status;
in property <int> battery_capacity;
in property <string> battery_capacity_level;
in property <string> battery_icon;
callback show_battery();
title: "chocobar";
width: bar_width *1px;
height: bar_height *1px;
always-on-top: true;
no-frame: true;
x: 0px;
y: 0px;
default-font-family: def_font_fam;
default-font-size: def_font_size *1px;
Rectangle {
x: 0px;
y: 0px;
width: 100%;
height: 100%;
background: #999898a6;
border-radius: 0px;
HorizontalLayout {
x: 0px;
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
BatteryWidget {
bar_height: root.bar_height;
icon_text: root.battery_icon;
square_btn_callback => root.show_battery();
battery_status: root.battery_status;
battery_capacity: root.battery_capacity;
battery_capacity_level: root.battery_capacity_level;
}
DateWidget {
// Get from root
date_text: root.date_text;
// Forward the widget's callback to the root's to access from Rust
show_calendar => root.show_calendar();
}
TimeWidget {
// Get from root
time_text: root.time_text;
// Forward the widget's callback to the root's to access from Rust
show_clock => root.show_clock();
}
}
}
}
}
}