diff options
author | 2023-09-12 14:51:00 +0200 | |
---|---|---|
committer | 2023-09-12 14:51:00 +0200 | |
commit | 6448429103c9c82b90040ac5a5a097bdded23f82 (patch) | |
tree | 79582bde4a7d6df71df0abefe35146b06452409f /examples/editor | |
parent | 346af3f8b0baa418fd37b878bc2930ff0bd57cc0 (diff) | |
download | iced-6448429103c9c82b90040ac5a5a097bdded23f82.tar.gz iced-6448429103c9c82b90040ac5a5a097bdded23f82.tar.bz2 iced-6448429103c9c82b90040ac5a5a097bdded23f82.zip |
Draft `Editor` API and `TextEditor` widget
Diffstat (limited to 'examples/editor')
-rw-r--r-- | examples/editor/Cargo.toml | 10 | ||||
-rw-r--r-- | examples/editor/src/main.rs | 49 |
2 files changed, 59 insertions, 0 deletions
diff --git a/examples/editor/Cargo.toml b/examples/editor/Cargo.toml new file mode 100644 index 00000000..528cf23c --- /dev/null +++ b/examples/editor/Cargo.toml @@ -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"]
\ No newline at end of file diff --git a/examples/editor/src/main.rs b/examples/editor/src/main.rs new file mode 100644 index 00000000..50989ac5 --- /dev/null +++ b/examples/editor/src/main.rs @@ -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() + } +} |