From f99165479812f1f4d2a38a7ee0ed4a7210420ab7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Maria=C5=84ski?= Date: Wed, 26 Apr 2023 23:55:42 +0200 Subject: [PATCH] misc --- cofd/app/src/component/traits.rs | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/cofd/app/src/component/traits.rs b/cofd/app/src/component/traits.rs index 2a2b7dd..dfd989e 100644 --- a/cofd/app/src/component/traits.rs +++ b/cofd/app/src/component/traits.rs @@ -6,7 +6,12 @@ use iced_lazy::Component; use cofd::{character::ArmorStruct, prelude::*}; -use crate::{fl, i18n::flt, Element, INPUT_PADDING}; +use crate::{ + fl, + i18n::flt, + widget::dots::{Shape, SheetDots}, + Element, INPUT_PADDING, +}; struct Traits { size: u16, @@ -37,7 +42,7 @@ pub fn traits_component( } #[derive(Clone)] -pub struct Event(String, Trait); +pub struct Event(u16, Trait); impl TraitsComponent { fn new(character: &Character, on_change: impl Fn(u16, Trait) -> Message + 'static) -> Self { @@ -67,22 +72,14 @@ impl Component for TraitsComponent { type Event = Event; fn update(&mut self, _state: &mut Self::State, event: Self::Event) -> Option { - if let Ok(val) = event.0.parse() { - Some((self.on_change)(val, event.1)) - } else if event.0.is_empty() { - Some((self.on_change)(0, event.1)) - } else { - None - } + Some((self.on_change)(event.0, event.1)) } fn view(&self, _state: &Self::State) -> Element { let beats = row![ text(format!("{}:", fl!("beats"))), text_input("", &format!("{}", self.traits.beats), |val| { - // if let Some(val) = val.parse() { - Event(val, Trait::Beats) - // } + Event(val.parse().unwrap_or(0), Trait::Beats) }) .padding(INPUT_PADDING) ]; @@ -94,7 +91,7 @@ impl Component for TraitsComponent { flt(&self.traits.splat, Some("beats")).unwrap() )), text_input("", &format!("{}", self.traits.alternate_beats), |val| { - Event(val, Trait::AlternateBeats) + Event(val.parse().unwrap_or(0), Trait::AlternateBeats) }) .padding(INPUT_PADDING) ]