Skip to content

Commit

Permalink
half and half demo layout and window to test composition
Browse files Browse the repository at this point in the history
  • Loading branch information
noxware committed Mar 9, 2024
1 parent 3456b21 commit e071928
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions examples/markdown-editor/src/app.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use hframe::Aware;

const INITIAL_MARKDOWN: &str = r#"
# Hello
Expand Down Expand Up @@ -28,19 +30,29 @@ impl App {

impl eframe::App for App {
fn update(&mut self, ctx: &egui::Context, _frame: &mut eframe::Frame) {
egui::SidePanel::right("render_panel").show(ctx, |ui| {
let md = comrak::markdown_to_html(&self.markdown_input, &comrak::Options::default());
let html = format!("<div style=\"font-family: sans-serif;\">{}</div>", md);
ui.add(hframe::BareHtml::new("render_html").content(&html));
});

egui::CentralPanel::default().show(ctx, |ui| {
ui.add_sized(
ui.available_size(),
egui::TextEdit::multiline(&mut self.markdown_input),
)
let full_height = ui.available_height();
let half_width = ui.available_width() / 2.0;

ui.horizontal(|ui| {
ui.add_sized(
[half_width, full_height],
egui::TextEdit::multiline(&mut self.markdown_input),
);

let html =
comrak::markdown_to_html(&self.markdown_input, &comrak::Options::default());
let styled_html = format!("<div style=\"font-family: sans-serif;\">{}</div>", html);
let html_widget = hframe::BareHtml::new("render_html").content(&styled_html);

ui.add_sized([half_width, full_height], html_widget);
});
});

egui::Window::new("Style")
.show(ctx, |ui| egui::widgets::global_dark_light_mode_buttons(ui))
.aware();

hframe::sync(ctx);
}
}

0 comments on commit e071928

Please sign in to comment.