diff options
| author | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-03-26 23:26:23 +0100 |
|---|---|---|
| committer | Rubén Beltrán del Río <jj@r.bdr.sh> | 2026-03-26 23:44:35 +0100 |
| commit | c2465ff46ea2503cf839efdd90ccc5174f84fbe8 (patch) | |
| tree | a02e710e04bb1b1068534427b5bb8235f1071cde /src | |
| parent | 1f28cbdf1dbe26e4c7da27323a0202a3276cb3a7 (diff) | |
Address clippy issues
Diffstat (limited to 'src')
| -rw-r--r-- | src/components/footer.rs | 18 | ||||
| -rw-r--r-- | src/components/header.rs | 24 | ||||
| -rw-r--r-- | src/file_registry.rs | 2 | ||||
| -rw-r--r-- | src/handlers/preferences.rs | 30 | ||||
| -rw-r--r-- | src/handlers/view.rs | 10 | ||||
| -rw-r--r-- | src/handlers/zoom.rs | 2 | ||||
| -rw-r--r-- | src/main.rs | 130 |
7 files changed, 119 insertions, 97 deletions
diff --git a/src/components/footer.rs b/src/components/footer.rs index 2576163..1c6581d 100644 --- a/src/components/footer.rs +++ b/src/components/footer.rs @@ -1,14 +1,12 @@ use gtk::prelude::*; -use relm4::prelude::*; use relm4::actions::ActionablePlus; +use relm4::prelude::*; -use crate::tr; use crate::constants; +use crate::tr; -use crate::{ - ZoomInAction, ZoomOutAction, actions::Action -}; -use crate::icon_names::shipped::{ ZOOM_IN_REGULAR, ZOOM_OUT_REGULAR }; +use crate::icon_names::shipped::{ZOOM_IN_REGULAR, ZOOM_OUT_REGULAR}; +use crate::{ZoomInAction, ZoomOutAction, actions::Action}; // Model and Input Messages @@ -22,7 +20,7 @@ pub struct FooterInit { #[derive(Debug, Clone)] pub enum FooterAction { - SetZoom(f64) + SetZoom(f64), } #[relm4::component(pub)] @@ -81,9 +79,7 @@ impl SimpleComponent for Footer { root: Self::Root, sender: ComponentSender<Self>, ) -> ComponentParts<Self> { - let model = Footer { - zoom: init.zoom - }; + let model = Footer { zoom: init.zoom }; let widgets = view_output!(); ComponentParts { model, widgets } @@ -91,7 +87,7 @@ impl SimpleComponent for Footer { fn update(&mut self, message: Self::Input, _sender: ComponentSender<Self>) { match message { - FooterAction::SetZoom(zoom) => self.zoom = zoom + FooterAction::SetZoom(zoom) => self.zoom = zoom, } } } diff --git a/src/components/header.rs b/src/components/header.rs index 7a39490..6c1055b 100644 --- a/src/components/header.rs +++ b/src/components/header.rs @@ -1,19 +1,17 @@ use gtk::{gio, prelude::*}; -use relm4::prelude::*; use relm4::actions::{ActionablePlus, RelmAction}; +use relm4::prelude::*; use wmap_renderer::StageType; -use crate::tr; use crate::preferences::models::{CustomStage, Template}; use crate::stages::{ALL_STAGE_TYPES, LocalizedStageType}; +use crate::tr; -use crate::{ - ChangeOrientationAction, ExportImageAction, actions::Action -}; use crate::icon_names::shipped::{ - IMAGE_REGULAR, MENU_LARGE, SPLIT_HORIZONTAL_REGULAR, SPLIT_VERTICAL_REGULAR + IMAGE_REGULAR, MENU_LARGE, SPLIT_HORIZONTAL_REGULAR, SPLIT_VERTICAL_REGULAR, }; +use crate::{ChangeOrientationAction, ExportImageAction, actions::Action}; // Model and Input Messages @@ -24,7 +22,7 @@ pub struct Header { horizontal_layout_enabled: bool, templates_menu: gio::Menu, main_menu: gio::Menu, - layout_action: RelmAction<ChangeOrientationAction> + layout_action: RelmAction<ChangeOrientationAction>, } pub struct HeaderInit { @@ -43,7 +41,7 @@ pub enum HeaderAction { SetCustomStages(Vec<CustomStage>), // Internal - StageTypeSelected(usize) + StageTypeSelected(usize), } #[relm4::component(pub)] @@ -110,7 +108,7 @@ impl SimpleComponent for Header { horizontal_layout_enabled: init.horizontal_layout_enabled, layout_action: init.layout_action, templates_menu, - main_menu + main_menu, }; let widgets = view_output!(); @@ -124,7 +122,7 @@ impl SimpleComponent for Header { HeaderAction::SetHorizontalLayoutEnabled(is_enabled) => { self.horizontal_layout_enabled = is_enabled; self.layout_action.set_enabled(is_enabled); - }, + } HeaderAction::SetLayoutOrientation(orientation) => self.orientation = orientation, HeaderAction::SetTemplates(templates) => { self.templates_menu.remove_all(); @@ -134,17 +132,17 @@ impl SimpleComponent for Header { Some(&format!("window.new-from-template::{}", template.id)), ); } - }, + } HeaderAction::SetCustomStages(stages) => { self.rebuild_custom_stages(&stages); - }, + } HeaderAction::StageTypeSelected(index) => { if index < self.available_stage_types.len() && let Some(stage_type) = self.available_stage_types.get(index) { let _ = sender.output(Action::StageTypeSelected(stage_type.clone())); } - }, + } } } } diff --git a/src/file_registry.rs b/src/file_registry.rs index 188e1fe..c8337cf 100644 --- a/src/file_registry.rs +++ b/src/file_registry.rs @@ -20,8 +20,8 @@ use std::cell::RefCell; use std::path::PathBuf; +use relm4::adw; use relm4::component::Controller; -use relm4::{adw}; use crate::AppModel; use crate::actions::Action; diff --git a/src/handlers/preferences.rs b/src/handlers/preferences.rs index f915898..89a1ef5 100644 --- a/src/handlers/preferences.rs +++ b/src/handlers/preferences.rs @@ -13,13 +13,13 @@ // 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 relm4::prelude::*; use adw::prelude::*; +use relm4::prelude::*; -use crate::file_registry; -use crate::preferences::{PreferencesWindow, UserPreferences, storage, window}; use crate::actions::Action; use crate::components::header::HeaderAction; +use crate::file_registry; +use crate::preferences::{PreferencesWindow, UserPreferences, storage, window}; use crate::AppModel; @@ -33,9 +33,7 @@ pub fn show(model: &mut AppModel, sender: &ComponentSender<AppModel>) { window::PreferencesOutput::PreferencesChanged(preferences) => { Action::PreferencesChanged(preferences) } - window::PreferencesOutput::Closed => { - Action::PreferencesWindowClosed - } + window::PreferencesOutput::Closed => Action::PreferencesWindowClosed, }); model.preferences_window = Some(controller); } @@ -53,9 +51,15 @@ pub fn close(model: &mut AppModel) { pub fn reload(model: &mut AppModel) { model.preferences = storage::load(); model.apply_preferences(); - model.header.emit(HeaderAction::SetCustomStages(model.preferences.custom_stages.clone())); - model.header.emit(HeaderAction::SetCustomStages(model.preferences.custom_stages.clone())); - model.header.emit(HeaderAction::SetTemplates(model.preferences.map_templates.clone())); + model.header.emit(HeaderAction::SetCustomStages( + model.preferences.custom_stages.clone(), + )); + model.header.emit(HeaderAction::SetCustomStages( + model.preferences.custom_stages.clone(), + )); + model.header.emit(HeaderAction::SetTemplates( + model.preferences.map_templates.clone(), + )); model.update_image(); } @@ -63,8 +67,12 @@ pub fn reload(model: &mut AppModel) { pub fn update(model: &mut AppModel, preferences: UserPreferences) { model.preferences = preferences; model.apply_preferences(); - model.header.emit(HeaderAction::SetCustomStages(model.preferences.custom_stages.clone())); - model.header.emit(HeaderAction::SetTemplates(model.preferences.map_templates.clone())); + model.header.emit(HeaderAction::SetCustomStages( + model.preferences.custom_stages.clone(), + )); + model.header.emit(HeaderAction::SetTemplates( + model.preferences.map_templates.clone(), + )); model.update_image(); file_registry::broadcast_to_all_windows(&Action::ReloadPreferences); } diff --git a/src/handlers/view.rs b/src/handlers/view.rs index 87c4172..44e7e40 100644 --- a/src/handlers/view.rs +++ b/src/handlers/view.rs @@ -13,8 +13,8 @@ // 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 relm4::prelude::*; use crate::components::header::HeaderAction; +use relm4::prelude::*; use crate::AppModel; use wmap_renderer::StageType; @@ -25,7 +25,9 @@ pub fn change_orientation(model: &mut AppModel) { gtk::Orientation::Horizontal => gtk::Orientation::Vertical, _ => gtk::Orientation::Horizontal, }; - model.header.emit(HeaderAction::SetLayoutOrientation(model.orientation)); + model + .header + .emit(HeaderAction::SetLayoutOrientation(model.orientation)); } /// Updates the selected stage type from dropdown selection. @@ -37,5 +39,7 @@ pub fn stage_type_selected(model: &mut AppModel, stage_type: StageType) { /// Updates the selected stage type from dropdown selection. pub fn change_horizontal_layout(model: &mut AppModel, is_enabled: bool) { model.horizontal_layout_enabled = is_enabled; - model.header.emit(HeaderAction::SetHorizontalLayoutEnabled(is_enabled)); + model + .header + .emit(HeaderAction::SetHorizontalLayoutEnabled(is_enabled)); } diff --git a/src/handlers/zoom.rs b/src/handlers/zoom.rs index 59a54a7..84b9bd5 100644 --- a/src/handlers/zoom.rs +++ b/src/handlers/zoom.rs @@ -16,8 +16,8 @@ use relm4::prelude::*; use crate::AppModel; -use crate::constants; use crate::components::footer::FooterAction; +use crate::constants; /// Sets the zoom level and updates the rendered image. pub fn zoom(model: &mut AppModel, level: f64) { diff --git a/src/main.rs b/src/main.rs index f661df9..0115d88 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,6 +18,7 @@ #![allow(unused_assignments)] mod actions; +mod components; mod constants; mod dialogs; mod file_registry; @@ -26,7 +27,6 @@ mod i18n; mod preferences; mod stages; mod ui_helpers; -mod components; mod icon_names { #![allow(clippy::doc_markdown)] // Generated code from relm4_icons_build @@ -38,11 +38,11 @@ use std::convert::identity; use std::path::PathBuf; use crate::actions::Action; +use adw::prelude::*; use cairo::ImageSurface; use gtk::glib; -use relm4::prelude::*; use relm4::actions::{AccelsPlus, RelmAction, RelmActionGroup}; -use adw::prelude::*; +use relm4::prelude::*; use sourceview5::LanguageManager; use sourceview5::prelude::*; @@ -51,8 +51,8 @@ use stages::LocalizedStageType; use wmap_parser::{Map, parse}; use wmap_renderer::{Configuration, StageType, render_to_surface}; -use components::header::{Header, HeaderInit}; use components::footer::{Footer, FooterInit}; +use components::header::{Header, HeaderInit}; /// Macro to reduce boilerplate when registering actions with accelerators. macro_rules! register_action { @@ -107,9 +107,9 @@ impl relm4::actions::ActionName for NewFromTemplateAction { const NAME: &'static str = "new-from-template"; } - struct AppInit { zoom: f64, + orientation: gtk::Orientation, file_path: Option<PathBuf>, initial_content: Option<String>, } @@ -237,6 +237,7 @@ impl AppModel { let controller = AppModel::builder() .launch(AppInit { zoom: 1.0, + orientation: gtk::Orientation::Horizontal, file_path, initial_content, }) @@ -250,6 +251,7 @@ impl AppModel { file_registry::store_controller(controller); } + // Initialize the buffer that will be used to hold and read the source code. fn init_source_buffer( init: &AppInit, sender: &ComponentSender<Self>, @@ -283,6 +285,24 @@ impl AppModel { (source, initial_content, current_file) } + // Initializes the Source View that shows the colorized text. + fn init_source_view(source: &sourceview5::Buffer) -> (sourceview5::View, gtk::CssProvider) { + let source_view = sourceview5::View::with_buffer(source); + source_view.set_monospace(true); + + let editor_css_provider = gtk::CssProvider::new(); + source_view.add_css_class("map-editor"); + if let Some(display) = gtk::gdk::Display::default() { + gtk::style_context_add_provider_for_display( + &display, + &editor_css_provider, + gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, + ); + } + (source_view, editor_css_provider) + } + + // Initializes the drawing area that shows the rendered map. fn init_drawing_area( initial_content: &str, ) -> ( @@ -307,6 +327,28 @@ impl AppModel { (drawing_area, map, render_configuration, stage_type, surface) } + // Initializes the breakpoint logic + fn init_breakpoints(sender: &ComponentSender<Self>, root: &adw::Window) { + let breakpoint = adw::Breakpoint::new(adw::BreakpointCondition::new_length( + adw::BreakpointConditionLengthType::MinWidth, + 440.0, + adw::LengthUnit::Sp, + )); + { + let sender = sender.clone(); + breakpoint.connect_apply(move |_| { + sender.input(Action::EnableHorizontalLayout); + }); + } + + { + let sender = sender.clone(); + breakpoint.connect_unapply(move |_| { + sender.input(Action::DisableHorizontalLayout); + }); + } + root.add_breakpoint(breakpoint); + } } #[relm4::component] @@ -366,22 +408,8 @@ impl SimpleComponent for AppModel { root: Self::Root, sender: ComponentSender<Self>, ) -> ComponentParts<Self> { - let (source, initial_content, current_file) = Self::init_source_buffer(&init, &sender); - - let source_view = sourceview5::View::with_buffer(&source); - source_view.set_monospace(true); - - let editor_css_provider = gtk::CssProvider::new(); - source_view.add_css_class("map-editor"); - if let Some(display) = gtk::gdk::Display::default() { - gtk::style_context_add_provider_for_display( - &display, - &editor_css_provider, - gtk::STYLE_PROVIDER_PRIORITY_APPLICATION, - ); - } - + let (source_view, editor_css_provider) = Self::init_source_view(&source); let (drawing_area, map, render_configuration, stage_type, surface) = Self::init_drawing_area(&initial_content); @@ -391,7 +419,6 @@ impl SimpleComponent for AppModel { let preferences = preferences::storage::load(); - let orientation = gtk::Orientation::Horizontal; let horizontal_layout_enabled = false; // Actions @@ -418,14 +445,15 @@ impl SimpleComponent for AppModel { &["<Primary>l"] ); - let sender_clone = sender.clone(); - let action: RelmAction<NewFromTemplateAction> = - RelmAction::new_with_target_value(move |_, template_id| { - sender_clone.input(Action::NewFromTemplateById(template_id)); - }); - action_group.add_action(action); - action_group.register_for_widget(&root); - + { + let sender = sender.clone(); + let action: RelmAction<NewFromTemplateAction> = + RelmAction::new_with_target_value(move |_, template_id| { + sender.input(Action::NewFromTemplateById(template_id)); + }); + action_group.add_action(action); + action_group.register_for_widget(&root); + } // Child Components let header = Header::builder() @@ -433,19 +461,17 @@ impl SimpleComponent for AppModel { layout_action, custom_stages: preferences.custom_stages.clone(), templates: preferences.map_templates.clone(), - orientation, - horizontal_layout_enabled + orientation: init.orientation, + horizontal_layout_enabled, }) .forward(sender.input_sender(), identity); let footer = Footer::builder() - .launch(FooterInit { - zoom: init.zoom - }) + .launch(FooterInit { zoom: init.zoom }) .forward(sender.input_sender(), identity); let mut model = AppModel { - orientation, + orientation: init.orientation, stage_type, source, source_view: source_view.clone(), @@ -466,7 +492,7 @@ impl SimpleComponent for AppModel { editor_css_provider, horizontal_layout_enabled: true, header, - footer + footer, }; model.apply_preferences(); @@ -492,30 +518,16 @@ impl SimpleComponent for AppModel { let widgets = view_output!(); // Breakpoints for Smaller Layouts - let breakpoint = adw::Breakpoint::new( - adw::BreakpointCondition::new_length( - adw::BreakpointConditionLengthType::MinWidth, - 440.0, - adw::LengthUnit::Sp - ) - ); - let sender_clone = sender.clone(); - breakpoint.connect_apply(move |_| { - sender_clone.input(Action::EnableHorizontalLayout); - }); - let sender_clone = sender.clone(); - breakpoint.connect_unapply(move |_| { - sender_clone.input(Action::DisableHorizontalLayout); - }); - root.add_breakpoint(breakpoint); + Self::init_breakpoints(&sender, &root); ComponentParts { model, widgets } } fn update(&mut self, message: Self::Input, sender: ComponentSender<Self>) { match message { Action::ChangeOrientation => handlers::view::change_orientation(self), - Action::StageTypeSelected(stage_type) => handlers::view::stage_type_selected(self, stage_type), - + Action::StageTypeSelected(stage_type) => { + handlers::view::stage_type_selected(self, stage_type); + } Action::SourceChanged => { let pending = *self.pending_load_events.borrow(); if pending > 0 { @@ -576,13 +588,16 @@ impl SimpleComponent for AppModel { Action::MarkInitialized => self.initialized = true, // Layout Transition - Action::DisableHorizontalLayout => handlers::view::change_horizontal_layout(self, false), + Action::DisableHorizontalLayout => { + handlers::view::change_horizontal_layout(self, false); + } Action::EnableHorizontalLayout => handlers::view::change_horizontal_layout(self, true), // Preferences - Action::ShowPreferences => handlers::preferences::show(self, &sender), - Action::PreferencesChanged(preferences) => handlers::preferences::update(self, preferences), + Action::PreferencesChanged(preferences) => { + handlers::preferences::update(self, preferences); + } Action::PreferencesWindowClosed => handlers::preferences::close(self), Action::ReloadPreferences => handlers::preferences::reload(self), } @@ -604,6 +619,7 @@ fn main() { let application = RelmApp::new(constants::APP_ID); application.run::<AppModel>(AppInit { zoom: 1.0, + orientation: gtk::Orientation::Horizontal, file_path: None, initial_content, }); |