1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
|
// Copyright (C) 2024 Rubén Beltrán del Río
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see https://map.tranquil.systems.
use gtk::prelude::*;
use relm4::Sender;
use relm4::gtk;
use uuid::Uuid;
use super::super::models::UserPreferences;
use super::super::window::{PreferencesInput, StageLabel};
pub struct StagesPage {
container: gtk::Box,
list_box: gtk::ListBox,
sender: Sender<PreferencesInput>,
}
impl StagesPage {
pub fn new(prefs: &UserPreferences, sender: Sender<PreferencesInput>) -> Self {
let container = gtk::Box::new(gtk::Orientation::Vertical, 10);
container.set_margin_top(20);
container.set_margin_bottom(20);
container.set_margin_start(20);
container.set_margin_end(20);
// Header
let header_label = gtk::Label::new(Some("Custom Stages"));
header_label.add_css_class("heading");
header_label.set_halign(gtk::Align::Start);
container.append(&header_label);
let help_label = gtk::Label::new(Some(
"Custom stages allow you to define your own evolution axis labels. These will be available for rendering when the renderer supports custom stages.",
));
help_label.add_css_class("dim-label");
help_label.set_halign(gtk::Align::Start);
help_label.set_wrap(true);
help_label.set_margin_bottom(10);
container.append(&help_label);
// Column headers
let header_row = gtk::Box::new(gtk::Orientation::Horizontal, 5);
header_row.add_css_class("dim-label");
let name_header = gtk::Label::new(Some("Name"));
name_header.set_width_chars(15);
name_header.set_xalign(0.0);
header_row.append(&name_header);
let i_header = gtk::Label::new(Some("Stage I"));
i_header.set_width_chars(12);
i_header.set_xalign(0.0);
header_row.append(&i_header);
let ii_header = gtk::Label::new(Some("Stage II"));
ii_header.set_width_chars(12);
ii_header.set_xalign(0.0);
header_row.append(&ii_header);
let iii_header = gtk::Label::new(Some("Stage III"));
iii_header.set_width_chars(12);
iii_header.set_xalign(0.0);
header_row.append(&iii_header);
let iv_header = gtk::Label::new(Some("Stage IV"));
iv_header.set_width_chars(12);
iv_header.set_xalign(0.0);
header_row.append(&iv_header);
// Spacer for delete button column
let spacer = gtk::Box::new(gtk::Orientation::Horizontal, 0);
spacer.set_width_request(32);
header_row.append(&spacer);
container.append(&header_row);
// Scrollable list area
let scrolled = gtk::ScrolledWindow::new();
scrolled.set_vexpand(true);
scrolled.set_min_content_height(200);
let list_box = gtk::ListBox::new();
list_box.set_selection_mode(gtk::SelectionMode::None);
list_box.add_css_class("boxed-list");
scrolled.set_child(Some(&list_box));
container.append(&scrolled);
// Add button
let button_box = gtk::Box::new(gtk::Orientation::Horizontal, 10);
button_box.set_halign(gtk::Align::End);
let add_button = gtk::Button::from_icon_name("list-add-symbolic");
add_button.set_tooltip_text(Some("Add custom stage"));
{
let sender = sender.clone();
add_button.connect_clicked(move |_| {
sender.emit(PreferencesInput::AddCustomStage);
});
}
button_box.append(&add_button);
container.append(&button_box);
let page = Self {
container,
list_box,
sender,
};
page.populate_stages(prefs);
page
}
pub fn widget(&self) -> gtk::Box {
self.container.clone()
}
pub fn refresh(&self, prefs: &UserPreferences) {
// Clear existing rows
while let Some(child) = self.list_box.first_child() {
self.list_box.remove(&child);
}
self.populate_stages(prefs);
}
fn populate_stages(&self, prefs: &UserPreferences) {
for stage in &prefs.custom_stages {
let row = self.create_stage_row(stage.id, &stage.name, &stage.stage);
self.list_box.append(&row);
}
}
fn create_stage_row(
&self,
id: Uuid,
name: &str,
stage: &super::super::models::Stage,
) -> gtk::ListBoxRow {
let row = gtk::ListBoxRow::new();
let hbox = gtk::Box::new(gtk::Orientation::Horizontal, 5);
hbox.set_margin_top(5);
hbox.set_margin_bottom(5);
hbox.set_margin_start(5);
hbox.set_margin_end(5);
// Name entry
let name_entry = gtk::Entry::new();
name_entry.set_text(name);
name_entry.set_width_chars(15);
{
let sender = self.sender.clone();
name_entry.connect_changed(move |entry| {
sender.emit(PreferencesInput::SetCustomStageName(
id,
entry.text().to_string(),
));
});
}
hbox.append(&name_entry);
// Stage I entry
let i_entry = gtk::Entry::new();
i_entry.set_text(&stage.i);
i_entry.set_width_chars(12);
{
let sender = self.sender.clone();
i_entry.connect_changed(move |entry| {
sender.emit(PreferencesInput::SetCustomStageLabel(
id,
StageLabel::I,
entry.text().to_string(),
));
});
}
hbox.append(&i_entry);
// Stage II entry
let ii_entry = gtk::Entry::new();
ii_entry.set_text(&stage.ii);
ii_entry.set_width_chars(12);
{
let sender = self.sender.clone();
ii_entry.connect_changed(move |entry| {
sender.emit(PreferencesInput::SetCustomStageLabel(
id,
StageLabel::Ii,
entry.text().to_string(),
));
});
}
hbox.append(&ii_entry);
// Stage III entry
let iii_entry = gtk::Entry::new();
iii_entry.set_text(&stage.iii);
iii_entry.set_width_chars(12);
{
let sender = self.sender.clone();
iii_entry.connect_changed(move |entry| {
sender.emit(PreferencesInput::SetCustomStageLabel(
id,
StageLabel::Iii,
entry.text().to_string(),
));
});
}
hbox.append(&iii_entry);
// Stage IV entry
let iv_entry = gtk::Entry::new();
iv_entry.set_text(&stage.iv);
iv_entry.set_width_chars(12);
{
let sender = self.sender.clone();
iv_entry.connect_changed(move |entry| {
sender.emit(PreferencesInput::SetCustomStageLabel(
id,
StageLabel::Iv,
entry.text().to_string(),
));
});
}
hbox.append(&iv_entry);
// Delete button
let delete_button = gtk::Button::from_icon_name("list-remove-symbolic");
delete_button.add_css_class("flat");
delete_button.set_tooltip_text(Some("Remove stage"));
{
let sender = self.sender.clone();
delete_button.connect_clicked(move |_| {
sender.emit(PreferencesInput::RemoveCustomStage(id));
});
}
hbox.append(&delete_button);
row.set_child(Some(&hbox));
row
}
}
|