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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
//! Alert history popup rendering.
//!
//! This module contains the alert history popup rendering logic,
//! displaying past alerts with severity levels and timestamps.
use eframe::egui::{self, RichText};
use crate::gui::app::AranetApp;
use crate::gui::types::AlertSeverity;
impl AranetApp {
/// Render the alert history popup.
pub(crate) fn render_alert_history_popup(&mut self, ctx: &egui::Context) {
egui::Window::new("Alert History")
.collapsible(false)
.resizable(true)
.default_width(400.0)
.default_height(300.0)
.anchor(egui::Align2::CENTER_CENTER, [0.0, 0.0])
.show(ctx, |ui| {
// Header with close button
ui.horizontal(|ui| {
ui.label(
RichText::new(format!("{} alerts", self.alert_history.len()))
.color(self.theme.text_muted)
.size(self.theme.typography.caption),
);
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
if ui
.add(
egui::Button::new(
RichText::new("Clear All")
.size(self.theme.typography.caption)
.color(self.theme.text_secondary),
)
.fill(self.theme.bg_secondary),
)
.clicked()
{
self.alert_history.clear();
}
ui.add_space(self.theme.spacing.sm);
if ui
.add(
egui::Button::new(
RichText::new("Close")
.size(self.theme.typography.caption)
.color(self.theme.text_on_accent),
)
.fill(self.theme.accent),
)
.clicked()
{
self.alert_history_visible = false;
}
});
});
ui.separator();
if self.alert_history.is_empty() {
ui.vertical_centered(|ui| {
ui.add_space(self.theme.spacing.xl);
ui.label(
RichText::new("No alerts yet")
.color(self.theme.text_muted)
.size(self.theme.typography.body),
);
ui.label(
RichText::new("Alerts will appear when thresholds are exceeded")
.color(self.theme.text_muted)
.size(self.theme.typography.caption),
);
});
} else {
egui::ScrollArea::vertical()
.max_height(250.0)
.show(ui, |ui| {
for alert in &self.alert_history {
let (severity_color, severity_bg) = match alert.severity {
AlertSeverity::Info => {
(self.theme.info, self.theme.tint_bg(self.theme.info, 15))
}
AlertSeverity::Warning => (
self.theme.warning,
self.theme.tint_bg(self.theme.warning, 15),
),
AlertSeverity::Critical => (
self.theme.danger,
self.theme.tint_bg(self.theme.danger, 15),
),
};
egui::Frame::new()
.fill(severity_bg)
.inner_margin(egui::Margin::same(self.theme.spacing.sm as i8))
.corner_radius(egui::CornerRadius::same(
self.theme.rounding.sm as u8,
))
.stroke(egui::Stroke::new(
1.0,
severity_color.gamma_multiply(0.3),
))
.show(ui, |ui| {
ui.horizontal(|ui| {
// Severity icon
ui.label(
RichText::new(alert.severity.icon())
.color(severity_color)
.size(self.theme.typography.body)
.strong(),
);
ui.vertical(|ui| {
ui.horizontal(|ui| {
// Time and device
ui.label(
RichText::new(&alert.time_str)
.color(self.theme.text_secondary)
.size(self.theme.typography.caption),
);
ui.label(
RichText::new("-")
.color(self.theme.text_muted)
.size(self.theme.typography.caption),
);
ui.label(
RichText::new(&alert.device_name)
.color(self.theme.text_primary)
.size(self.theme.typography.caption)
.strong(),
);
ui.with_layout(
egui::Layout::right_to_left(
egui::Align::Center,
),
|ui| {
ui.label(
RichText::new(alert.age_str())
.color(self.theme.text_muted)
.size(
self.theme
.typography
.caption,
),
);
},
);
});
ui.label(
RichText::new(&alert.message)
.color(self.theme.text_secondary)
.size(self.theme.typography.caption),
);
});
});
});
ui.add_space(self.theme.spacing.xs);
}
});
}
});
}
}