mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 22:00:03 -04:00
Add a VERY experimental markdown viewer
This commit is contained in:
@@ -13,17 +13,19 @@ struct Demos {
|
||||
impl Default for Demos {
|
||||
fn default() -> Self {
|
||||
let demos: Vec<Box<dyn super::Demo>> = vec![
|
||||
Box::new(super::widget_gallery::WidgetGallery::default()),
|
||||
Box::new(super::sliders::Sliders::default()),
|
||||
Box::new(super::input_test::InputTest::default()),
|
||||
Box::new(super::font_book::FontBook::default()),
|
||||
Box::new(super::painting::Painting::default()),
|
||||
Box::new(super::dancing_strings::DancingStrings::default()),
|
||||
Box::new(super::drag_and_drop::DragAndDropDemo::default()),
|
||||
Box::new(super::tests::Tests::default()),
|
||||
Box::new(super::window_options::WindowOptions::default()),
|
||||
Box::new(super::font_book::FontBook::default()),
|
||||
Box::new(super::markdown_editor::MarkdownEditor::default()),
|
||||
Box::new(super::painting::Painting::default()),
|
||||
Box::new(super::scrolling::Scrolling::default()),
|
||||
Box::new(super::sliders::Sliders::default()),
|
||||
Box::new(super::widget_gallery::WidgetGallery::default()),
|
||||
Box::new(super::window_options::WindowOptions::default()),
|
||||
// Tests:
|
||||
Box::new(super::layout_test::LayoutTest::default()),
|
||||
Box::new(super::tests::IdTest::default()),
|
||||
Box::new(super::input_test::InputTest::default()),
|
||||
];
|
||||
Self {
|
||||
open: vec![false; demos.len()],
|
||||
|
||||
@@ -29,7 +29,7 @@ impl Default for LayoutTest {
|
||||
|
||||
impl super::Demo for LayoutTest {
|
||||
fn name(&self) -> &str {
|
||||
"🖹 Layouts"
|
||||
"🗺 Layout Test"
|
||||
}
|
||||
|
||||
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
||||
|
||||
66
egui_demo_lib/src/apps/demo/markdown_editor.rs
Normal file
66
egui_demo_lib/src/apps/demo/markdown_editor.rs
Normal file
@@ -0,0 +1,66 @@
|
||||
use egui::*;
|
||||
|
||||
#[cfg_attr(feature = "persistence", derive(serde::Deserialize, serde::Serialize))]
|
||||
#[derive(PartialEq)]
|
||||
pub struct MarkdownEditor {
|
||||
markdown: String,
|
||||
}
|
||||
|
||||
impl Default for MarkdownEditor {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
markdown: r#"
|
||||
# Markdown editor
|
||||
Markdown support in egui is experimental, and *very* limited. There are:
|
||||
|
||||
* bullet points
|
||||
* with sub-points
|
||||
* `inline code`
|
||||
* *emphasis*
|
||||
* [hyperlinks](https://github.com/emilk/egui)
|
||||
|
||||
---
|
||||
|
||||
Also the separator
|
||||
|
||||
"#
|
||||
.trim_start()
|
||||
.to_owned(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl super::Demo for MarkdownEditor {
|
||||
fn name(&self) -> &str {
|
||||
"🖹 Markdown Editor"
|
||||
}
|
||||
|
||||
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
||||
egui::Window::new(self.name()).open(open).show(ctx, |ui| {
|
||||
use super::View;
|
||||
self.ui(ui);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
impl super::View for MarkdownEditor {
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.vertical_centered(|ui| {
|
||||
egui::reset_button(ui, self);
|
||||
ui.add(crate::__egui_github_link_file!());
|
||||
});
|
||||
ui.separator();
|
||||
ui.columns(2, |columns| {
|
||||
ScrollArea::auto_sized()
|
||||
.id_source("source")
|
||||
.show(&mut columns[0], |ui| {
|
||||
ui.text_edit_multiline(&mut self.markdown);
|
||||
});
|
||||
ScrollArea::auto_sized()
|
||||
.id_source("rendered")
|
||||
.show(&mut columns[1], |ui| {
|
||||
egui::experimental::markdown(ui, &self.markdown);
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,7 @@ pub mod font_contents_emoji;
|
||||
pub mod font_contents_ubuntu;
|
||||
pub mod input_test;
|
||||
pub mod layout_test;
|
||||
pub mod markdown_editor;
|
||||
pub mod painting;
|
||||
pub mod scrolling;
|
||||
pub mod sliders;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
#[derive(Default)]
|
||||
pub struct Tests {}
|
||||
pub struct IdTest {}
|
||||
|
||||
impl super::Demo for Tests {
|
||||
impl super::Demo for IdTest {
|
||||
fn name(&self) -> &str {
|
||||
"📋 Tests"
|
||||
"📋 ID Test"
|
||||
}
|
||||
|
||||
fn show(&mut self, ctx: &egui::CtxRef, open: &mut bool) {
|
||||
@@ -14,7 +14,7 @@ impl super::Demo for Tests {
|
||||
}
|
||||
}
|
||||
|
||||
impl super::View for Tests {
|
||||
impl super::View for IdTest {
|
||||
fn ui(&mut self, ui: &mut egui::Ui) {
|
||||
ui.heading("Name collision example");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user