diff --git a/Cargo.lock b/Cargo.lock index ce894c9..59d8060 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3302,9 +3302,9 @@ checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" [[package]] name = "wasm-bindgen" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a82edfc16a6c469f5f44dc7b571814045d60404b55a0ee849f9bcfa2e63dd9b5" +checksum = "128d1e363af62632b8eb57219c8fd7877144af57558fb2ef0368d0087bddeb2e" dependencies = [ "cfg-if", "once_cell", @@ -3313,9 +3313,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-backend" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9de396da306523044d3302746f1208fa71d7532227f15e347e2d93e4145dd77b" +checksum = "cb6dd4d3ca0ddffd1dd1c9c04f94b868c37ff5fac97c30b97cff2d74fce3a358" dependencies = [ "bumpalo", "log", @@ -3340,9 +3340,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "585c4c91a46b072c92e908d99cb1dcdf95c5218eeb6f3bf1efa991ee7a68cccf" +checksum = "e79384be7f8f5a9dd5d7167216f022090cf1f9ec128e6e6a482a2cb5c5422c56" dependencies = [ "quote", "wasm-bindgen-macro-support", @@ -3350,9 +3350,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-macro-support" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afc340c74d9005395cf9dd098506f7f44e38f2b4a21c6aaacf9a105ea5e1e836" +checksum = "26c6ab57572f7a24a4985830b120de1594465e5d500f24afe89e16b4e833ef68" dependencies = [ "proc-macro2", "quote", @@ -3363,9 +3363,9 @@ dependencies = [ [[package]] name = "wasm-bindgen-shared" -version = "0.2.93" +version = "0.2.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c62a0a307cb4a311d3a07867860911ca130c3494e8c2719593806c08bc5d0484" +checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d" [[package]] name = "wasm-timer" diff --git a/Cargo.toml b/Cargo.toml index d3a322d..a929b05 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -160,3 +160,6 @@ required-features = ["number_input"] [[example]] name = "wrap" required-features = ["wrap", "number_input"] + +[lib] +crate-type = ["cdylib", "rlib"] \ No newline at end of file diff --git a/examples/number_input.rs b/examples/number_input.rs index 2ad181f..bb17d0a 100644 --- a/examples/number_input.rs +++ b/examples/number_input.rs @@ -37,6 +37,9 @@ impl NumberInputDemo { if let Message::NumInpChanged(Ok(val)) = message { println!("Value changed to {:?}", val); self.value = val; + } else if let Message::NumInpChanged(Err(_)) = message { + println!("Error Value reset to 0.0"); + self.value = 0.0; } } diff --git a/src/widget/typed_input.rs b/src/widget/typed_input.rs index bf8d714..7ad578e 100644 --- a/src/widget/typed_input.rs +++ b/src/widget/typed_input.rs @@ -347,6 +347,11 @@ where match message { InternalMessage::OnChange(value) => { self.text = value; + + if self.text.ends_with('.') { + self.text.push('0'); + } + let value = match T::from_str(&self.text) { Ok(val) if self.value != val => { self.value = val.clone(); @@ -364,6 +369,10 @@ where } InternalMessage::OnSubmit => { if let Some(on_submit) = &self.on_submit { + if self.text.ends_with('.') { + self.text.push('0'); + } + let value = match T::from_str(&self.text) { Ok(v) => Ok(v), Err(_) => Err(self.text.clone()), @@ -374,6 +383,10 @@ where InternalMessage::OnPaste(value) => { self.text = value; + if self.text.ends_with('.') { + self.text.push('0'); + } + let value = match T::from_str(&self.text) { Ok(val) if self.value != val => { self.value = val.clone();