pub mod aaguid;
pub mod device;
pub mod help;
pub mod mds;
pub mod theme;
use theme::{f_bold, f_reg, Palette};
pub fn help_popover(ctx: &egui::Context, p: &Palette, topic: &str, anchor: egui::Pos2) -> bool {
let Some(h) = help::help(topic) else {
return true; };
let mut dismissed = false;
let screen = ctx.content_rect();
egui::Area::new(egui::Id::new("help_scrim"))
.order(egui::Order::Middle)
.fixed_pos(screen.min)
.interactable(true)
.show(ctx, |ui| {
ui.painter()
.rect_filled(screen, 0.0, egui::Color32::from_black_alpha(97));
if ui.allocate_rect(screen, egui::Sense::click()).clicked() {
dismissed = true;
}
});
let width = 300.0;
let x = (anchor.x).min(screen.right() - width - 12.0).max(12.0);
let pos = egui::pos2(x, anchor.y + 7.0);
egui::Area::new(egui::Id::new("help_pop"))
.order(egui::Order::Foreground)
.fixed_pos(pos)
.show(ctx, |ui| {
ui.set_max_width(width);
egui::Frame {
inner_margin: egui::Margin::same(16),
corner_radius: egui::CornerRadius::same(13),
fill: p.pop,
stroke: egui::Stroke::new(1.0, p.line),
shadow: egui::epaint::Shadow {
offset: [0, 12],
blur: 40,
spread: 0,
color: egui::Color32::from_black_alpha(115),
},
..Default::default()
}
.show(ui, |ui| {
ui.set_max_width(width - 32.0);
ui.horizontal(|ui| {
badge_q(ui, p);
ui.add_space(2.0);
ui.label(egui::RichText::new(h.title).font(f_bold(13.5)).color(p.txt));
});
ui.add_space(6.0);
ui.label(egui::RichText::new(h.body).font(f_reg(13.0)).color(p.txt));
if !h.slug.is_empty() {
ui.add_space(10.0);
ui.hyperlink_to(
egui::RichText::new("Learn how to use this ↗")
.font(theme::f_sb(12.5))
.color(p.accent),
help::learn_url(h.slug),
);
}
});
});
if ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
dismissed = true;
}
dismissed
}
fn badge_q(ui: &mut egui::Ui, p: &Palette) {
let d = 18.0;
let (rect, _) = ui.allocate_exact_size(egui::vec2(d, d), egui::Sense::hover());
ui.painter().circle_filled(rect.center(), d / 2.0, p.accent);
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
"?",
theme::f_bold(11.0),
p.accent_ink,
);
}
pub fn help_button(ui: &mut egui::Ui, p: &Palette, active: bool) -> egui::Response {
let d = 17.0;
let (rect, resp) = ui.allocate_exact_size(egui::vec2(d, d), egui::Sense::click());
let (fill, fg) = if active || resp.hovered() {
(p.accent, p.accent_ink)
} else {
(p.accent_soft(), p.accent)
};
ui.painter().circle_filled(rect.center(), d / 2.0, fill);
ui.painter().text(
rect.center(),
egui::Align2::CENTER_CENTER,
"?",
theme::f_bold(10.5),
fg,
);
resp.on_hover_text("What's this?")
}