Removed text_input example in favor for Tour

This commit is contained in:
Casper Storm 2023-02-20 14:42:10 +01:00 committed by Héctor Ramón Jiménez
parent d24a4a4689
commit 898307e9ac
No known key found for this signature in database
GPG key ID: 140CC052C94F138E
5 changed files with 66 additions and 124 deletions

View file

@ -5,8 +5,14 @@ use iced::widget::{
scrollable, slider, text, text_input, toggler, vertical_space,
};
use iced::widget::{Button, Column, Container, Slider};
use iced::Font;
use iced::{Color, Element, Length, Renderer, Sandbox, Settings};
const ICON_FONT: Font = Font::External {
name: "Icons",
bytes: include_bytes!("../fonts/icons.ttf"),
};
pub fn main() -> iced::Result {
env_logger::init();
@ -127,6 +133,7 @@ impl Steps {
Step::TextInput {
value: String::new(),
is_secure: false,
is_showing_icon: false,
},
Step::Debugger,
Step::End,
@ -171,14 +178,32 @@ impl Steps {
enum Step {
Welcome,
Slider { value: u8 },
RowsAndColumns { layout: Layout, spacing: u16 },
Text { size: u16, color: Color },
Radio { selection: Option<Language> },
Toggler { can_continue: bool },
Image { width: u16 },
Slider {
value: u8,
},
RowsAndColumns {
layout: Layout,
spacing: u16,
},
Text {
size: u16,
color: Color,
},
Radio {
selection: Option<Language>,
},
Toggler {
can_continue: bool,
},
Image {
width: u16,
},
Scrollable,
TextInput { value: String, is_secure: bool },
TextInput {
value: String,
is_secure: bool,
is_showing_icon: bool,
},
Debugger,
End,
}
@ -194,6 +219,7 @@ pub enum StepMessage {
ImageWidthChanged(u16),
InputChanged(String),
ToggleSecureInput(bool),
ToggleTextInputIcon(bool),
DebugToggled(bool),
TogglerChanged(bool),
}
@ -256,6 +282,14 @@ impl<'a> Step {
*can_continue = value;
}
}
StepMessage::ToggleTextInputIcon(toggle) => {
if let Step::TextInput {
is_showing_icon, ..
} = self
{
*is_showing_icon = toggle
}
}
};
}
@ -303,9 +337,11 @@ impl<'a> Step {
Self::rows_and_columns(*layout, *spacing)
}
Step::Scrollable => Self::scrollable(),
Step::TextInput { value, is_secure } => {
Self::text_input(value, *is_secure)
}
Step::TextInput {
value,
is_secure,
is_showing_icon,
} => Self::text_input(value, *is_secure, *is_showing_icon),
Step::Debugger => Self::debugger(debug),
Step::End => Self::end(),
}
@ -530,8 +566,12 @@ impl<'a> Step {
)
}
fn text_input(value: &str, is_secure: bool) -> Column<'a, StepMessage> {
let text_input = text_input(
fn text_input(
value: &str,
is_secure: bool,
is_showing_icon: bool,
) -> Column<'a, StepMessage> {
let mut text_input = text_input(
"Type something to continue...",
value,
StepMessage::InputChanged,
@ -539,6 +579,15 @@ impl<'a> Step {
.padding(10)
.size(30);
if is_showing_icon {
text_input = text_input.icon(text_input::Icon {
font: ICON_FONT,
code_point: '\u{e900}',
size: Some(35),
position: text_input::IconPosition::Right,
});
}
Self::container("Text input")
.push("Use a text input to ask for different kinds of information.")
.push(if is_secure {
@ -551,6 +600,11 @@ impl<'a> Step {
is_secure,
StepMessage::ToggleSecureInput,
))
.push(checkbox(
"Show icon",
is_showing_icon,
StepMessage::ToggleTextInputIcon,
))
.push(
"A text input produces a message every time it changes. It is \
very easy to keep track of its contents:",