From 276508713f57e18680a7dc466e52967eed3aaf66 Mon Sep 17 00:00:00 2001 From: Joakim Hulthe Date: Thu, 10 Jul 2025 19:50:38 +0200 Subject: [PATCH] Different header sizes --- src/app.rs | 24 ++++++++++++++++++++++-- src/file_editor.rs | 2 +- src/markdown/highlighter.rs | 13 +++++++++++-- 3 files changed, 34 insertions(+), 5 deletions(-) diff --git a/src/app.rs b/src/app.rs index d30c250..1791598 100644 --- a/src/app.rs +++ b/src/app.rs @@ -14,8 +14,8 @@ use crate::{ util::{GuiSender, file_mtime, log_error}, }; use egui::{ - Align, Button, Context, FontData, FontDefinitions, Image, Key, Modifiers, PointerButton, - RichText, ScrollArea, Widget, include_image, + Align, Button, Context, FontData, FontDefinitions, FontId, Image, Key, Modifiers, + PointerButton, RichText, ScrollArea, Widget, include_image, }; use eyre::eyre; @@ -201,6 +201,26 @@ impl App { cc.egui_ctx.set_fonts(fonts); + // markdown font styles + cc.egui_ctx.style_mut(|style| { + for (name, size) in [ + ("H1", 28.0), + ("H2", 26.0), + ("H3", 24.0), + ("H4", 22.0), + ("H5", 20.0), + ("H6", 18.0), + ] { + style.text_styles.insert( + egui::TextStyle::Name(name.into()), + FontId { + size, + family: egui::FontFamily::Proportional, + }, + ); + } + }); + // enable features on egui_extras to add more image types egui_extras::install_image_loaders(&cc.egui_ctx); diff --git a/src/file_editor.rs b/src/file_editor.rs index 8a44b13..2a176d6 100644 --- a/src/file_editor.rs +++ b/src/file_editor.rs @@ -145,7 +145,7 @@ impl FileEditor { if let Some(inner) = &mut self.inner { while let Ok(event) = inner.file_events.try_recv() { - match dbg!(event) { + match event { FileEvent::NewFileMTime(mtime) => { self.file_mtime = Some(mtime); } diff --git a/src/markdown/highlighter.rs b/src/markdown/highlighter.rs index a471c33..e1a5877 100644 --- a/src/markdown/highlighter.rs +++ b/src/markdown/highlighter.rs @@ -1,5 +1,7 @@ use egui::text::{CCursorRange, LayoutJob}; +use crate::markdown::Heading; + use super::{Item, Style, parse}; /// Highlight markdown, caching previous output to save CPU. @@ -71,8 +73,15 @@ fn format_from_style(egui_style: &egui::Style, style: &Style) -> egui::text::Tex egui_style.visuals.text_color() }; - let text_style = if style.heading.is_some() { - TextStyle::Heading + let text_style = if let Some(heading) = style.heading { + match heading { + Heading::H1 => TextStyle::Name("H1".into()), + Heading::H2 => TextStyle::Name("H2".into()), + Heading::H3 => TextStyle::Name("H3".into()), + Heading::H4 => TextStyle::Name("H4".into()), + Heading::H5 => TextStyle::Name("H5".into()), + Heading::H6 => TextStyle::Name("H6".into()), + } } else if style.code { TextStyle::Monospace } else if style.small | style.raised {