aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPolesznyák Márk <contact@pml68.dev>2025-11-10 00:41:19 +0100
committerPolesznyák Márk <contact@pml68.dev>2025-11-10 00:41:19 +0100
commit853fc6dff8389e1dfa355bc46f8ea559216e9c63 (patch)
tree6bb0863241e4470c2389e3a08c096e3e75464f40
parentfeat(rich example): use single paragraph, centered text (diff)
downloadiced_selection-853fc6dff8389e1dfa355bc46f8ea559216e9c63.tar.gz
feat(name example): replace TextInput with TextEditor for multi-line support, disable wrapping
-rw-r--r--examples/name/Cargo.toml1
-rw-r--r--examples/name/src/main.rs21
2 files changed, 16 insertions, 6 deletions
diff --git a/examples/name/Cargo.toml b/examples/name/Cargo.toml
index 23c3b58..e24d7d2 100644
--- a/examples/name/Cargo.toml
+++ b/examples/name/Cargo.toml
@@ -5,4 +5,5 @@ edition = "2024"
[dependencies]
iced.workspace = true
+iced.features = ["advanced"]
iced_selection = { path = "../.." }
diff --git a/examples/name/src/main.rs b/examples/name/src/main.rs
index bfb60be..deed136 100644
--- a/examples/name/src/main.rs
+++ b/examples/name/src/main.rs
@@ -1,5 +1,6 @@
+use iced::advanced::text::Wrapping;
use iced::widget::operation::focus_next;
-use iced::widget::{center, column, text_input};
+use iced::widget::{center, column, text_editor};
use iced::{Center, Element, Task};
use iced_selection::text;
@@ -9,12 +10,13 @@ fn main() -> iced::Result {
#[derive(Default)]
struct State {
+ content: text_editor::Content,
name: String,
}
#[derive(Debug, Clone)]
enum Message {
- UpdateText(String),
+ UpdateText(text_editor::Action),
}
impl State {
@@ -24,16 +26,23 @@ impl State {
fn update(&mut self, message: Message) {
match message {
- Message::UpdateText(name) => self.name = name,
+ Message::UpdateText(action) => {
+ let is_edit = action.is_edit();
+
+ self.content.perform(action);
+
+ if is_edit {
+ self.name = self.content.text();
+ }
+ }
};
}
fn view(&self) -> Element<'_, Message> {
center(
column![
- text!("Hello {}", &self.name),
- text_input("Type your name here...", &self.name)
- .on_input(Message::UpdateText)
+ text!("Hello {}", &self.name).wrapping(Wrapping::None),
+ text_editor(&self.content).on_action(Message::UpdateText)
]
.spacing(10)
.align_x(Center),