Skip to content

Commit

Permalink
Fix header sizing issue (#20)
Browse files Browse the repository at this point in the history
The issue originates from mixing row heights (as returned by `ui.text_style_height()` and font size. This PR fixes this discrepancy, leading to correct (relative) header sizing.
  • Loading branch information
abey79 authored Nov 7, 2023
1 parent 8c231bc commit 1982fbb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
9 changes: 9 additions & 0 deletions examples/hello_world.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,15 @@ vec.push(5);
1. Sub item
[^1]: A footnote
# Header 1
## Header 2
### Header 3
#### Header 4
##### Header 5
###### Header 6
Some text.
"#;

egui::CentralPanel::default().show(ctx, |ui| {
Expand Down
12 changes: 10 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -653,8 +653,16 @@ impl CommonMarkViewerInternal {
let mut text = RichText::new(text);

if let Some(level) = self.text_style.heading {
let max_height = ui.text_style_height(&TextStyle::Heading);
let min_height = ui.text_style_height(&TextStyle::Body);
let max_height = ui
.style()
.text_styles
.get(&egui::TextStyle::Heading)
.map_or(32.0, |d| d.size);
let min_height = ui
.style()
.text_styles
.get(&egui::TextStyle::Body)
.map_or(14.0, |d| d.size);
let diff = max_height - min_height;
match level {
HeadingLevel::H1 => {
Expand Down

0 comments on commit 1982fbb

Please sign in to comment.