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
|
// Map, wardley map editor for linux
// Copyright (C) 2026 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 Affero 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 Affero General Public License for more details.
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
use gtk::prelude::*;
use relm4::Sender;
use relm4::gtk;
use crate::ui_helpers::create_switch_row;
use super::super::models::UserPreferences;
use super::super::window::PreferencesInput;
pub struct MapPage {
container: gtk::Box,
show_background_switch: gtk::Switch,
smart_positioning_switch: gtk::Switch,
custom_font_switch: gtk::Switch,
font_button: gtk::FontButton,
export_format_dropdown: gtk::DropDown,
}
impl MapPage {
pub fn new(preferences: &UserPreferences, sender: Sender<PreferencesInput>) -> Self {
let container = gtk::Box::new(gtk::Orientation::Vertical, 20);
container.set_margin_top(20);
container.set_margin_bottom(20);
container.set_margin_start(20);
container.set_margin_end(20);
container.set_valign(gtk::Align::Start);
// Map Style section
let style_label = gtk::Label::new(Some("Map Style"));
style_label.add_css_class("heading");
style_label.set_halign(gtk::Align::Start);
container.append(&style_label);
// Show Background
let background_row =
create_switch_row("Show Map Background", preferences.show_map_background);
let show_background_switch = background_row.1.clone();
{
let sender = sender.clone();
show_background_switch.connect_state_set(move |_, state| {
sender.emit(PreferencesInput::SetShowMapBackground(state));
gtk::glib::Propagation::Proceed
});
}
container.append(&background_row.0);
// Smart Label Positioning
let smart_row = create_switch_row(
"Use Smart Label Positioning",
preferences.use_smart_label_positioning,
);
let smart_positioning_switch = smart_row.1.clone();
{
let sender = sender.clone();
smart_positioning_switch.connect_state_set(move |_, state| {
sender.emit(PreferencesInput::SetUseSmartLabelPositioning(state));
gtk::glib::Propagation::Proceed
});
}
container.append(&smart_row.0);
// Use Custom Font
let custom_font_row = create_switch_row("Use Custom Font", preferences.use_custom_font);
let custom_font_switch = custom_font_row.1.clone();
container.append(&custom_font_row.0);
// Font selection
let font_row = gtk::Box::new(gtk::Orientation::Horizontal, 10);
font_row.append(>k::Label::new(Some("Font")));
let font_button = gtk::FontButton::new();
font_button.set_font(&preferences.custom_font_name);
font_button.set_sensitive(preferences.use_custom_font);
font_button.set_hexpand(true);
font_button.set_use_font(true);
{
let sender = sender.clone();
font_button.connect_font_set(move |button| {
if let Some(font) = button.font() {
let font_desc = gtk::pango::FontDescription::from_string(&font);
if let Some(family) = font_desc.family() {
sender.emit(PreferencesInput::SetCustomFontName(family.to_string()));
}
}
});
}
font_row.append(&font_button);
container.append(&font_row);
// Connect custom font switch to font button sensitivity
{
let font_button_clone = font_button.clone();
let sender = sender.clone();
custom_font_switch.connect_state_set(move |_, state| {
font_button_clone.set_sensitive(state);
sender.emit(PreferencesInput::SetUseCustomFont(state));
gtk::glib::Propagation::Proceed
});
}
// Export section
let export_label = gtk::Label::new(Some("Export"));
export_label.add_css_class("heading");
export_label.set_halign(gtk::Align::Start);
export_label.set_margin_top(10);
container.append(&export_label);
let export_row = gtk::Box::new(gtk::Orientation::Horizontal, 10);
export_row.append(>k::Label::new(Some("Default Export Format")));
let formats = gtk::StringList::new(&["PNG", "SVG"]);
let export_format_dropdown = gtk::DropDown::new(Some(formats), None::<gtk::Expression>);
let selected = match preferences.default_export_format.as_str() {
"svg" => 1,
_ => 0,
};
export_format_dropdown.set_selected(selected);
{
let sender = sender.clone();
export_format_dropdown.connect_selected_notify(move |dropdown| {
let format = match dropdown.selected() {
1 => "svg",
_ => "png",
};
sender.emit(PreferencesInput::SetDefaultExportFormat(format.to_string()));
});
}
export_row.append(&export_format_dropdown);
container.append(&export_row);
Self {
container,
show_background_switch,
smart_positioning_switch,
custom_font_switch,
font_button,
export_format_dropdown,
}
}
pub fn widget(&self) -> gtk::Box {
self.container.clone()
}
pub fn sync_from(&self, preferences: &UserPreferences) {
self.show_background_switch
.set_active(preferences.show_map_background);
self.smart_positioning_switch
.set_active(preferences.use_smart_label_positioning);
self.custom_font_switch
.set_active(preferences.use_custom_font);
self.font_button.set_sensitive(preferences.use_custom_font);
self.font_button.set_font(&preferences.custom_font_name);
let selected = match preferences.default_export_format.as_str() {
"svg" => 1,
_ => 0,
};
self.export_format_dropdown.set_selected(selected);
}
}
|