use egui::{Align, Layout, Response, RichText, Ui};
use crate::styles::typography;
pub struct PanelHeader<'a> {
title: &'a str,
use_heading: bool,
separator: bool,
}
impl<'a> PanelHeader<'a> {
pub fn new(title: &'a str) -> Self {
Self {
title,
use_heading: true,
separator: true,
}
}
#[must_use]
pub fn strong(mut self) -> Self {
self.use_heading = false;
self
}
#[must_use]
pub fn no_separator(mut self) -> Self {
self.separator = false;
self
}
pub fn show(self, ui: &mut Ui, actions: impl FnOnce(&mut Ui)) -> Response {
let response = ui
.horizontal(|ui| {
if self.use_heading {
ui.heading(self.title);
} else {
ui.label(RichText::new(self.title).strong().size(typography::LG));
}
ui.with_layout(Layout::right_to_left(Align::Center), actions);
})
.response;
if self.separator {
ui.separator();
}
response
}
pub fn show_plain(self, ui: &mut Ui) -> Response {
self.show(ui, |_| {})
}
}