Add text editor area
This commit is contained in:
parent
f5e12466ac
commit
eb69f5f56f
31
src/main.rs
31
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)]
|
#[derive(Debug, Clone)]
|
||||||
enum Message {}
|
enum Message {
|
||||||
|
Edit(text_editor::Action),
|
||||||
|
}
|
||||||
|
|
||||||
struct Application;
|
struct Application {
|
||||||
|
book_content: text_editor::Content,
|
||||||
|
}
|
||||||
|
|
||||||
impl Sandbox for Application {
|
impl Sandbox for Application {
|
||||||
type Message = Message;
|
type Message = Message;
|
||||||
|
|
||||||
fn new() -> Self {
|
fn new() -> Self {
|
||||||
Self
|
Self {
|
||||||
|
book_content: text_editor::Content::new(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn title(&self) -> String {
|
fn title(&self) -> String {
|
||||||
|
@ -17,11 +26,19 @@ impl Sandbox for Application {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update(&mut self, message: Message) {
|
fn update(&mut self, message: Message) {
|
||||||
match message {}
|
match message {
|
||||||
|
Message::Edit(action) => self.book_content.perform(action),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn view(&self) -> Element<'_, Message> {
|
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()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue