diff options
author | 2023-04-12 04:19:54 +0200 | |
---|---|---|
committer | 2023-04-12 04:19:54 +0200 | |
commit | 250ba3a7f1b41c7f7ca32b8db40a8c4069ebef77 (patch) | |
tree | 16ba220cfde260d82a1e048acbf95530a0bd27b9 /examples | |
parent | e6a93e960c3ac71a74f11555fd2d225c185f6e8c (diff) | |
download | iced-250ba3a7f1b41c7f7ca32b8db40a8c4069ebef77.tar.gz iced-250ba3a7f1b41c7f7ca32b8db40a8c4069ebef77.tar.bz2 iced-250ba3a7f1b41c7f7ca32b8db40a8c4069ebef77.zip |
Remove `text_input` example
Diffstat (limited to 'examples')
-rw-r--r-- | examples/text_input/Cargo.toml | 11 | ||||
-rw-r--r-- | examples/text_input/README.md | 15 | ||||
-rw-r--r-- | examples/text_input/src/main.rs | 94 |
3 files changed, 0 insertions, 120 deletions
diff --git a/examples/text_input/Cargo.toml b/examples/text_input/Cargo.toml deleted file mode 100644 index aead9896..00000000 --- a/examples/text_input/Cargo.toml +++ /dev/null @@ -1,11 +0,0 @@ -[package] -name = "text_input" -authors = ["Dan Mishin <jungletryne@yandex.com>"] -version = "0.1.0" -edition = "2021" - -# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html - -[dependencies] -iced = { path = "../..", features = ["tokio"] } -tokio = { version = "1.26.0", features = ["time"] } diff --git a/examples/text_input/README.md b/examples/text_input/README.md deleted file mode 100644 index 435989cc..00000000 --- a/examples/text_input/README.md +++ /dev/null @@ -1,15 +0,0 @@ -# Text Input - -This example shows basic usage of text edit. -The button delays the change of the text field state to allow testing of the corner cases. - -<div align="center"> - <a href="https://gfycat.com/everycarelessisabellinewheatear"> - <img src="https://thumbs.gfycat.com/EveryCarelessIsabellinewheatear-max-1mb.gif" height="400px"> - </a> -</div> - -You can run it with cargo run: -```bash -cargo run --package text_input -```
\ No newline at end of file diff --git a/examples/text_input/src/main.rs b/examples/text_input/src/main.rs deleted file mode 100644 index 418593f4..00000000 --- a/examples/text_input/src/main.rs +++ /dev/null @@ -1,94 +0,0 @@ -use crate::Message::{StartTimer, TextEditModeChange}; -use iced::widget::{button, column, container, row, text, text_input}; -use iced::{ - executor, window, Application, Command, Element, Length, Renderer, - Settings, Theme, -}; -use tokio::time::{sleep, Duration}; - -fn main() -> iced::Result { - let settings = Settings { - window: window::Settings { - size: (700, 100), - ..window::Settings::default() - }, - ..Settings::default() - }; - - Example::run(settings) -} - -#[derive(Default)] -struct Example { - data: String, - text_edit_enabled: bool, -} - -#[derive(Debug, Clone)] -enum Message { - StartTimer, - TextEditModeChange, - TextInputChanged(String), -} - -impl Application for Example { - type Executor = executor::Default; - type Message = Message; - type Theme = Theme; - type Flags = (); - - fn new(_flags: Self::Flags) -> (Self, Command<Self::Message>) { - (Self::default(), Command::none()) - } - - fn title(&self) -> String { - "TextInput example".into() - } - - fn update(&mut self, message: Self::Message) -> Command<Self::Message> { - match message { - Message::TextEditModeChange => { - self.text_edit_enabled = !self.text_edit_enabled; - Command::none() - } - Message::TextInputChanged(updated_text) => { - self.data = updated_text; - Command::none() - } - StartTimer => { - let timer_f = async { - sleep(Duration::from_secs(3)).await; - }; - Command::perform(timer_f, |_| TextEditModeChange) - } - } - } - - fn view(&self) -> Element<'_, Self::Message, Renderer<Self::Theme>> { - let placeholder = if self.text_edit_enabled { - "Enabled TextEdit" - } else { - "Disabled TextEdit" - }; - - let mut txt_input = text_input(placeholder, &self.data); - - if self.text_edit_enabled { - txt_input = txt_input.on_input(Message::TextInputChanged); - } - - let btn = button("Enable/Disable").on_press(StartTimer); - let label = text( - "The mode will be changed after 3s when the button is pressed", - ); - - let content = row![txt_input, btn].spacing(10); - let content = column![content, label].spacing(10); - - container(content) - .width(Length::Shrink) - .height(Length::Shrink) - .padding(20) - .into() - } -} |