|
1 | | -// src/ui.rs |
2 | 1 | use adw::prelude::*; |
3 | | -use adw::{HeaderBar, ToolbarView}; |
4 | | -use gtk::prelude::*; |
5 | | -use gtk::{Align, Box as GtkBox, Button, FlowBox, Image, Label, Orientation, PolicyType, ScrolledWindow, Separator}; |
6 | | -use glib::clone; |
7 | | -use std::cell::RefCell; |
8 | | -use std::path::Path; |
| 2 | +use adw::ApplicationWindow; |
| 3 | +use gtk::{Box as GtkBox, Button, Label, Orientation, ScrolledWindow, Separator}; |
9 | 4 | use std::rc::Rc; |
10 | | -use gdk_pixbuf::Pixbuf; |
| 5 | +use std::cell::RefCell; |
| 6 | + |
11 | 7 | use crate::actions::Actions; |
12 | 8 |
|
13 | | -pub fn build_ui(window: &adw::ApplicationWindow, actions: Rc<RefCell<Actions>>) { |
14 | | - // HeaderBar |
15 | | - let header_bar = HeaderBar::builder() |
16 | | - .show_end_title_buttons(true) |
17 | | - .build(); |
18 | | - |
19 | | - // Title widget with logo and title |
20 | | - let title_box = GtkBox::builder() |
21 | | - .orientation(Orientation::Horizontal) |
22 | | - .spacing(10) |
23 | | - .build(); |
24 | | - |
25 | | - // Logo |
26 | | - let logo_path = "/usr/share/HackerOS/ICONS/Plymouth-Icons/watermark.png"; |
27 | | - let logo_image = if Path::new(logo_path).exists() { |
28 | | - let pixbuf = Pixbuf::from_file_at_scale(logo_path, 32, 32, true).ok(); |
29 | | - Image::from_pixbuf(pixbuf.as_ref()) |
30 | | - } else { |
31 | | - Image::new() |
32 | | - }; |
33 | | - title_box.append(&logo_image); |
34 | | - |
35 | | - // Title label |
| 9 | +pub fn build_ui(window: &ApplicationWindow, actions_rc: Rc<RefCell<Actions>>) { |
| 10 | + let main_box = GtkBox::builder() |
| 11 | + .orientation(Orientation::Vertical) |
| 12 | + .spacing(20) |
| 13 | + .margin_start(20) |
| 14 | + .margin_end(20) |
| 15 | + .margin_top(20) |
| 16 | + .margin_bottom(20) |
| 17 | + .build(); |
| 18 | + |
| 19 | + // Title |
36 | 20 | let title_label = Label::builder() |
37 | | - .label("Witaj w HackerOS!") |
38 | | - .use_markup(true) |
39 | | - .build(); |
40 | | - title_label.set_markup("<span font='Arial bold 20'>Witaj w HackerOS!</span>"); |
41 | | - title_box.append(&title_label); |
42 | | - |
43 | | - header_bar.set_title_widget(Some(&title_box)); |
44 | | - |
45 | | - // Content box |
46 | | - let content_box = GtkBox::builder() |
47 | | - .orientation(Orientation::Vertical) |
48 | | - .spacing(15) |
49 | | - .margin_top(20) |
50 | | - .margin_start(20) |
51 | | - .margin_end(20) |
52 | | - .margin_bottom(20) |
53 | | - .build(); |
54 | | - |
55 | | - // Subtitle |
56 | | - let subtitle_label = Label::builder() |
57 | | - .label("Twój system do Gier i Etycznego Hakowania") |
58 | | - .use_markup(true) |
59 | | - .halign(Align::Center) |
60 | | - .build(); |
61 | | - subtitle_label.set_markup("<span font='Arial 18'>Twój system do Gier i Etycznego Hakowania</span>"); |
62 | | - subtitle_label.style_context().add_class("subtitle"); |
63 | | - content_box.append(&subtitle_label); |
| 21 | + .label("Witaj w HackerOS!") |
| 22 | + .css_classes(vec!["title".to_string()]) |
| 23 | + .build(); |
| 24 | + main_box.append(&title_label); |
64 | 25 |
|
65 | | - actions.borrow_mut().subtitle_label = Some(subtitle_label.clone()); |
| 26 | + // Subtitle (feedback label) |
| 27 | + let subtitle_label = Label::builder() |
| 28 | + .label("Wybierz akcję poniżej.") |
| 29 | + .css_classes(vec!["subtitle".to_string()]) |
| 30 | + .build(); |
| 31 | + main_box.append(&subtitle_label); |
| 32 | + |
| 33 | + // Set subtitle_label in Actions |
| 34 | + { |
| 35 | + let mut actions = actions_rc.borrow_mut(); |
| 36 | + actions.subtitle_label = Some(subtitle_label); |
| 37 | + } |
66 | 38 |
|
67 | 39 | // Separator |
68 | | - let separator = Separator::builder() |
69 | | - .orientation(Orientation::Horizontal) |
70 | | - .margin_start(10) |
71 | | - .margin_end(10) |
72 | | - .build(); |
73 | | - content_box.append(&separator); |
74 | | - |
75 | | - // ScrolledWindow for buttons |
| 40 | + let separator1 = Separator::new(Orientation::Horizontal); |
| 41 | + main_box.append(&separator1); |
| 42 | + |
| 43 | + // Scrolled content for buttons |
76 | 44 | let scrolled_window = ScrolledWindow::builder() |
77 | | - .hscrollbar_policy(PolicyType::Never) |
78 | | - .vscrollbar_policy(PolicyType::Automatic) |
79 | | - .hexpand(true) |
80 | | - .vexpand(true) |
81 | | - .build(); |
82 | | - content_box.append(&scrolled_window); |
83 | | - |
84 | | - // FlowBox for buttons |
85 | | - let flow_box = FlowBox::builder() |
86 | | - .column_spacing(15) |
87 | | - .row_spacing(15) |
88 | | - .margin_start(10) |
89 | | - .margin_end(10) |
90 | | - .margin_bottom(20) |
91 | | - .homogeneous(true) |
92 | | - .min_children_per_line(2) |
93 | | - .max_children_per_line(3) |
94 | | - .build(); |
95 | | - scrolled_window.set_child(Some(&flow_box)); |
| 45 | + .vexpand(true) |
| 46 | + .build(); |
| 47 | + |
| 48 | + let buttons_box = GtkBox::builder() |
| 49 | + .orientation(Orientation::Vertical) |
| 50 | + .spacing(10) |
| 51 | + .margin_start(10) |
| 52 | + .margin_end(10) |
| 53 | + .margin_top(10) |
| 54 | + .margin_bottom(10) |
| 55 | + .build(); |
96 | 56 |
|
97 | 57 | // Buttons |
98 | | - let buttons = vec![ |
99 | | - ("Otwórz stronę HackerOS", clone!(@strong actions => move || actions.borrow().open_website())), |
100 | | - ("Otwórz X", clone!(@strong actions => move || actions.borrow().open_x())), |
101 | | - ("Otwórz sklep z aplikacjami", clone!(@strong actions => move || actions.borrow().open_software())), |
102 | | - ("Changelog", clone!(@strong actions => move || actions.borrow().open_changelog())), |
103 | | - ("Informacje o systemie", clone!(@strong actions => move || actions.borrow().open_system_info())), |
104 | | - ("Zgłoś błąd", clone!(@strong actions => move || actions.borrow().report_bug())), |
105 | | - ("Forum dyskusyjne", clone!(@strong actions => move || actions.borrow().open_forum())), |
106 | | - ("Zaktualizuj system", clone!(@strong actions => move || actions.borrow().update_system())), |
107 | | - ("Uruchom HackerOS Games", clone!(@strong actions => move || actions.borrow().run_command_with_feedback("/usr/share/HackerOS/Scripts/Bin/HackerOS-Games.sh"))), |
108 | | - ("Hacker Launcher", clone!(@strong actions => move || actions.borrow().run_command_with_feedback("/usr/share/HackerOS/Scripts/HackerOS-Apps/Hacker_Launcher"))), |
109 | | - ]; |
110 | | - |
111 | | - for (label, action) in buttons { |
112 | | - let button = Button::builder() |
113 | | - .label(label) |
114 | | - .build(); |
115 | | - button.connect_clicked(move |_| action()); |
116 | | - flow_box.append(&button); |
117 | | - } |
| 58 | + let website_button = Button::builder() |
| 59 | + .label("Otwórz stronę HackerOS") |
| 60 | + .build(); |
| 61 | + website_button.connect_clicked({ |
| 62 | + let actions_rc = actions_rc.clone(); |
| 63 | + move |_| actions_rc.borrow().open_website() |
| 64 | + }); |
| 65 | + buttons_box.append(&website_button); |
| 66 | + |
| 67 | + let x_button = Button::builder() |
| 68 | + .label("Otwórz X (Twitter)") |
| 69 | + .build(); |
| 70 | + x_button.connect_clicked({ |
| 71 | + let actions_rc = actions_rc.clone(); |
| 72 | + move |_| actions_rc.borrow().open_x() |
| 73 | + }); |
| 74 | + buttons_box.append(&x_button); |
| 75 | + |
| 76 | + let software_button = Button::builder() |
| 77 | + .label("Otwórz Sklep z aplikacjami") |
| 78 | + .build(); |
| 79 | + software_button.connect_clicked({ |
| 80 | + let actions_rc = actions_rc.clone(); |
| 81 | + move |_| actions_rc.borrow().open_software() |
| 82 | + }); |
| 83 | + buttons_box.append(&software_button); |
| 84 | + |
| 85 | + let changelog_button = Button::builder() |
| 86 | + .label("Otwórz Changelog") |
| 87 | + .build(); |
| 88 | + changelog_button.connect_clicked({ |
| 89 | + let actions_rc = actions_rc.clone(); |
| 90 | + move |_| actions_rc.borrow().open_changelog() |
| 91 | + }); |
| 92 | + buttons_box.append(&changelog_button); |
| 93 | + |
| 94 | + let system_info_button = Button::builder() |
| 95 | + .label("Otwórz Informacje o systemie") |
| 96 | + .build(); |
| 97 | + system_info_button.connect_clicked({ |
| 98 | + let actions_rc = actions_rc.clone(); |
| 99 | + move |_| actions_rc.borrow().open_system_info() |
| 100 | + }); |
| 101 | + buttons_box.append(&system_info_button); |
| 102 | + |
| 103 | + let report_bug_button = Button::builder() |
| 104 | + .label("Zgłoś błąd") |
| 105 | + .build(); |
| 106 | + report_bug_button.connect_clicked({ |
| 107 | + let actions_rc = actions_rc.clone(); |
| 108 | + move |_| actions_rc.borrow().report_bug() |
| 109 | + }); |
| 110 | + buttons_box.append(&report_bug_button); |
| 111 | + |
| 112 | + let forum_button = Button::builder() |
| 113 | + .label("Otwórz Forum dyskusyjne") |
| 114 | + .build(); |
| 115 | + forum_button.connect_clicked({ |
| 116 | + let actions_rc = actions_rc.clone(); |
| 117 | + move |_| actions_rc.borrow().open_forum() |
| 118 | + }); |
| 119 | + buttons_box.append(&forum_button); |
| 120 | + |
| 121 | + let update_button = Button::builder() |
| 122 | + .label("Aktualizuj system") |
| 123 | + .build(); |
| 124 | + update_button.connect_clicked({ |
| 125 | + let actions_rc = actions_rc.clone(); |
| 126 | + move |_| actions_rc.borrow().update_system() |
| 127 | + }); |
| 128 | + buttons_box.append(&update_button); |
| 129 | + |
| 130 | + scrolled_window.set_child(Some(&buttons_box)); |
| 131 | + main_box.append(&scrolled_window); |
| 132 | + |
| 133 | + // Separator |
| 134 | + let separator2 = Separator::new(Orientation::Horizontal); |
| 135 | + main_box.append(&separator2); |
118 | 136 |
|
119 | 137 | // Footer |
120 | 138 | let footer_label = Label::builder() |
121 | | - .label("© 2025 HackerOS Team | All rights reserved") |
122 | | - .halign(Align::Center) |
123 | | - .build(); |
124 | | - footer_label.style_context().add_class("footer"); |
125 | | - content_box.append(&footer_label); |
126 | | - |
127 | | - // ToolbarView to integrate header and content |
128 | | - let toolbar_view = ToolbarView::new(); |
129 | | - toolbar_view.add_top_bar(&header_bar); |
130 | | - toolbar_view.set_content(Some(&content_box)); |
131 | | - |
132 | | - // Set window content |
133 | | - window.set_content(Some(&toolbar_view)); |
| 139 | + .label("© 2025 HackerOS Team") |
| 140 | + .css_classes(vec!["footer".to_string()]) |
| 141 | + .build(); |
| 142 | + main_box.append(&footer_label); |
| 143 | + |
| 144 | + window.set_content(Some(&main_box)); |
134 | 145 | } |
0 commit comments