Skip to content

Commit

Permalink
Rewrote text input
Browse files Browse the repository at this point in the history
Also implemnted secure/masked input

Closes #58
  • Loading branch information
ecton committed Nov 16, 2023
1 parent 1ed1a95 commit c39f8f3
Show file tree
Hide file tree
Showing 11 changed files with 1,031 additions and 388 deletions.
11 changes: 10 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
6 changes: 3 additions & 3 deletions examples/focus-order.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -33,7 +34,6 @@ fn main() -> gooey::Result {

let password_row = "Password"
.and(
// TODO secure input
password
.clone()
.into_input()
Expand Down Expand Up @@ -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()
}
3 changes: 2 additions & 1 deletion examples/gameui.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
18 changes: 16 additions & 2 deletions examples/input.rs
Original file line number Diff line number Diff line change
@@ -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()
}
5 changes: 3 additions & 2 deletions examples/login.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
}
3 changes: 2 additions & 1 deletion examples/slider.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
3 changes: 2 additions & 1 deletion examples/theme.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
24 changes: 13 additions & 11 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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>,
Expand Down Expand Up @@ -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> {}
2 changes: 1 addition & 1 deletion src/widgets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit c39f8f3

Please sign in to comment.