标题粗体显示:h1-h6 标题在正文中标粗区分

This commit is contained in:
2026-05-15 12:09:11 +08:00
parent b51ce6853b
commit 19336d5d34
2 changed files with 56 additions and 9 deletions

View File

@@ -239,13 +239,38 @@ egui::ComboBox::from_id_salt("bg_type_selector")
ui.with_layout(
egui::Layout::top_down(align).with_main_justify(false),
|ui| {
ui.add(
egui::Label::new(
egui::RichText::new(&indented)
let mut is_heading = false;
let mut remaining = indented.as_str();
while !remaining.is_empty() {
if let Some(pos) = remaining.find(['\x01', '\x02']) {
if pos > 0 {
let text = &remaining[..pos];
let mut rt = egui::RichText::new(text)
.size(style.font_size)
.color(colors.text);
if is_heading {
rt = rt.strong();
}
ui.add(egui::Label::new(rt).wrap());
}
let marker = remaining.chars().nth(pos).unwrap();
if marker == '\x01' {
is_heading = true;
} else {
is_heading = false;
}
remaining = &remaining[pos + 1..];
} else {
let mut rt = egui::RichText::new(remaining)
.size(style.font_size)
.color(colors.text)
).wrap()
);
.color(colors.text);
if is_heading {
rt = rt.strong();
}
ui.add(egui::Label::new(rt).wrap());
break;
}
}
},
);
});