editor has separate window now
This commit is contained in:
Generated
+7
@@ -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
@@ -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"] }
|
||||
|
||||
@@ -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
@@ -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),
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user