From 853fc6dff8389e1dfa355bc46f8ea559216e9c63 Mon Sep 17 00:00:00 2001 From: Polesznyák Márk Date: Mon, 10 Nov 2025 00:41:19 +0100 Subject: feat(name example): replace TextInput with TextEditor for multi-line support, disable wrapping --- examples/name/Cargo.toml | 1 + examples/name/src/main.rs | 21 +++++++++++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) (limited to 'examples') 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), -- cgit v1.2.3