From 2ca91dbc44ed6df259fe6269c63d635060be9042 Mon Sep 17 00:00:00 2001 From: Chris Cochrun Date: Thu, 12 Feb 2026 15:48:43 -0600 Subject: [PATCH] some clippy stuff --- src/core/songs.rs | 52 +++++++++++++++++++++---------------------- src/main.rs | 7 +++--- src/ui/presenter.rs | 5 ++--- src/ui/song_editor.rs | 47 ++++++++++++++++---------------------- src/ui/text_svg.rs | 18 ++++++++------- 5 files changed, 61 insertions(+), 68 deletions(-) diff --git a/src/core/songs.rs b/src/core/songs.rs index a0d3a05..7ed444f 100644 --- a/src/core/songs.rs +++ b/src/core/songs.rs @@ -80,7 +80,7 @@ pub enum VerseName { } impl VerseName { - #[must_use] + #[must_use] pub fn from_string(name: String) -> Self { match name.as_str() { "Verse" => Self::Verse { number: 1 }, @@ -97,7 +97,7 @@ impl VerseName { } } - #[must_use] + #[must_use] pub fn all_names() -> Vec { vec![ "Verse".into(), @@ -113,7 +113,7 @@ impl VerseName { ] } - #[must_use] + #[must_use] pub fn next(&self) -> Self { match self { Self::Verse { number } => { @@ -289,15 +289,13 @@ impl ServiceTrait for Song { let slides: Vec = lyrics .iter() .filter_map(|l| { - let font = - Font::default() - .name( - self.font - .clone() - .unwrap_or_else(|| "Calibri".into()), - ) - .size(self.font_size.unwrap_or(100) - as u8); + let font = Font::default() + .name( + self.font + .clone() + .unwrap_or_else(|| "Calibri".into()), + ) + .size(self.font_size.unwrap_or(100) as u8); let stroke_size = self.stroke_size.unwrap_or_default(); let stroke: Stroke = stroke( @@ -901,18 +899,21 @@ pub async fn update_song_in_db( }); let lyrics = ron::ser::to_string(&lyrics).into_diagnostic()?; - let (vertical_alignment, horizontal_alignment) = item - .text_alignment.map_or_else(|| ("center", "center"), |ta| match ta { - TextAlignment::TopLeft => ("top", "left"), - TextAlignment::TopCenter => ("top", "center"), - TextAlignment::TopRight => ("top", "right"), - TextAlignment::MiddleLeft => ("center", "left"), - TextAlignment::MiddleCenter => ("center", "center"), - TextAlignment::MiddleRight => ("center", "right"), - TextAlignment::BottomLeft => ("bottom", "left"), - TextAlignment::BottomCenter => ("bottom", "center"), - TextAlignment::BottomRight => ("bottom", "right"), - }); + let (vertical_alignment, horizontal_alignment) = + item.text_alignment.map_or_else( + || ("center", "center"), + |ta| match ta { + TextAlignment::TopLeft => ("top", "left"), + TextAlignment::TopCenter => ("top", "center"), + TextAlignment::TopRight => ("top", "right"), + TextAlignment::MiddleLeft => ("center", "left"), + TextAlignment::MiddleCenter => ("center", "center"), + TextAlignment::MiddleRight => ("center", "right"), + TextAlignment::BottomLeft => ("bottom", "left"), + TextAlignment::BottomCenter => ("bottom", "center"), + TextAlignment::BottomRight => ("bottom", "right"), + }, + ); let stroke_size = item.stroke_size.unwrap_or_default(); let shadow_size = item.shadow_size.unwrap_or_default(); @@ -966,7 +967,6 @@ pub async fn update_song_in_db( impl Song { #[must_use] pub fn get_lyric(&self, verse: &VerseName) -> Option { - self.verse_map.as_ref().and_then(|verse_map| { verse_map.get(verse).cloned().map(|lyric| { lyric.trim().trim_end_matches('\n').to_string() @@ -1184,7 +1184,7 @@ impl Song { } } - #[must_use] + #[must_use] pub fn get_next_verse_name(&self) -> VerseName { if let Some(verse_names) = &self.verses { let verses: Vec<&VerseName> = verse_names diff --git a/src/main.rs b/src/main.rs index 5bcfcd6..496210a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1512,14 +1512,15 @@ impl cosmic::Application for App { } Message::Save => { let service = self.service.clone(); - let file = self.file.clone(); + let file1 = self.file.clone(); + let file2 = self.file.clone(); Task::perform( - file::save(service, file.clone()), + async move { file::save(service, file1) }, move |res| match res { Ok(()) => { tracing::info!( "saving file to: {:?}", - file + file2 ); cosmic::Action::None } diff --git a/src/ui/presenter.rs b/src/ui/presenter.rs index 428b15d..5821c91 100644 --- a/src/ui/presenter.rs +++ b/src/ui/presenter.rs @@ -23,9 +23,8 @@ use cosmic::{ }, prelude::*, widget::{ - Container, Id, Row, Space, container, - context_menu, image, menu, mouse_area, responsive, - scrollable, text, + Container, Id, Row, Space, container, context_menu, image, + menu, mouse_area, responsive, scrollable, text, }, }; use iced_video_player::{Position, Video, VideoPlayer, gst_pbutils}; diff --git a/src/ui/song_editor.rs b/src/ui/song_editor.rs index cc23ec8..531a4a7 100644 --- a/src/ui/song_editor.rs +++ b/src/ui/song_editor.rs @@ -478,8 +478,7 @@ impl SongEditor { ) => { if let Some(mut song) = self.song.clone() { - let old_verse_name = - verse.verse_name; + let old_verse_name = verse.verse_name; let verse_name = song .verse_name_from_str( @@ -530,9 +529,9 @@ impl SongEditor { inner_verse.verse_name == verse }) - { - verses.remove(verse); - } + { + verses.remove(verse); + } return Action::Task( self.update_song(song), ); @@ -1148,10 +1147,8 @@ impl SongEditor { )) }; - let selected_font = self - .song - .as_ref() - .and_then(|song| song.font.as_ref()); + let selected_font = + self.song.as_ref().and_then(|song| song.font.as_ref()); let font_selector = tooltip( stack![ @@ -1183,10 +1180,10 @@ impl SongEditor { ) .gap(10); - let selected_font_size = self - .song - .as_ref() - .and_then(|song| song.font_size.map(|size| size.to_string())); + let selected_font_size = + self.song.as_ref().and_then(|song| { + song.font_size.map(|size| size.to_string()) + }); let font_size = tooltip( stack![ @@ -1361,11 +1358,9 @@ impl SongEditor { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", ], - self.song - .as_ref() - .and_then(|song| { - song.shadow_size.map(|size| size as usize) - }), + self.song.as_ref().and_then(|song| { + song.shadow_size.map(|size| size as usize) + }), |i| Message::UpdateShadowSize(i as u16), ) .gap(5.0); @@ -1376,11 +1371,9 @@ impl SongEditor { "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ], - self.song - .as_ref() - .and_then(|song| { - song.shadow_offset.map(|offset| offset.0 as usize) - }), + self.song.as_ref().and_then(|song| { + song.shadow_offset.map(|offset| offset.0 as usize) + }), |i| Message::UpdateShadowOffsetX(i as i16), ) .gap(5.0); @@ -1391,11 +1384,9 @@ impl SongEditor { "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", ], - self.song - .as_ref() - .and_then(|song| { - song.shadow_offset.map(|offset| offset.1 as usize) - }), + self.song.as_ref().and_then(|song| { + song.shadow_offset.map(|offset| offset.1 as usize) + }), |i| Message::UpdateShadowOffsetY(i as i16), ) .gap(5.0); diff --git a/src/ui/text_svg.rs b/src/ui/text_svg.rs index 2f86258..c8842da 100644 --- a/src/ui/text_svg.rs +++ b/src/ui/text_svg.rs @@ -175,7 +175,7 @@ impl Hash for Color { } impl Color { - #[must_use] + #[must_use] pub fn to_css_hex_string(&self) -> String { format!("#{:x}", self.0.into_format::()) } @@ -334,15 +334,18 @@ impl TextSvg { ("end", position, x_width_padded.as_str()) } TextAlignment::BottomLeft => { - let position = (total_lines as f32).mul_add(-text_and_line_spacing, size.height); + let position = (total_lines as f32) + .mul_add(-text_and_line_spacing, size.height); ("start", position, "10") } TextAlignment::BottomCenter => { - let position = (total_lines as f32).mul_add(-text_and_line_spacing, size.height); + let position = (total_lines as f32) + .mul_add(-text_and_line_spacing, size.height); ("middle", position, center_y.as_str()) } TextAlignment::BottomRight => { - let position = (total_lines as f32).mul_add(-text_and_line_spacing, size.height); + let position = (total_lines as f32) + .mul_add(-text_and_line_spacing, size.height); ("end", position, x_width_padded.as_str()) } }; @@ -439,10 +442,9 @@ impl TextSvg { resvg::render(&resvg_tree, transform, &mut pixmap.as_mut()); // debug!("rendered"); - if cache - && let Err(e) = pixmap.save_png(&path) { - error!(?e, "Couldn't save a copy of the text"); - } + if cache && let Err(e) = pixmap.save_png(&path) { + error!(?e, "Couldn't save a copy of the text"); + } // debug!("saved"); // let handle = Handle::from_path(path);