summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorLibravatar Casper Storm <casper.storm@lich.io>2023-02-13 11:38:05 +0100
committerLibravatar Héctor Ramón Jiménez <hector0193@gmail.com>2023-04-11 05:11:19 +0200
commit7b369842959511f17d5c27941fd0308484bff8ea (patch)
treedb4bcb9ce1f8770e00a51743e397ad4f89b0be60 /examples
parent931b30dc5ac17b65b1fb996cb4b87fc946c410e3 (diff)
downloadiced-7b369842959511f17d5c27941fd0308484bff8ea.tar.gz
iced-7b369842959511f17d5c27941fd0308484bff8ea.tar.bz2
iced-7b369842959511f17d5c27941fd0308484bff8ea.zip
feat: added handle to text_input
Diffstat (limited to 'examples')
-rw-r--r--examples/text_input/Cargo.toml9
-rw-r--r--examples/text_input/README.md10
-rw-r--r--examples/text_input/fonts/icons.ttfbin0 -> 1612 bytes
-rw-r--r--examples/text_input/src/main.rs93
4 files changed, 112 insertions, 0 deletions
diff --git a/examples/text_input/Cargo.toml b/examples/text_input/Cargo.toml
new file mode 100644
index 00000000..5937ef8e
--- /dev/null
+++ b/examples/text_input/Cargo.toml
@@ -0,0 +1,9 @@
+[package]
+name = "text_input"
+version = "0.1.0"
+authors = ["Casper Rogild Storm<casper@rogildstorm.com>"]
+edition = "2021"
+publish = false
+
+[dependencies]
+iced = { path = "../..", features = ["debug"] }
diff --git a/examples/text_input/README.md b/examples/text_input/README.md
new file mode 100644
index 00000000..2b2d8059
--- /dev/null
+++ b/examples/text_input/README.md
@@ -0,0 +1,10 @@
+## 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
diff --git a/examples/text_input/fonts/icons.ttf b/examples/text_input/fonts/icons.ttf
new file mode 100644
index 00000000..bfe8a24b
--- /dev/null
+++ b/examples/text_input/fonts/icons.ttf
Binary files differ
diff --git a/examples/text_input/src/main.rs b/examples/text_input/src/main.rs
new file mode 100644
index 00000000..b25ed7e1
--- /dev/null
+++ b/examples/text_input/src/main.rs
@@ -0,0 +1,93 @@
+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_handle: bool,
+}
+
+#[derive(Debug, Clone)]
+enum Message {
+ Changed(String),
+ ToggleHandle(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::ToggleHandle(_) => {
+ self.is_showing_handle = !self.is_showing_handle
+ }
+ }
+ }
+
+ fn view(&self) -> Element<Message> {
+ let checkbox =
+ checkbox("Handle", self.is_showing_handle, Message::ToggleHandle)
+ .spacing(5)
+ .text_size(16);
+
+ let mut text_input =
+ text_input("Placeholder", self.value.as_str(), Message::Changed);
+
+ if self.is_showing_handle {
+ text_input = text_input.handle(text_input::Handle {
+ font: ICON_FONT,
+ text: String::from('\u{e900}'),
+ size: Some(18),
+ position: text_input::HandlePosition::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)
+ }
+}