pub(crate) const BACKDROP_ALPHA: u8 = 60;
pub(crate) const OVERLAY_CLOSE_SIZE: f32 = 16.0;
#[must_use]
pub(crate) fn max_panel_width(ctx: &egui::Context, spacing: &crate::responsive::Spacing) -> f32 {
let screen = ctx.input(egui::InputState::viewport_rect);
(screen.width() - 2.0 * spacing.page_padding - 50.0).max(0.0)
}
pub(crate) fn paint_backdrop(ctx: &egui::Context, id_suffix: &str, alpha: u8) -> egui::Response {
let screen = ctx.input(egui::InputState::viewport_rect);
let layer = egui::LayerId::new(egui::Order::Middle, egui::Id::unique(id_suffix));
let _ = ctx.layer_painter(layer).rect_filled(
screen,
egui::CornerRadius::ZERO,
egui::Color32::from_black_alpha(alpha),
);
egui::Area::new(egui::Id::unique(id_suffix).with("sense"))
.order(egui::Order::Middle)
.anchor(egui::Align2::LEFT_TOP, egui::Vec2::ZERO)
.show(ctx, |inner_ui| {
inner_ui
.allocate_exact_size(screen.size(), egui::Sense::click())
.1
})
.inner
}
pub(crate) fn close_button(
ui: &mut egui::Ui,
ctx: &egui::Context,
theme: &crate::theme::shadcn_theme::ShadcnTheme,
open: &mut bool,
) {
let _ = ui.with_layout(egui::Layout::right_to_left(egui::Align::TOP), |inner_ui| {
let (rect, resp) = inner_ui.allocate_exact_size(
egui::vec2(OVERLAY_CLOSE_SIZE, OVERLAY_CLOSE_SIZE),
egui::Sense::click(),
);
if inner_ui.is_rect_visible(rect) {
crate::icons::paint_icon::paint_icon(
inner_ui.painter(),
rect,
&crate::icons::lucide_icon::LucideIcon::X,
theme.muted_foreground,
);
}
let close_clicked = resp
.on_hover_cursor(egui::CursorIcon::PointingHand)
.clicked();
if close_clicked {
*open = false;
ctx.request_repaint();
}
});
}
#[must_use]
pub(crate) fn clamp_overlay_width(width: f32, floor: f32, screen_max: f32) -> f32 {
let cap = screen_max.max(0.0);
width.clamp(floor.min(cap), cap)
}