diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-01-16 15:33:52 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-01-16 15:42:08 +0100 |
| commit | 439cd0d998571506dd7971fe1e357d09cb2ff36e (patch) | |
| tree | f9f2667865c3816736b3f009c0841510b97fcb76 /src/preferences/pages/editor.rs | |
| parent | 5a902f8b350f8b2b33c4e19c70f3425802faaa1b (diff) | |
Add license, and expand variables
Diffstat (limited to 'src/preferences/pages/editor.rs')
| -rw-r--r-- | src/preferences/pages/editor.rs | 56 |
1 files changed, 23 insertions, 33 deletions
diff --git a/src/preferences/pages/editor.rs b/src/preferences/pages/editor.rs index 5334a37..9f10d43 100644 --- a/src/preferences/pages/editor.rs +++ b/src/preferences/pages/editor.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; @@ -29,7 +32,7 @@ pub struct EditorPage { } impl EditorPage { - 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,7 +48,7 @@ impl EditorPage { let font_size_box = gtk::Box::new(gtk::Orientation::Horizontal, 10); let font_size_spin = gtk::SpinButton::with_range(7.0, 21.0, 1.0); - font_size_spin.set_value(prefs.editor_font_size); + font_size_spin.set_value(preferences.editor_font_size); { let sender = sender.clone(); font_size_spin.connect_value_changed(move |spin| { @@ -64,7 +67,7 @@ impl EditorPage { container.append(&style_label); // Soft Wrap Lines - let soft_wrap_row = create_switch_row("Soft Wrap Lines", prefs.soft_wrap_lines); + let soft_wrap_row = create_switch_row("Soft Wrap Lines", preferences.soft_wrap_lines); let soft_wrap_switch = soft_wrap_row.1.clone(); { let sender = sender.clone(); @@ -77,7 +80,7 @@ impl EditorPage { // Use Custom Font let custom_font_row = - create_switch_row("Use Custom Editor Font", prefs.use_custom_editor_font); + create_switch_row("Use Custom Editor Font", preferences.use_custom_editor_font); let custom_font_switch = custom_font_row.1.clone(); container.append(&custom_font_row.0); @@ -88,15 +91,15 @@ impl EditorPage { let font_button = gtk::FontButton::new(); font_button.set_font(&format!( "{} {}", - prefs.custom_editor_font_name, prefs.editor_font_size as i32 + preferences.custom_editor_font_name, preferences.editor_font_size as i32 )); - font_button.set_sensitive(prefs.use_custom_editor_font); + font_button.set_sensitive(preferences.use_custom_editor_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() { // Extract font family from the font string let font_desc = gtk::pango::FontDescription::from_string(&font); if let Some(family) = font_desc.family() { @@ -134,30 +137,17 @@ impl EditorPage { self.container.clone() } - pub fn sync_from(&self, prefs: &UserPreferences) { - self.font_size_spin.set_value(prefs.editor_font_size); - self.soft_wrap_switch.set_active(prefs.soft_wrap_lines); + pub fn sync_from(&self, preferences: &UserPreferences) { + self.font_size_spin.set_value(preferences.editor_font_size); + self.soft_wrap_switch.set_active(preferences.soft_wrap_lines); self.custom_font_switch - .set_active(prefs.use_custom_editor_font); - self.font_button.set_sensitive(prefs.use_custom_editor_font); + .set_active(preferences.use_custom_editor_font); + self.font_button + .set_sensitive(preferences.use_custom_editor_font); self.font_button.set_font(&format!( "{} {}", - prefs.custom_editor_font_name, prefs.editor_font_size as i32 + preferences.custom_editor_font_name, preferences.editor_font_size as i32 )); } } -fn create_switch_row(label: &str, initial_state: bool) -> (gtk::Box, gtk::Switch) { - let row = gtk::Box::new(gtk::Orientation::Horizontal, 10); - row.append(>k::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) -} |