From fe49ae116e6308e335492504bc76a0ebb6d70a10 Mon Sep 17 00:00:00 2001 From: m00nwtchr Date: Wed, 31 Jul 2024 17:53:41 +0200 Subject: [PATCH] Clippy/fmt --- rustfmt.toml | 4 +++- src/component/attributes.rs | 16 +++++++++------- src/component/forms.rs | 5 +++-- src/component/info.rs | 26 +++++++++++++------------- src/component/integrity.rs | 14 +++++++------- src/component/list.rs | 3 +-- src/component/merits.rs | 16 ++++++---------- src/component/mod.rs | 1 - src/component/skills.rs | 25 ++++++++++++++----------- src/component/traits.rs | 6 +++--- src/i18n.rs | 34 +++++++++++++++++----------------- src/main.rs | 23 +++++++++++------------ src/view/character_list.rs | 11 +++++++++-- src/view/creator.rs | 21 ++++++++------------- src/view/equipment.rs | 8 ++------ src/view/mod.rs | 3 +-- src/view/overview.rs | 31 +++++++++++++++---------------- src/view/sheet.rs | 15 +++++++++++---- src/view/splat_extras.rs | 20 +++++++++----------- src/widget/dots.rs | 18 +++++++++++------- src/widget/track.rs | 18 +++++++++++------- 21 files changed, 164 insertions(+), 154 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 18d655e..cb260d3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1 +1,3 @@ -hard_tabs = true \ No newline at end of file +hard_tabs = true +imports_granularity = "Crate" +group_imports = "StdExternalCrate" \ No newline at end of file diff --git a/src/component/attributes.rs b/src/component/attributes.rs index 6603dce..d2f2223 100644 --- a/src/component/attributes.rs +++ b/src/component/attributes.rs @@ -1,13 +1,15 @@ +use cofd::{ + character::modifier::ModifierTarget, + prelude::{TraitCategory, *}, +}; use iced::{ widget::{column, row, text, Column}, Alignment, Length, }; -use cofd::{character::modifier::ModifierTarget, prelude::TraitCategory, prelude::*}; - -use crate::i18n::Translate; use crate::{ fl, + i18n::Translate, widget::dots::{Shape, SheetDots}, Element, H2_SIZE, TITLE_SPACING, }; @@ -15,7 +17,7 @@ use crate::{ #[derive(Debug, Clone)] pub struct AttributeBar; -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct Message(u16, Attribute); impl AttributeBar { @@ -40,9 +42,9 @@ impl AttributeBar { .spacing(3) .width(Length::Fill) .align_items(Alignment::End), - self.mk_attr_col(&character, TraitCategory::Mental), - self.mk_attr_col(&character, TraitCategory::Physical), - self.mk_attr_col(&character, TraitCategory::Social), + self.mk_attr_col(character, TraitCategory::Mental), + self.mk_attr_col(character, TraitCategory::Physical), + self.mk_attr_col(character, TraitCategory::Social), column![].width(Length::Fill) ] .spacing(10) diff --git a/src/component/forms.rs b/src/component/forms.rs index 38b6e59..a2622d2 100644 --- a/src/component/forms.rs +++ b/src/component/forms.rs @@ -1,4 +1,3 @@ -use crate::{fl, i18n::Translate, Element, INPUT_PADDING}; use cofd::{ character::modifier::ModifierTarget, prelude::*, @@ -14,6 +13,8 @@ use iced::{ Length, }; +use crate::{i18n::Translate, Element, INPUT_PADDING}; + #[derive(Debug, Clone)] pub struct FormsComponent; @@ -46,7 +47,7 @@ impl FormsComponent { if let Splat::Werewolf(..) = &character.splat { for form in Form::all() { - row = row.push(self.mk_col(form, &character)); + row = row.push(self.mk_col(form, character)); } } diff --git a/src/component/info.rs b/src/component/info.rs index 5da8d55..9663d0c 100644 --- a/src/component/info.rs +++ b/src/component/info.rs @@ -1,18 +1,18 @@ -use iced::widget::{component, container, scrollable, Component}; +use cofd::{ + character::InfoTrait, + prelude::*, + splat::{Splat, SplatTrait, XSplat, YSplat, ZSplat}, +}; use iced::{ widget::{column, pick_list, row, text, text_input, Column}, Alignment, Length, }; -use std::{cell::RefCell, rc::Rc}; -use crate::i18n::{Translate, Translated}; -use crate::{fl, i18n, Element, INPUT_PADDING}; -use cofd::{ - character::InfoTrait, - prelude::*, - splat::{Splat, SplatTrait, XSplat, YSplat, ZSplat}, +use crate::{ + fl, i18n, + i18n::{Translate, Translated}, + Element, INPUT_PADDING, }; -use iced::overlay::menu; #[derive(Debug, Clone)] pub struct InfoBar; @@ -69,7 +69,7 @@ impl InfoBar { let col3: Element = match character.splat { Splat::Mortal(..) => self.mk_info_col( vec![InfoTrait::Age, InfoTrait::Faction, InfoTrait::GroupName], - &character, + character, ), _ => { let mut xsplats = character.splat.xsplats(); @@ -208,7 +208,7 @@ impl InfoBar { row![ self.mk_info_col( vec![InfoTrait::Name, InfoTrait::Player, InfoTrait::Chronicle], - &character + character ), self.mk_info_col( vec![ @@ -216,7 +216,7 @@ impl InfoBar { InfoTrait::ViceAnchor, InfoTrait::Concept ], - &character + character ), col3, ] @@ -239,7 +239,7 @@ impl InfoBar { _ => _trait.translated(), }; - col1 = col1.push(text(format!("{}:", str))); + col1 = col1.push(text(format!("{str}:"))); col2 = col2.push( text_input("", character.info.get(_trait)) .on_input(move |val| Message::InfoTraitChanged(val, _trait)) diff --git a/src/component/integrity.rs b/src/component/integrity.rs index 0efc02f..8e18f80 100644 --- a/src/component/integrity.rs +++ b/src/component/integrity.rs @@ -1,8 +1,13 @@ +use cofd::{character::Wound, prelude::*, splat::Splat}; +use iced::{ + widget::{column, row, text, text_input, Column}, + Alignment, Length, +}; + use super::list; -use crate::i18n::Translate; -use crate::widget::{dots, track}; use crate::{ fl, + i18n::Translate, widget::{ self, dots::{Shape, SheetDots}, @@ -10,11 +15,6 @@ use crate::{ }, Element, COMPONENT_SPACING, H3_SIZE, INPUT_PADDING, MAX_INPUT_WIDTH, TITLE_SPACING, }; -use cofd::{character::Wound, prelude::*, splat::Splat}; -use iced::{ - widget::{column, row, text, text_input, Column}, - Alignment, Length, -}; #[derive(Debug, Clone)] pub struct IntegrityComponent; diff --git a/src/component/list.rs b/src/component/list.rs index 92f5872..7631013 100644 --- a/src/component/list.rs +++ b/src/component/list.rs @@ -1,6 +1,5 @@ -use iced::widget::{component, Component}; use iced::{ - widget::{text, Column}, + widget::{component, text, Column, Component}, Alignment, Element, Pixels, }; diff --git a/src/component/merits.rs b/src/component/merits.rs index 4e66ad1..67a7803 100644 --- a/src/component/merits.rs +++ b/src/component/merits.rs @@ -1,22 +1,18 @@ +use cofd::{ + prelude::*, + splat::{Merit, SplatTrait}, +}; use iced::{ widget::{column, pick_list, row, text, text_input, Column}, Alignment, Length, }; -use std::{cell::RefCell, rc::Rc}; -use crate::i18n::Translated; -use crate::widget::dots; use crate::{ fl, i18n, - i18n::Translate, + i18n::Translated, widget::dots::{Shape, SheetDots}, Element, H3_SIZE, INPUT_PADDING, TITLE_SPACING, }; -use cofd::{ - prelude::*, - splat::{Merit, SplatTrait}, -}; -use iced::widget::{component, container, overlay, scrollable, Component}; #[derive(Debug, Clone)] pub struct MeritComponent; @@ -96,7 +92,7 @@ impl MeritComponent { .merits .iter() .filter(|(merit, _)| *merit == *e) - .count() == 0 && e.is_available(&character, attributes, skills) + .count() == 0 && e.is_available(character, attributes, skills) }) .cloned() .map(Into::into) diff --git a/src/component/mod.rs b/src/component/mod.rs index a4f14cd..c3762cd 100644 --- a/src/component/mod.rs +++ b/src/component/mod.rs @@ -9,7 +9,6 @@ mod traits; pub use attributes::AttributeBar; pub use forms::FormsComponent; -pub use info::InfoBar; pub use integrity::IntegrityComponent; pub use list::list; pub use merits::MeritComponent; diff --git a/src/component/skills.rs b/src/component/skills.rs index 703378e..0b223d9 100644 --- a/src/component/skills.rs +++ b/src/component/skills.rs @@ -1,8 +1,11 @@ -use std::{cell::RefCell, rc::Rc}; - -use cofd::splat::mage::{Mage, Ministry, Order}; -use cofd::{character::modifier::ModifierTarget, prelude::*, splat::Splat}; -use iced::widget::{component, Component}; +use cofd::{ + character::modifier::ModifierTarget, + prelude::*, + splat::{ + mage::{Mage, Ministry, Order}, + Splat, + }, +}; use iced::{ theme::{self}, widget::{button, checkbox, column, row, text, text_input, Column}, @@ -10,11 +13,11 @@ use iced::{ }; use super::list; -use crate::i18n::Translate; -use crate::view::overview::vec_changed; use crate::{ fl, - widget::dots::{self, Shape, SheetDots}, + i18n::Translate, + view::overview::vec_changed, + widget::dots::{Shape, SheetDots}, H2_SIZE, H3_SIZE, TITLE_SPACING, }; @@ -83,9 +86,9 @@ impl SkillsComponent { pub fn view(&self, character: &Character) -> Element { column![ text(fl!("skills").to_uppercase()).size(H2_SIZE), - self.mk_skill_col(&character, TraitCategory::Mental), - self.mk_skill_col(&character, TraitCategory::Physical), - self.mk_skill_col(&character, TraitCategory::Social), + self.mk_skill_col(character, TraitCategory::Mental), + self.mk_skill_col(character, TraitCategory::Physical), + self.mk_skill_col(character, TraitCategory::Social), ] .spacing(10) // .padding(15) diff --git a/src/component/traits.rs b/src/component/traits.rs index 90567a0..5303c7c 100644 --- a/src/component/traits.rs +++ b/src/component/traits.rs @@ -1,11 +1,11 @@ -use crate::{fl, Element, INPUT_PADDING}; use cofd::{character::ArmorStruct, prelude::*}; -use iced::widget::{component, Component}; use iced::{ - widget::{column, row, text, text_input}, + widget::{column, component, row, text, text_input, Component}, Length, }; +use crate::{fl, Element, INPUT_PADDING}; + struct Traits { size: u16, speed: u16, diff --git a/src/i18n.rs b/src/i18n.rs index 04fe3d6..3d275f8 100644 --- a/src/i18n.rs +++ b/src/i18n.rs @@ -1,16 +1,22 @@ -use cofd::prelude::{Template, VariantName}; -use cofd::splat::ability::Ability; -use cofd::splat::changeling::Regalia; -use cofd::splat::werewolf::{HuntersAspect, KuruthTriggers, MoonGift, Rite, ShadowGift, WolfGift}; -use cofd::splat::{Merit, NameKey, Splat, SplatKind, XSplat, YSplat, ZSplat}; -use cofd::template::mage::Arcanum; -use cofd::template::SupernaturalTolerance; -use cofd::traits::TraitCategory; +use std::{ + fmt::{ + Display, {self}, + }, + ops::Deref, + sync::Arc, +}; + use cofd::{ character::InfoTrait, - splat::werewolf::Form, - template::{Anchor, Fuel, Integrity}, - traits::{attribute::Attribute, skill::Skill, Trait}, + prelude::{Template, VariantName}, + splat::{ + ability::Ability, + changeling::Regalia, + werewolf::{Form, HuntersAspect, KuruthTriggers, MoonGift, Rite, ShadowGift, WolfGift}, + Merit, Splat, SplatKind, XSplat, YSplat, ZSplat, + }, + template::{mage::Arcanum, Anchor, Fuel, Integrity, SupernaturalTolerance}, + traits::{attribute::Attribute, skill::Skill, Trait, TraitCategory}, }; use i18n_embed::{ fluent::{fluent_language_loader, FluentLanguageLoader}, @@ -18,12 +24,6 @@ use i18n_embed::{ }; use once_cell::sync::Lazy; use rust_embed::RustEmbed; -use std::fmt::Display; -use std::ops::Deref; -use std::{ - fmt::{self}, - sync::Arc, -}; #[derive(RustEmbed)] #[folder = "i18n"] // path to the compiled localization resources diff --git a/src/main.rs b/src/main.rs index 60381d0..a7b3f03 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,17 +11,19 @@ clippy::default_trait_access )] +use std::{ + fmt::{Debug, Formatter}, + mem, +}; + use cofd::prelude::*; use iced::{ executor, - widget::{button, column, row, Column}, - Alignment, Application, Command, Element, Length, Settings, Size, Theme, + widget::{button, column}, + Alignment, Application, Command, Element, Length, Settings, Theme, }; #[cfg(target_arch = "wasm32")] use log::Level; -use std::cell::{Ref, RefMut}; -use std::fmt::{Debug, Formatter}; -use std::{cell::RefCell, mem, rc::Rc}; mod component; mod i18n; @@ -29,11 +31,10 @@ mod store; mod view; mod widget; -use crate::view::character_list::CharacterList; -use crate::view::sheet::SheetView; -use crate::view::*; use store::Store; +use crate::view::{character_list::CharacterList, sheet::SheetView, *}; + const H2_SIZE: u16 = 25; const H3_SIZE: u16 = 20; @@ -188,8 +189,7 @@ impl Application for PlayerCompanionApp { #[cfg(target_arch = "wasm32")] { - use iced::window; - use iced::window::Id; + use iced::{window, window::Id}; let window = web_sys::window().unwrap(); let (width, height) = ( window.inner_width().unwrap().as_f64().unwrap() as f32, @@ -238,7 +238,7 @@ mod demo { use cofd::{ character::CharacterInfo, prelude::*, - splat::{changeling::*, geist::*, mage::*, vampire::*, werewolf::*, Merit, Splat}, + splat::{changeling::*, geist::*, mage::*, vampire::*, werewolf::*, Merit}, }; #[allow(unused_imports)] @@ -569,7 +569,6 @@ mod demo { presence: 2, manipulation: 3, composure: 2, - ..Default::default() }) .with_skills(Skills { academics: 1, diff --git a/src/view/character_list.rs b/src/view/character_list.rs index 8b9e96d..169af25 100644 --- a/src/view/character_list.rs +++ b/src/view/character_list.rs @@ -1,12 +1,13 @@ use std::fmt::Write; -use crate::i18n::Translate; use cofd::prelude::*; use iced::{ - widget::{button, column, row, Column, text}, + widget::{button, column, row, text, Column}, Alignment, Element, Length, }; +use crate::i18n::Translate; + pub struct CharacterList; pub enum Action { @@ -18,6 +19,12 @@ pub enum Message { PickCharacter(usize), } +impl Default for CharacterList { + fn default() -> Self { + Self::new() + } +} + impl CharacterList { pub fn new() -> Self { Self diff --git a/src/view/creator.rs b/src/view/creator.rs index 064fe12..b2bbf62 100644 --- a/src/view/creator.rs +++ b/src/view/creator.rs @@ -1,14 +1,12 @@ -use crate::i18n::Translated; -use crate::{i18n::Translate, INPUT_PADDING}; -use cofd::splat::SplatKind; -use cofd::{prelude::*, splat::Splat}; -use iced::overlay::menu; -use iced::widget::{container, scrollable}; +use cofd::{prelude::*, splat::SplatKind}; use iced::{ - widget::{button, column, component, pick_list, row, text, Component}, + overlay::menu, + widget::{button, column, component, container, pick_list, row, scrollable, text, Component}, Element, Length, }; +use crate::{i18n::Translated, INPUT_PADDING}; + pub struct CreatorView { on_done: Box Message>, splat: SplatKind, @@ -43,13 +41,10 @@ impl CreatorView { + 'static, ::Style: From<::Style>, { - let splats: Vec> = SplatKind::all() - .into_iter() - .copied() - .map(Into::into) - .collect(); + let splats: Vec> = + SplatKind::all().iter().copied().map(Into::into).collect(); - let splat: Translated = self.splat.clone().into(); + let splat: Translated = self.splat.into(); pick_list(splats, Some(splat), |val| Event::SplatChanged(val.unwrap())) .padding(INPUT_PADDING) .width(Length::Fill) diff --git a/src/view/equipment.rs b/src/view/equipment.rs index 3e995cc..4944894 100644 --- a/src/view/equipment.rs +++ b/src/view/equipment.rs @@ -1,16 +1,12 @@ -use super::overview::vec_changed; -use crate::{Element, H2_SIZE, TITLE_SPACING}; use closure::closure; use cofd::{character::Weapon, prelude::*}; -use iced::widget::{component, Component}; use iced::{ widget::{column, row, text, text_input}, Alignment, Length, }; -use std::cell::{Ref, RefMut}; -use std::{cell::RefCell, marker::PhantomData, rc::Rc}; -use crate::fl; +use super::overview::vec_changed; +use crate::{fl, Element, H2_SIZE, TITLE_SPACING}; #[derive(Debug, Clone)] pub struct EquipmentTab; diff --git a/src/view/mod.rs b/src/view/mod.rs index 6341e9f..f300543 100644 --- a/src/view/mod.rs +++ b/src/view/mod.rs @@ -2,10 +2,9 @@ pub mod character_list; pub mod creator; pub mod equipment; pub mod overview; -pub mod splat_extras; pub mod sheet; +pub mod splat_extras; -pub use character_list::CharacterList; pub use creator::creator_view; // pub use equipment::EquipmentTab; // pub use overview::OverviewTab; diff --git a/src/view/overview.rs b/src/view/overview.rs index df0a02e..a94dd6d 100644 --- a/src/view/overview.rs +++ b/src/view/overview.rs @@ -1,35 +1,34 @@ use closure::closure; -use cofd::splat::mage::Mage; -use cofd::splat::werewolf::Auspice; -use cofd::traits::DerivedTrait; use cofd::{ character::Wound, prelude::*, splat::{ ability::Ability, changeling::Regalia, - mage::{Ministry, Order}, - werewolf::{HuntersAspect, KuruthTrigger, KuruthTriggerSet, KuruthTriggers, Tribe}, - Merit, Splat, + werewolf::{ + Auspice, HuntersAspect, KuruthTrigger, KuruthTriggerSet, KuruthTriggers, Tribe, + }, + Splat, }, + traits::DerivedTrait, }; -use iced::widget::{button, container, scrollable}; use iced::{ theme, - widget::{column, component, pick_list, row, text, text_input, Column, Component}, + widget::{column, pick_list, row, text, text_input, Column}, Alignment, Element, Length, }; -use crate::component::info::InfoBar; -use crate::component::{ - attributes, info, integrity, merits, skills, AttributeBar, MeritComponent, SkillsComponent, -}; -use crate::i18n::Translated; use crate::{ - component::{list, traits_component, IntegrityComponent}, + component::{ + attributes, info, info::InfoBar, integrity, list, merits, skills, traits_component, + AttributeBar, IntegrityComponent, MeritComponent, SkillsComponent, + }, fl, i18n, - i18n::Translate, - widget::{dots, dots::Shape, dots::SheetDots, track, track::HealthTrack}, + i18n::{Translate, Translated}, + widget::{ + dots::{Shape, SheetDots}, + track::HealthTrack, + }, COMPONENT_SPACING, H2_SIZE, H3_SIZE, INPUT_PADDING, MAX_INPUT_WIDTH, TITLE_SPACING, }; diff --git a/src/view/sheet.rs b/src/view/sheet.rs index 3952c90..286794d 100644 --- a/src/view/sheet.rs +++ b/src/view/sheet.rs @@ -1,9 +1,10 @@ -use std::cell::{Ref, RefMut}; +use cofd::character::Character; +use iced::{ + widget::{button, column, row}, + Element, Length, +}; use super::*; -use cofd::character::Character; -use iced::widget::{button, column, row, Column, Component}; -use iced::{Element, Length}; #[derive(Debug, Clone)] pub enum Tab { @@ -31,6 +32,12 @@ pub enum Message { SelectSplatExtras, } +impl Default for SheetView { + fn default() -> Self { + Self::new() + } +} + impl SheetView { pub fn new() -> Self { Self { diff --git a/src/view/splat_extras.rs b/src/view/splat_extras.rs index 25181be..61cb36b 100644 --- a/src/view/splat_extras.rs +++ b/src/view/splat_extras.rs @@ -1,12 +1,3 @@ -use crate::component::{forms, list, FormsComponent}; -use crate::i18n::Translated; -use crate::widget::dots; -use crate::{ - fl, - i18n::Translate, - widget::dots::{Shape, SheetDots}, - Element, H2_SIZE, H3_SIZE, INPUT_PADDING, TITLE_SPACING, -}; use cofd::{ prelude::*, splat::{ @@ -16,12 +7,19 @@ use cofd::{ Splat, }, }; -use iced::widget::{button, component, container, overlay, scrollable, Component}; use iced::{ widget::{checkbox, column, pick_list, row, text, text_input, Column}, Alignment, Length, }; +use crate::{ + component::{forms, list, FormsComponent}, + fl, + i18n::{Translate, Translated}, + widget::dots::{Shape, SheetDots}, + Element, H2_SIZE, H3_SIZE, INPUT_PADDING, TITLE_SPACING, +}; + fn func( c: C, f: impl Fn(&mut C, T), @@ -258,7 +256,7 @@ impl SplatExtrasTab { arcanum = arcanum.push( pick_list( arcana.clone(), - Some::>(rote.arcanum.clone().into()), + Some::>(rote.arcanum.into()), func( rote.clone(), |rote, val: Translated| rote.arcanum = val.unwrap(), diff --git a/src/widget/dots.rs b/src/widget/dots.rs index f5b97ca..3acb7d8 100644 --- a/src/widget/dots.rs +++ b/src/widget/dots.rs @@ -1,12 +1,16 @@ -use std::array; use std::default::Default; -use iced::advanced::layout::{self, Layout, Limits, Node}; -use iced::advanced::widget::{self, Widget}; -use iced::advanced::{renderer, Clipboard, Shell}; -use iced::widget::{text, Column, Row}; -use iced::{event, touch, Background, Padding, Point, Theme}; -use iced::{mouse, Alignment, Border, Color, Element, Length, Rectangle, Size}; +use iced::{ + advanced::{ + layout::{self, Layout, Limits, Node}, + renderer, + widget::{self, Widget}, + Clipboard, Shell, + }, + event, mouse, touch, + widget::text, + Background, Border, Color, Element, Length, Point, Rectangle, Size, Theme, +}; pub struct SheetDots<'a, Message, Theme = iced::Theme> where diff --git a/src/widget/track.rs b/src/widget/track.rs index a72c8ff..9861118 100644 --- a/src/widget/track.rs +++ b/src/widget/track.rs @@ -1,13 +1,17 @@ use std::default::Default; -use iced::advanced::layout::{self, Layout, Node}; -use iced::advanced::widget::{self, Widget}; -use iced::advanced::{renderer, Clipboard, Shell}; -use iced::widget::{text, Column, Row}; -use iced::{event, touch, Background, Point, Theme}; -use iced::{mouse, Alignment, Border, Color, Element, Length, Rectangle, Size}; - use cofd::character::{Damage, Wound}; +use iced::{ + advanced::{ + layout::{self, Layout, Node}, + renderer, + widget::{self, Widget}, + Clipboard, Shell, + }, + event, mouse, touch, + widget::text, + Background, Border, Color, Element, Length, Point, Rectangle, Size, Theme, +}; pub struct HealthTrack<'a, Message, Theme> where