Add text editor area

This commit is contained in:
Jarrod Doyle 2024-01-21 15:58:56 +00:00
parent f5e12466ac
commit eb69f5f56f
Signed by: Jayrude
GPG Key ID: 38B57B16E7C0ADF7
1 changed files with 24 additions and 7 deletions

View File

@ -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()
}
}