editor has separate window now

This commit is contained in:
2025-07-14 01:30:33 +01:00
parent 1b0b53a2d2
commit 35ab726206
4 changed files with 102 additions and 29 deletions
Generated
+7
View File
@@ -851,6 +851,12 @@ version = "1.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
[[package]]
name = "data-url"
version = "0.3.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a"
[[package]]
name = "digest"
version = "0.10.7"
@@ -1052,6 +1058,7 @@ version = "0.20.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "efb41b6833a6aaa99ca5c4f8e75b2410d69a7b3e30148d413f541147404a0dfa"
dependencies = [
"data-url",
"egui",
"egui_extras",
"pulldown-cmark",
+1 -1
View File
@@ -19,4 +19,4 @@ serde = { version = "1.0.219", features = ["derive"] }
serde_json = "1.0.140"
chrono = { version = "0.4.41", features = ["serde"] }
thiserror = "2.0.12"
egui_commonmark = "0.20.0"
egui_commonmark = { version = "0.20.0", features = ["embedded_image"] }
+7
View File
@@ -182,6 +182,13 @@ impl eframe::App for Interface {
// Top bar with actions
egui::TopBottomPanel::top("top").show(ctx, |ui| {
ui.horizontal(|ui| {
// Open Markdown Editor button
if ui.button("📝 Open Editor").clicked() {
self.editor.show_editor = true;
}
ui.separator();
// create new template
if ui.button("New Template").clicked() {
self.right_panel_content = RightPanelContent::Template {
+87 -28
View File
@@ -1,50 +1,109 @@
use egui::{TextEdit, Ui};
use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
pub struct MainEditor {
preview: bool,
pub show_editor: bool,
pub show_preview: bool,
text: String,
preview_cache: CommonMarkCache,
}
impl MainEditor {
pub fn new() -> Self {
Self {
preview: true,
show_editor: false, // Start with editor hidden
show_preview: true,
text: String::new(),
preview_cache: CommonMarkCache::default(),
}
}
pub fn ui(&mut self, ctx: &egui::Context) {
if self.preview {
egui::TopBottomPanel::bottom("bottom_panel")
// Show the editor window if enabled
if self.show_editor {
egui::Window::new("Markdown Editor")
.resizable(true)
.default_height(250.0)
.default_width(1000.0)
.default_height(800.0)
.max_height(800.0)
.open(&mut self.show_editor)
.show(ctx, |ui| {
egui::ScrollArea::vertical()
.stick_to_bottom(true)
.auto_shrink(false)
ui.horizontal(|ui| {
ui.label("Content Editor");
ui.checkbox(&mut self.show_preview, "Preview");
});
ui.separator();
if self.show_preview {
// Preview area
egui::SidePanel::right("preview_panel")
.resizable(true)
.default_width(ui.available_width() / 2.0)
.show_inside(ui, |ui| {
// Preview area with centered content and max width
egui::ScrollArea::both()
.auto_shrink([false, false])
.id_salt("preview_scroll")
.show(ui, |ui| {
let max_width = 600;
let available_width = ui.available_width();
let content_width = (max_width as f32).min(available_width);
let padding = (available_width - content_width) / 2.0;
ui.horizontal(|ui| {
ui.add_space(padding);
ui.vertical(|ui| {
ui.set_width(content_width);
ui.add_space(15.0);
ui.set_min_width(max_width as f32);
CommonMarkViewer::new()
.default_width(Some(max_width))
.max_image_width(Some(512))
.show(ui, &mut self.preview_cache, &self.text);
});
});
});
});
}
// Editor area with centered content and max width
egui::ScrollArea::both()
.auto_shrink([false, false])
.id_salt("editor_scroll")
.show(ui, |ui| {
let mut cache = CommonMarkCache::default();
CommonMarkViewer::new().show(ui, &mut cache, &self.text);
let max_width = 600;
let available_width = ui.available_width();
let content_width = (max_width as f32).min(available_width);
let padding = (available_width - content_width) / 2.0;
ui.horizontal(|ui| {
ui.add_space(padding);
ui.vertical(|ui| {
ui.set_width(content_width);
ui.add_space(15.0);
ui.set_min_width(max_width as f32);
let text_edit = TextEdit::multiline(&mut self.text)
.id_source("MainEditor_editor")
.font(egui::TextStyle::Monospace)
.interactive(true)
.frame(false)
.lock_focus(true)
.hint_text("Type here...")
.desired_width(max_width as f32);
ui.add_sized(
egui::vec2(max_width as f32, ui.available_height()),
text_edit,
);
});
});
});
});
}
egui::CentralPanel::default().show(ctx, |ui| {
egui::ScrollArea::vertical()
.enable_scrolling(true)
.auto_shrink(false)
.show(ui, |ui| {
ui.add(
egui::TextEdit::multiline(&mut self.text)
.id_source("MainEditor_numlines")
.font(egui::TextStyle::Monospace)
.interactive(true)
.frame(false)
.lock_focus(true)
.hint_text("Type here...")
.desired_width(256.0),
);
});
});
}
}