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"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
|
checksum = "f27ae1dd37df86211c42e150270f82743308803d90a6f6e6651cd730d5e1732f"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "data-url"
|
||||||
|
version = "0.3.1"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "5c297a1c74b71ae29df00c3e22dd9534821d60eb9af5a0192823fa2acea70c2a"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "digest"
|
name = "digest"
|
||||||
version = "0.10.7"
|
version = "0.10.7"
|
||||||
@@ -1052,6 +1058,7 @@ version = "0.20.0"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "efb41b6833a6aaa99ca5c4f8e75b2410d69a7b3e30148d413f541147404a0dfa"
|
checksum = "efb41b6833a6aaa99ca5c4f8e75b2410d69a7b3e30148d413f541147404a0dfa"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"data-url",
|
||||||
"egui",
|
"egui",
|
||||||
"egui_extras",
|
"egui_extras",
|
||||||
"pulldown-cmark",
|
"pulldown-cmark",
|
||||||
|
|||||||
+1
-1
@@ -19,4 +19,4 @@ serde = { version = "1.0.219", features = ["derive"] }
|
|||||||
serde_json = "1.0.140"
|
serde_json = "1.0.140"
|
||||||
chrono = { version = "0.4.41", features = ["serde"] }
|
chrono = { version = "0.4.41", features = ["serde"] }
|
||||||
thiserror = "2.0.12"
|
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
|
// Top bar with actions
|
||||||
egui::TopBottomPanel::top("top").show(ctx, |ui| {
|
egui::TopBottomPanel::top("top").show(ctx, |ui| {
|
||||||
ui.horizontal(|ui| {
|
ui.horizontal(|ui| {
|
||||||
|
// Open Markdown Editor button
|
||||||
|
if ui.button("📝 Open Editor").clicked() {
|
||||||
|
self.editor.show_editor = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
ui.separator();
|
||||||
|
|
||||||
// create new template
|
// create new template
|
||||||
if ui.button("New Template").clicked() {
|
if ui.button("New Template").clicked() {
|
||||||
self.right_panel_content = RightPanelContent::Template {
|
self.right_panel_content = RightPanelContent::Template {
|
||||||
|
|||||||
+77
-18
@@ -1,50 +1,109 @@
|
|||||||
|
use egui::{TextEdit, Ui};
|
||||||
use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
|
use egui_commonmark::{CommonMarkCache, CommonMarkViewer};
|
||||||
|
|
||||||
pub struct MainEditor {
|
pub struct MainEditor {
|
||||||
preview: bool,
|
pub show_editor: bool,
|
||||||
|
pub show_preview: bool,
|
||||||
text: String,
|
text: String,
|
||||||
|
preview_cache: CommonMarkCache,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MainEditor {
|
impl MainEditor {
|
||||||
pub fn new() -> Self {
|
pub fn new() -> Self {
|
||||||
Self {
|
Self {
|
||||||
preview: true,
|
show_editor: false, // Start with editor hidden
|
||||||
|
show_preview: true,
|
||||||
text: String::new(),
|
text: String::new(),
|
||||||
|
preview_cache: CommonMarkCache::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ui(&mut self, ctx: &egui::Context) {
|
pub fn ui(&mut self, ctx: &egui::Context) {
|
||||||
if self.preview {
|
// Show the editor window if enabled
|
||||||
egui::TopBottomPanel::bottom("bottom_panel")
|
if self.show_editor {
|
||||||
|
egui::Window::new("Markdown Editor")
|
||||||
.resizable(true)
|
.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| {
|
.show(ctx, |ui| {
|
||||||
egui::ScrollArea::vertical()
|
ui.horizontal(|ui| {
|
||||||
.stick_to_bottom(true)
|
ui.label("Content Editor");
|
||||||
.auto_shrink(false)
|
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| {
|
.show(ui, |ui| {
|
||||||
let mut cache = CommonMarkCache::default();
|
let max_width = 600;
|
||||||
CommonMarkViewer::new().show(ui, &mut cache, &self.text);
|
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);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
egui::CentralPanel::default().show(ctx, |ui| {
|
// Editor area with centered content and max width
|
||||||
egui::ScrollArea::vertical()
|
egui::ScrollArea::both()
|
||||||
.enable_scrolling(true)
|
.auto_shrink([false, false])
|
||||||
.auto_shrink(false)
|
.id_salt("editor_scroll")
|
||||||
.show(ui, |ui| {
|
.show(ui, |ui| {
|
||||||
ui.add(
|
let max_width = 600;
|
||||||
egui::TextEdit::multiline(&mut self.text)
|
let available_width = ui.available_width();
|
||||||
.id_source("MainEditor_numlines")
|
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)
|
.font(egui::TextStyle::Monospace)
|
||||||
.interactive(true)
|
.interactive(true)
|
||||||
.frame(false)
|
.frame(false)
|
||||||
.lock_focus(true)
|
.lock_focus(true)
|
||||||
.hint_text("Type here...")
|
.hint_text("Type here...")
|
||||||
.desired_width(256.0),
|
.desired_width(max_width as f32);
|
||||||
|
|
||||||
|
ui.add_sized(
|
||||||
|
egui::vec2(max_width as f32, ui.available_height()),
|
||||||
|
text_edit,
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user