Rewrote text input

Also implemnted secure/masked input

Closes #58
This commit is contained in:
Jonathan Johnson 2023-11-16 15:34:26 -08:00
parent 1ed1a95a1d
commit c39f8f33ad
No known key found for this signature in database
GPG key ID: A66D6A34D6620579
11 changed files with 1036 additions and 393 deletions

11
Cargo.lock generated
View file

@ -831,6 +831,8 @@ dependencies = [
"pollster",
"tracing",
"tracing-subscriber",
"unicode-segmentation",
"zeroize",
]
[[package]]
@ -1087,7 +1089,7 @@ checksum = "e2db585e1d738fc771bf08a151420d3ed193d9d895a36df7f6f8a9456b911ddc"
[[package]]
name = "kludgine"
version = "0.1.0"
source = "git+https://github.com/khonsulabs/kludgine#c0135da62309896fab58a2f5b517c32cde151fb3"
source = "git+https://github.com/khonsulabs/kludgine#220df4ed07fcf86459a34591a7923d7ddb25e67e"
dependencies = [
"ahash",
"alot",
@ -1101,6 +1103,7 @@ dependencies = [
"lyon_tessellation",
"pollster",
"smallvec",
"unicode-bidi",
"wgpu",
]
@ -3152,3 +3155,9 @@ dependencies = [
"quote",
"syn",
]
[[package]]
name = "zeroize"
version = "1.7.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "525b4ec142c6b68a2d10f01f7bbf6755599ca3f81ea53b8431b7dd348f5fdb2d"

View file

@ -27,6 +27,8 @@ ahash = "0.8.6"
gooey-macros = { version = "0.1.0", path = "gooey-macros" }
derive_more = { version = "1.0.0-beta.6", features = ["from"] }
arboard = "3.2.1"
zeroize = "1.6.1"
unicode-segmentation = "1.10.1"
# [patch."https://github.com/khonsulabs/kludgine"]

View file

@ -1,7 +1,8 @@
use std::process::exit;
use gooey::value::{Dynamic, MapEach, StringValue};
use gooey::value::{Dynamic, MapEach};
use gooey::widget::{MakeWidget, MakeWidgetWithId, WidgetTag};
use gooey::widgets::input::{InputValue, MaskedString};
use gooey::widgets::Expand;
use gooey::Run;
use kludgine::figures::units::Lp;
@ -33,7 +34,6 @@ fn main() -> gooey::Result {
let password_row = "Password"
.and(
// TODO secure input
password
.clone()
.into_input()
@ -79,6 +79,6 @@ fn main() -> gooey::Result {
.run()
}
fn validate(username: &String, password: &String) -> bool {
fn validate(username: &String, password: &MaskedString) -> bool {
!username.is_empty() && !password.is_empty()
}

View file

@ -1,5 +1,6 @@
use gooey::value::{Dynamic, StringValue};
use gooey::value::Dynamic;
use gooey::widget::{MakeWidget, HANDLED, IGNORED};
use gooey::widgets::input::InputValue;
use gooey::widgets::Space;
use gooey::Run;
use kludgine::app::winit::event::ElementState;

View file

@ -1,7 +1,21 @@
use gooey::value::StringValue;
use gooey::value::Dynamic;
use gooey::widget::MakeWidget;
use gooey::widgets::input::{InputValue, MaskedString};
use gooey::Run;
use kludgine::figures::units::Px;
fn main() -> gooey::Result {
"Hello".into_input().expand().run()
let contents = Dynamic::from("Hello World");
let password = Dynamic::new(MaskedString::default());
"Text Input Field:"
.and(contents.into_input())
.and("Masked Input Field:")
.and(password.into_input())
.into_rows()
.width(Px(100)..Px(800))
.scroll()
.centered()
.expand()
.run()
}

View file

@ -1,7 +1,8 @@
use std::process::exit;
use gooey::value::{Dynamic, MapEach, StringValue};
use gooey::value::{Dynamic, MapEach};
use gooey::widget::MakeWidget;
use gooey::widgets::input::{InputValue, MaskedString};
use gooey::widgets::Expand;
use gooey::Run;
use kludgine::figures::units::Lp;
@ -58,6 +59,6 @@ fn main() -> gooey::Result {
.run()
}
fn validate(username: &String, password: &String) -> bool {
fn validate(username: &String, password: &MaskedString) -> bool {
!username.is_empty() && !password.is_empty()
}

View file

@ -1,6 +1,7 @@
use gooey::animation::{LinearInterpolate, PercentBetween};
use gooey::value::{Dynamic, StringValue};
use gooey::value::Dynamic;
use gooey::widget::MakeWidget;
use gooey::widgets::input::InputValue;
use gooey::widgets::slider::Slidable;
use gooey::Run;
use kludgine::figures::units::Lp;

View file

@ -3,8 +3,9 @@ use gooey::styles::components::{TextColor, WidgetBackground};
use gooey::styles::{
ColorScheme, ColorSource, ColorTheme, FixedTheme, SurfaceTheme, Theme, ThemePair,
};
use gooey::value::{Dynamic, MapEach, StringValue};
use gooey::value::{Dynamic, MapEach};
use gooey::widget::MakeWidget;
use gooey::widgets::input::InputValue;
use gooey::widgets::slider::Slidable;
use gooey::widgets::{Slider, Stack};
use gooey::window::ThemeMode;

View file

@ -17,7 +17,7 @@ use crate::animation::{DynamicTransition, LinearInterpolate};
use crate::context::{WidgetContext, WindowHandle};
use crate::utils::{IgnorePoison, WithClone};
use crate::widget::{WidgetId, WidgetInstance};
use crate::widgets::{Input, Switcher};
use crate::widgets::Switcher;
/// An instance of a value that provides APIs to observe and react to its
/// contents.
@ -504,6 +504,18 @@ impl<T> From<Dynamic<T>> for DynamicReader<T> {
}
}
impl From<&str> for Dynamic<String> {
fn from(value: &str) -> Self {
Dynamic::from(value.to_string())
}
}
impl From<String> for Dynamic<String> {
fn from(value: String) -> Self {
Dynamic::new(value)
}
}
#[derive(Debug)]
struct DynamicMutexGuard<'a, T> {
dynamic: &'a DynamicData<T>,
@ -1384,13 +1396,3 @@ macro_rules! impl_tuple_map_each {
}
impl_all_tuples!(impl_tuple_map_each);
/// A type that can be converted into a [`Value<String>`].
pub trait StringValue: IntoValue<String> + Sized {
/// Returns this string as a text input widget.
fn into_input(self) -> Input {
Input::new(self.into_value())
}
}
impl<T> StringValue for T where T: IntoValue<String> {}

View file

@ -6,7 +6,7 @@ mod canvas;
pub mod checkbox;
pub mod container;
mod expand;
mod input;
pub mod input;
pub mod label;
mod mode_switch;
mod resize;

File diff suppressed because it is too large Load diff