aboutsummaryrefslogtreecommitdiff
path: root/src/preferences/pages/map.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/preferences/pages/map.rs')
-rw-r--r--src/preferences/pages/map.rs65
1 files changed, 28 insertions, 37 deletions
diff --git a/src/preferences/pages/map.rs b/src/preferences/pages/map.rs
index f3537c0..8deae20 100644
--- a/src/preferences/pages/map.rs
+++ b/src/preferences/pages/map.rs
@@ -1,22 +1,25 @@
-// Copyright (C) 2024 Rubén Beltrán del Río
+// 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 General Public License as published by
+// 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 General Public License for more details.
+// GNU Affero 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.
+// 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;
@@ -30,7 +33,7 @@ pub struct MapPage {
}
impl MapPage {
- pub fn new(prefs: &UserPreferences, sender: Sender<PreferencesInput>) -> Self {
+ 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);
@@ -45,8 +48,9 @@ impl MapPage {
container.append(&style_label);
// Show Background
- let bg_row = create_switch_row("Show Map Background", prefs.show_map_background);
- let show_background_switch = bg_row.1.clone();
+ 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| {
@@ -54,12 +58,12 @@ impl MapPage {
gtk::glib::Propagation::Proceed
});
}
- container.append(&bg_row.0);
+ container.append(&background_row.0);
// Smart Label Positioning
let smart_row = create_switch_row(
"Use Smart Label Positioning",
- prefs.use_smart_label_positioning,
+ preferences.use_smart_label_positioning,
);
let smart_positioning_switch = smart_row.1.clone();
{
@@ -72,7 +76,7 @@ impl MapPage {
container.append(&smart_row.0);
// Use Custom Font
- let custom_font_row = create_switch_row("Use Custom Font", prefs.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);
@@ -81,14 +85,14 @@ impl MapPage {
font_row.append(&gtk::Label::new(Some("Font")));
let font_button = gtk::FontButton::new();
- font_button.set_font(&prefs.custom_font_name);
- font_button.set_sensitive(prefs.use_custom_font);
+ 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 |btn| {
- if let Some(font) = btn.font() {
+ 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()));
@@ -122,7 +126,7 @@ impl MapPage {
let formats = gtk::StringList::new(&["PNG", "SVG"]);
let export_format_dropdown = gtk::DropDown::new(Some(formats), None::<gtk::Expression>);
- let selected = match prefs.default_export_format.as_str() {
+ let selected = match preferences.default_export_format.as_str() {
"svg" => 1,
_ => 0,
};
@@ -154,16 +158,17 @@ impl MapPage {
self.container.clone()
}
- pub fn sync_from(&self, prefs: &UserPreferences) {
+ pub fn sync_from(&self, preferences: &UserPreferences) {
self.show_background_switch
- .set_active(prefs.show_map_background);
+ .set_active(preferences.show_map_background);
self.smart_positioning_switch
- .set_active(prefs.use_smart_label_positioning);
- self.custom_font_switch.set_active(prefs.use_custom_font);
- self.font_button.set_sensitive(prefs.use_custom_font);
- self.font_button.set_font(&prefs.custom_font_name);
+ .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 prefs.default_export_format.as_str() {
+ let selected = match preferences.default_export_format.as_str() {
"svg" => 1,
_ => 0,
};
@@ -171,17 +176,3 @@ impl MapPage {
}
}
-fn create_switch_row(label: &str, initial_state: bool) -> (gtk::Box, gtk::Switch) {
- let row = gtk::Box::new(gtk::Orientation::Horizontal, 10);
- row.append(&gtk::Label::new(Some(label)));
-
- let spacer = gtk::Box::new(gtk::Orientation::Horizontal, 0);
- spacer.set_hexpand(true);
- row.append(&spacer);
-
- let switch = gtk::Switch::new();
- switch.set_active(initial_state);
- row.append(&switch);
-
- (row, switch)
-}