Removed text_input example in favor for Tour
This commit is contained in:
parent
d24a4a4689
commit
898307e9ac
5 changed files with 66 additions and 124 deletions
|
|
@ -1,9 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "text_input"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["Casper Rogild Storm<casper@rogildstorm.com>"]
|
|
||||||
edition = "2021"
|
|
||||||
publish = false
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
iced = { path = "../..", features = ["debug"] }
|
|
||||||
|
|
@ -1,10 +0,0 @@
|
||||||
## TextInput
|
|
||||||
|
|
||||||
A `TextInput` is a field that can be filled with text.
|
|
||||||
|
|
||||||
You can run it with `cargo run`:
|
|
||||||
```
|
|
||||||
cargo run --package text_input
|
|
||||||
```
|
|
||||||
|
|
||||||
[`main`]: src/main.rs
|
|
||||||
|
|
@ -1,93 +0,0 @@
|
||||||
use iced::widget::{checkbox, column, container, text_input};
|
|
||||||
use iced::{Element, Font, Length, Sandbox, Settings};
|
|
||||||
|
|
||||||
const ICON_FONT: Font = Font::External {
|
|
||||||
name: "Icons",
|
|
||||||
bytes: include_bytes!("../fonts/icons.ttf"),
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn main() -> iced::Result {
|
|
||||||
Example::run(Settings::default())
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Default)]
|
|
||||||
struct Example {
|
|
||||||
value: String,
|
|
||||||
is_showing_icon: bool,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
|
||||||
enum Message {
|
|
||||||
Changed(String),
|
|
||||||
ToggleIcon(bool),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Sandbox for Example {
|
|
||||||
type Message = Message;
|
|
||||||
|
|
||||||
fn new() -> Self {
|
|
||||||
Self::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn title(&self) -> String {
|
|
||||||
String::from("Text Input - Iced")
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
|
||||||
match message {
|
|
||||||
Message::Changed(value) => self.value = value,
|
|
||||||
Message::ToggleIcon(_) => {
|
|
||||||
self.is_showing_icon = !self.is_showing_icon
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn view(&self) -> Element<Message> {
|
|
||||||
let checkbox =
|
|
||||||
checkbox("Icon", self.is_showing_icon, Message::ToggleIcon)
|
|
||||||
.spacing(5)
|
|
||||||
.text_size(16);
|
|
||||||
|
|
||||||
let mut text_input =
|
|
||||||
text_input("Placeholder", self.value.as_str(), Message::Changed);
|
|
||||||
|
|
||||||
if self.is_showing_icon {
|
|
||||||
text_input = text_input.icon(text_input::Icon {
|
|
||||||
font: ICON_FONT,
|
|
||||||
code_point: '\u{e900}',
|
|
||||||
size: Some(18),
|
|
||||||
position: text_input::IconPosition::Right,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
let content = column!["What is blazing fast?", text_input, checkbox]
|
|
||||||
.width(Length::Units(200))
|
|
||||||
.spacing(10);
|
|
||||||
|
|
||||||
container(content)
|
|
||||||
.width(Length::Fill)
|
|
||||||
.height(Length::Fill)
|
|
||||||
.center_x()
|
|
||||||
.center_y()
|
|
||||||
.into()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn theme(&self) -> iced::Theme {
|
|
||||||
iced::Theme::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn style(&self) -> iced::theme::Application {
|
|
||||||
iced::theme::Application::default()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn scale_factor(&self) -> f64 {
|
|
||||||
1.0
|
|
||||||
}
|
|
||||||
|
|
||||||
fn run(settings: Settings<()>) -> Result<(), iced::Error>
|
|
||||||
where
|
|
||||||
Self: 'static + Sized,
|
|
||||||
{
|
|
||||||
<Self as iced::Application>::run(settings)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -5,8 +5,14 @@ use iced::widget::{
|
||||||
scrollable, slider, text, text_input, toggler, vertical_space,
|
scrollable, slider, text, text_input, toggler, vertical_space,
|
||||||
};
|
};
|
||||||
use iced::widget::{Button, Column, Container, Slider};
|
use iced::widget::{Button, Column, Container, Slider};
|
||||||
|
use iced::Font;
|
||||||
use iced::{Color, Element, Length, Renderer, Sandbox, Settings};
|
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 {
|
pub fn main() -> iced::Result {
|
||||||
env_logger::init();
|
env_logger::init();
|
||||||
|
|
||||||
|
|
@ -127,6 +133,7 @@ impl Steps {
|
||||||
Step::TextInput {
|
Step::TextInput {
|
||||||
value: String::new(),
|
value: String::new(),
|
||||||
is_secure: false,
|
is_secure: false,
|
||||||
|
is_showing_icon: false,
|
||||||
},
|
},
|
||||||
Step::Debugger,
|
Step::Debugger,
|
||||||
Step::End,
|
Step::End,
|
||||||
|
|
@ -171,14 +178,32 @@ impl Steps {
|
||||||
|
|
||||||
enum Step {
|
enum Step {
|
||||||
Welcome,
|
Welcome,
|
||||||
Slider { value: u8 },
|
Slider {
|
||||||
RowsAndColumns { layout: Layout, spacing: u16 },
|
value: u8,
|
||||||
Text { size: u16, color: Color },
|
},
|
||||||
Radio { selection: Option<Language> },
|
RowsAndColumns {
|
||||||
Toggler { can_continue: bool },
|
layout: Layout,
|
||||||
Image { width: u16 },
|
spacing: u16,
|
||||||
|
},
|
||||||
|
Text {
|
||||||
|
size: u16,
|
||||||
|
color: Color,
|
||||||
|
},
|
||||||
|
Radio {
|
||||||
|
selection: Option<Language>,
|
||||||
|
},
|
||||||
|
Toggler {
|
||||||
|
can_continue: bool,
|
||||||
|
},
|
||||||
|
Image {
|
||||||
|
width: u16,
|
||||||
|
},
|
||||||
Scrollable,
|
Scrollable,
|
||||||
TextInput { value: String, is_secure: bool },
|
TextInput {
|
||||||
|
value: String,
|
||||||
|
is_secure: bool,
|
||||||
|
is_showing_icon: bool,
|
||||||
|
},
|
||||||
Debugger,
|
Debugger,
|
||||||
End,
|
End,
|
||||||
}
|
}
|
||||||
|
|
@ -194,6 +219,7 @@ pub enum StepMessage {
|
||||||
ImageWidthChanged(u16),
|
ImageWidthChanged(u16),
|
||||||
InputChanged(String),
|
InputChanged(String),
|
||||||
ToggleSecureInput(bool),
|
ToggleSecureInput(bool),
|
||||||
|
ToggleTextInputIcon(bool),
|
||||||
DebugToggled(bool),
|
DebugToggled(bool),
|
||||||
TogglerChanged(bool),
|
TogglerChanged(bool),
|
||||||
}
|
}
|
||||||
|
|
@ -256,6 +282,14 @@ impl<'a> Step {
|
||||||
*can_continue = value;
|
*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)
|
Self::rows_and_columns(*layout, *spacing)
|
||||||
}
|
}
|
||||||
Step::Scrollable => Self::scrollable(),
|
Step::Scrollable => Self::scrollable(),
|
||||||
Step::TextInput { value, is_secure } => {
|
Step::TextInput {
|
||||||
Self::text_input(value, *is_secure)
|
value,
|
||||||
}
|
is_secure,
|
||||||
|
is_showing_icon,
|
||||||
|
} => Self::text_input(value, *is_secure, *is_showing_icon),
|
||||||
Step::Debugger => Self::debugger(debug),
|
Step::Debugger => Self::debugger(debug),
|
||||||
Step::End => Self::end(),
|
Step::End => Self::end(),
|
||||||
}
|
}
|
||||||
|
|
@ -530,8 +566,12 @@ impl<'a> Step {
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn text_input(value: &str, is_secure: bool) -> Column<'a, StepMessage> {
|
fn text_input(
|
||||||
let text_input = text_input(
|
value: &str,
|
||||||
|
is_secure: bool,
|
||||||
|
is_showing_icon: bool,
|
||||||
|
) -> Column<'a, StepMessage> {
|
||||||
|
let mut text_input = text_input(
|
||||||
"Type something to continue...",
|
"Type something to continue...",
|
||||||
value,
|
value,
|
||||||
StepMessage::InputChanged,
|
StepMessage::InputChanged,
|
||||||
|
|
@ -539,6 +579,15 @@ impl<'a> Step {
|
||||||
.padding(10)
|
.padding(10)
|
||||||
.size(30);
|
.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")
|
Self::container("Text input")
|
||||||
.push("Use a text input to ask for different kinds of information.")
|
.push("Use a text input to ask for different kinds of information.")
|
||||||
.push(if is_secure {
|
.push(if is_secure {
|
||||||
|
|
@ -551,6 +600,11 @@ impl<'a> Step {
|
||||||
is_secure,
|
is_secure,
|
||||||
StepMessage::ToggleSecureInput,
|
StepMessage::ToggleSecureInput,
|
||||||
))
|
))
|
||||||
|
.push(checkbox(
|
||||||
|
"Show icon",
|
||||||
|
is_showing_icon,
|
||||||
|
StepMessage::ToggleTextInputIcon,
|
||||||
|
))
|
||||||
.push(
|
.push(
|
||||||
"A text input produces a message every time it changes. It is \
|
"A text input produces a message every time it changes. It is \
|
||||||
very easy to keep track of its contents:",
|
very easy to keep track of its contents:",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue