2023-09-12 14:51:00 +02:00
|
|
|
use iced::widget::{container, text_editor};
|
2023-09-13 15:17:04 +02:00
|
|
|
use iced::{Element, Font, Sandbox, Settings, Theme};
|
2023-09-12 14:51:00 +02:00
|
|
|
|
|
|
|
|
pub fn main() -> iced::Result {
|
|
|
|
|
Editor::run(Settings::default())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct Editor {
|
|
|
|
|
content: text_editor::Content,
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-16 15:40:16 +02:00
|
|
|
#[derive(Debug, Clone)]
|
2023-09-12 14:51:00 +02:00
|
|
|
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()
|
|
|
|
|
}
|
2023-09-13 15:17:04 +02:00
|
|
|
|
|
|
|
|
fn theme(&self) -> Theme {
|
|
|
|
|
Theme::Dark
|
|
|
|
|
}
|
2023-09-12 14:51:00 +02:00
|
|
|
}
|