diff options
author | 2019-12-08 06:42:39 +0100 | |
---|---|---|
committer | 2019-12-08 06:42:39 +0100 | |
commit | f942fc3b68ecbbe136c54922109c7e2e4732735b (patch) | |
tree | 6463a16eabb455744d5fa17bd724701ef5345fd4 /examples | |
parent | f5d316490898d4a5a27d9f5f9bb68796f5278c70 (diff) | |
parent | a7694e0112d45cffa0d25e3f19fc0289c3804c47 (diff) | |
download | iced-f942fc3b68ecbbe136c54922109c7e2e4732735b.tar.gz iced-f942fc3b68ecbbe136c54922109c7e2e4732735b.tar.bz2 iced-f942fc3b68ecbbe136c54922109c7e2e4732735b.zip |
Merge pull request #113 from hecrj/feature/password-input
Password input
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tour.rs | 43 |
1 files changed, 32 insertions, 11 deletions
diff --git a/examples/tour.rs b/examples/tour.rs index b06fbc37..da05b396 100644 --- a/examples/tour.rs +++ b/examples/tour.rs @@ -140,6 +140,7 @@ impl Steps { Step::Scrollable, Step::TextInput { value: String::new(), + is_secure: false, state: text_input::State::new(), }, Step::Debugger, @@ -210,6 +211,7 @@ enum Step { Scrollable, TextInput { value: String, + is_secure: bool, state: text_input::State, }, Debugger, @@ -226,6 +228,7 @@ pub enum StepMessage { LanguageSelected(Language), ImageWidthChanged(f32), InputChanged(String), + ToggleSecureInput(bool), DebugToggled(bool), } @@ -277,6 +280,11 @@ impl<'a> Step { *value = new_value; } } + StepMessage::ToggleSecureInput(toggle) => { + if let Step::TextInput { is_secure, .. } = self { + *is_secure = toggle; + } + } }; } @@ -328,7 +336,11 @@ impl<'a> Step { spacing, } => Self::rows_and_columns(*layout, spacing_slider, *spacing), Step::Scrollable => Self::scrollable(), - Step::TextInput { value, state } => Self::text_input(value, state), + Step::TextInput { + value, + is_secure, + state, + } => Self::text_input(value, *is_secure, state), Step::Debugger => Self::debugger(debug), Step::End => Self::end(), } @@ -582,22 +594,31 @@ impl<'a> Step { fn text_input( value: &str, + is_secure: bool, state: &'a mut text_input::State, ) -> Column<'a, StepMessage> { + let text_input = TextInput::new( + state, + "Type something to continue...", + value, + StepMessage::InputChanged, + ) + .padding(10) + .size(30); Self::container("Text input") .push(Text::new( "Use a text input to ask for different kinds of information.", )) - .push( - TextInput::new( - state, - "Type something to continue...", - value, - StepMessage::InputChanged, - ) - .padding(10) - .size(30), - ) + .push(if is_secure { + text_input.password() + } else { + text_input + }) + .push(Checkbox::new( + is_secure, + "Enable password mode", + StepMessage::ToggleSecureInput, + )) .push(Text::new( "A text input produces a message every time it changes. It is \ very easy to keep track of its contents:", |