Skip to content

Commit 4229c6d

Browse files
authored
Update ui.rs
1 parent 843f8e9 commit 4229c6d

File tree

1 file changed

+50
-36
lines changed

1 file changed

+50
-36
lines changed

source-code/src/ui.rs

Lines changed: 50 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,36 @@
11
use adw::prelude::*;
2-
use adw::ApplicationWindow;
3-
use gtk::{Box as GtkBox, Button, Label, Orientation, ScrolledWindow, Separator};
2+
use adw::{ApplicationWindow, Clamp, HeaderBar, WindowTitle};
3+
use gtk::{Box as GtkBox, Button, Image, Label, Orientation, ScrolledWindow, Separator};
44
use std::rc::Rc;
55
use std::cell::RefCell;
66

77
use crate::actions::Actions;
88

9+
fn create_button_with_icon(label_text: &str, icon_name: &str) -> Button {
10+
let button = Button::new();
11+
let hbox = GtkBox::new(Orientation::Horizontal, 6);
12+
let icon = Image::builder()
13+
.icon_name(icon_name)
14+
.pixel_size(24) // Set icon size for better look
15+
.build();
16+
hbox.append(&icon);
17+
let label = Label::new(Some(label_text));
18+
hbox.append(&label);
19+
button.set_child(Some(&hbox));
20+
button.set_halign(gtk::Align::Center); // Center buttons
21+
button
22+
}
23+
924
pub fn build_ui(window: &ApplicationWindow, actions_rc: Rc<RefCell<Actions>>) {
25+
// Add HeaderBar for prettier title and standard controls (close, minimize, maximize/fullscreen)
26+
let header_bar = HeaderBar::new();
27+
let window_title = WindowTitle::builder()
28+
.title("Witaj w HackerOS!")
29+
.subtitle("")
30+
.build();
31+
header_bar.set_title_widget(Some(&window_title));
32+
header_bar.set_show_end_title_buttons(true); // Ensure window controls (close, etc.)
33+
1034
let main_box = GtkBox::builder()
1135
.orientation(Orientation::Vertical)
1236
.spacing(20)
@@ -16,17 +40,14 @@ pub fn build_ui(window: &ApplicationWindow, actions_rc: Rc<RefCell<Actions>>) {
1640
.margin_bottom(20)
1741
.build();
1842

19-
// Title
20-
let title_label = Label::builder()
21-
.label("Witaj w HackerOS!")
22-
.css_classes(vec!["title".to_string()])
23-
.build();
24-
main_box.append(&title_label);
43+
// Prepend the header_bar to main_box for CSD
44+
main_box.prepend(&header_bar);
2545

26-
// Subtitle (feedback label)
46+
// Subtitle (feedback label) below header
2747
let subtitle_label = Label::builder()
2848
.label("Wybierz akcję poniżej.")
2949
.css_classes(vec!["subtitle".to_string()])
50+
.halign(gtk::Align::Center)
3051
.build();
3152
main_box.append(&subtitle_label);
3253

@@ -47,80 +68,65 @@ pub fn build_ui(window: &ApplicationWindow, actions_rc: Rc<RefCell<Actions>>) {
4768

4869
let buttons_box = GtkBox::builder()
4970
.orientation(Orientation::Vertical)
50-
.spacing(10)
71+
.spacing(15) // Increased spacing for prettier look
5172
.margin_start(10)
5273
.margin_end(10)
5374
.margin_top(10)
5475
.margin_bottom(10)
76+
.halign(gtk::Align::Center) // Center the buttons box
5577
.build();
5678

57-
// Buttons
58-
let website_button = Button::builder()
59-
.label("Otwórz stronę HackerOS")
60-
.build();
79+
// Buttons with icons for prettier UI
80+
let website_button = create_button_with_icon("Otwórz stronę HackerOS", "applications-internet-symbolic");
6181
website_button.connect_clicked({
6282
let actions_rc = actions_rc.clone();
6383
move |_| actions_rc.borrow().open_website()
6484
});
6585
buttons_box.append(&website_button);
6686

67-
let x_button = Button::builder()
68-
.label("Otwórz X (Twitter)")
69-
.build();
87+
let x_button = create_button_with_icon("Otwórz X (Twitter)", "internet-chat-symbolic");
7088
x_button.connect_clicked({
7189
let actions_rc = actions_rc.clone();
7290
move |_| actions_rc.borrow().open_x()
7391
});
7492
buttons_box.append(&x_button);
7593

76-
let software_button = Button::builder()
77-
.label("Otwórz Sklep z aplikacjami")
78-
.build();
94+
let software_button = create_button_with_icon("Otwórz Sklep z aplikacjami", "system-software-install-symbolic");
7995
software_button.connect_clicked({
8096
let actions_rc = actions_rc.clone();
8197
move |_| actions_rc.borrow().open_software()
8298
});
8399
buttons_box.append(&software_button);
84100

85-
let changelog_button = Button::builder()
86-
.label("Otwórz Changelog")
87-
.build();
101+
let changelog_button = create_button_with_icon("Otwórz Changelog", "document-properties-symbolic");
88102
changelog_button.connect_clicked({
89103
let actions_rc = actions_rc.clone();
90104
move |_| actions_rc.borrow().open_changelog()
91105
});
92106
buttons_box.append(&changelog_button);
93107

94-
let system_info_button = Button::builder()
95-
.label("Otwórz Informacje o systemie")
96-
.build();
108+
let system_info_button = create_button_with_icon("Otwórz Informacje o systemie", "help-about-symbolic");
97109
system_info_button.connect_clicked({
98110
let actions_rc = actions_rc.clone();
99111
move |_| actions_rc.borrow().open_system_info()
100112
});
101113
buttons_box.append(&system_info_button);
102114

103-
let report_bug_button = Button::builder()
104-
.label("Zgłoś błąd")
105-
.build();
115+
let report_bug_button = create_button_with_icon("Zgłoś błąd", "dialog-warning-symbolic");
106116
report_bug_button.connect_clicked({
107117
let actions_rc = actions_rc.clone();
108118
move |_| actions_rc.borrow().report_bug()
109119
});
110120
buttons_box.append(&report_bug_button);
111121

112-
let forum_button = Button::builder()
113-
.label("Otwórz Forum dyskusyjne")
114-
.build();
122+
let forum_button = create_button_with_icon("Otwórz Forum dyskusyjne", "internet-group-chat-symbolic");
115123
forum_button.connect_clicked({
116124
let actions_rc = actions_rc.clone();
117125
move |_| actions_rc.borrow().open_forum()
118126
});
119127
buttons_box.append(&forum_button);
120128

121-
let update_button = Button::builder()
122-
.label("Aktualizuj system")
123-
.build();
129+
let update_button = create_button_with_icon("Aktualizuj system", "system-software-update-symbolic");
124130
update_button.connect_clicked({
125131
let actions_rc = actions_rc.clone();
126132
move |_| actions_rc.borrow().update_system()
@@ -138,8 +144,16 @@ pub fn build_ui(window: &ApplicationWindow, actions_rc: Rc<RefCell<Actions>>) {
138144
let footer_label = Label::builder()
139145
.label("© 2025 HackerOS Team")
140146
.css_classes(vec!["footer".to_string()])
147+
.halign(gtk::Align::Center)
141148
.build();
142149
main_box.append(&footer_label);
143150

144-
window.set_content(Some(&main_box));
151+
// Use Clamp for responsive/prettier content limiting
152+
let clamp = Clamp::builder()
153+
.maximum_size(800) // Limit max width for better centering on large windows
154+
.tightening_threshold(600)
155+
.build();
156+
clamp.set_child(Some(&main_box));
157+
158+
window.set_content(Some(&clamp));
145159
}

0 commit comments

Comments
 (0)