Draft Editor API and TextEditor widget
This commit is contained in:
parent
346af3f8b0
commit
6448429103
25 changed files with 1384 additions and 92 deletions
10
examples/editor/Cargo.toml
Normal file
10
examples/editor/Cargo.toml
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
[package]
|
||||
name = "editor"
|
||||
version = "0.1.0"
|
||||
authors = ["Héctor Ramón Jiménez <hector@hecrj.dev>"]
|
||||
edition = "2021"
|
||||
publish = false
|
||||
|
||||
[dependencies]
|
||||
iced.workspace = true
|
||||
iced.features = ["debug"]
|
||||
49
examples/editor/src/main.rs
Normal file
49
examples/editor/src/main.rs
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
use iced::widget::{container, text_editor};
|
||||
use iced::{Element, Font, Sandbox, Settings};
|
||||
|
||||
pub fn main() -> iced::Result {
|
||||
Editor::run(Settings::default())
|
||||
}
|
||||
|
||||
struct Editor {
|
||||
content: text_editor::Content,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
enum Message {
|
||||
Edit(text_editor::Action),
|
||||
}
|
||||
|
||||
impl Sandbox for Editor {
|
||||
type Message = Message;
|
||||
|
||||
fn new() -> Self {
|
||||
Self {
|
||||
content: text_editor::Content::with(include_str!(
|
||||
"../../../README.md"
|
||||
)),
|
||||
}
|
||||
}
|
||||
|
||||
fn title(&self) -> String {
|
||||
String::from("Editor - Iced")
|
||||
}
|
||||
|
||||
fn update(&mut self, message: Message) {
|
||||
match message {
|
||||
Message::Edit(action) => {
|
||||
self.content.edit(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn view(&self) -> Element<Message> {
|
||||
container(
|
||||
text_editor(&self.content)
|
||||
.on_edit(Message::Edit)
|
||||
.font(Font::with_name("Hasklug Nerd Font Mono")),
|
||||
)
|
||||
.padding(20)
|
||||
.into()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue