1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//! Code/CodeBlock atom
//!
//! Theme-aware code display components with proper scaling support.
use crate::theme::Theme;
use egui::{FontId, RichText, Ui};
/// Inline code styling
///
/// Uses theme for colors, spacing, and font sizing.
pub struct Code<'a> {
text: &'a str,
}
impl<'a> Code<'a> {
pub fn new(text: &'a str) -> Self {
Self { text }
}
pub fn show(self, ui: &mut Ui) {
let theme = Theme::current(ui.ctx());
// Use tertiary background for inline code
let bg = theme.bg_tertiary;
// Use state_danger for code highlight (reddish)
let fg = theme.state_danger;
egui::Frame::new()
.fill(bg)
.corner_radius(theme.radius_sm)
.inner_margin(egui::Margin::symmetric((theme.spacing_xs * 0.75) as i8, 1))
.show(ui, |ui| {
ui.label(
RichText::new(self.text)
.color(fg)
.font(FontId::monospace(theme.font_size_sm)),
);
});
}
}
/// Code block for multi-line code
///
/// Uses theme for colors, spacing, borders, and font sizing.
pub struct CodeBlock<'a> {
code: &'a str,
language: Option<&'a str>,
}
impl<'a> CodeBlock<'a> {
pub fn new(code: &'a str) -> Self {
Self {
code,
language: None,
}
}
pub fn language(mut self, lang: &'a str) -> Self {
self.language = Some(lang);
self
}
pub fn show(self, ui: &mut Ui) {
let theme = Theme::current(ui.ctx());
// Use secondary background for code blocks
let bg = theme.bg_secondary;
// Use primary text for code content
let fg = theme.text_primary;
// Use border color from theme
let border = theme.border;
egui::Frame::new()
.fill(bg)
.stroke(egui::Stroke::new(theme.border_width, border))
.corner_radius(theme.radius_md)
.inner_margin(egui::Margin::same(theme.spacing_sm as i8))
.show(ui, |ui| {
// Language label
if let Some(lang) = self.language {
ui.label(
RichText::new(lang)
.size(theme.font_size_xs)
.color(theme.text_muted),
);
ui.add_space(theme.spacing_xs);
}
// Code content
ui.label(
RichText::new(self.code)
.color(fg)
.font(FontId::monospace(theme.font_size_sm)),
);
});
}
}