Remove text_input example
This commit is contained in:
parent
e6a93e960c
commit
250ba3a7f1
3 changed files with 0 additions and 120 deletions
|
|
@ -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"] }
|
|
||||||
|
|
@ -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
|
|
||||||
```
|
|
||||||
|
|
@ -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()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue