From eb69f5f56f125c8c2f2b4dd111774bcd1535bf0d Mon Sep 17 00:00:00 2001 From: Jarrod Doyle Date: Sun, 21 Jan 2024 15:58:56 +0000 Subject: [PATCH] Add text editor area --- src/main.rs | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/src/main.rs b/src/main.rs index 640ac5d..d513b2d 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,15 +1,24 @@ -use iced::{widget::text, Element, Result, Sandbox, Settings}; +use iced::{ + widget::{column, text, text_editor}, + Element, Result, Sandbox, Settings, +}; -#[derive(Debug)] -enum Message {} +#[derive(Debug, Clone)] +enum Message { + Edit(text_editor::Action), +} -struct Application; +struct Application { + book_content: text_editor::Content, +} impl Sandbox for Application { type Message = Message; fn new() -> Self { - Self + Self { + book_content: text_editor::Content::new(), + } } fn title(&self) -> String { @@ -17,11 +26,19 @@ impl Sandbox for Application { } fn update(&mut self, message: Message) { - match message {} + match message { + Message::Edit(action) => self.book_content.perform(action), + } } fn view(&self) -> Element<'_, Message> { - text("Hello, world!").into() + let hello_world = text("Hello, world!"); + let active_editor = text_editor(&self.book_content).on_action(Message::Edit); + + column![hello_world, active_editor] + .spacing(10) + .padding(10) + .into() } }