use egui::{Color32, Context, Ui};
use crate::components::style::Tone;
use crate::{banner, show_popover};
pub struct Banner<'a> {
message: &'a str,
color: Option<Color32>,
tone: Tone,
}
impl<'a> Banner<'a> {
pub fn new(message: &'a str) -> Self {
Self {
message,
color: None,
tone: Tone::Warning,
}
}
pub fn tone(mut self, tone: Tone) -> Self {
self.tone = tone;
self
}
pub fn color(mut self, color: Color32) -> Self {
self.color = Some(color);
self
}
pub fn show(self, ui: &mut Ui, actions: impl FnOnce(&mut Ui)) {
let color = self.color.unwrap_or_else(|| self.tone.text(ui.visuals()));
banner(ui, color, self.message, actions);
}
}
pub struct Popover<'a> {
id: &'a str,
width: f32,
}
impl<'a> Popover<'a> {
pub fn new(id: &'a str) -> Self {
Self { id, width: 420.0 }
}
pub fn width(mut self, width: f32) -> Self {
self.width = width;
self
}
pub fn show<R>(self, ctx: &Context, add: impl FnOnce(&mut Ui) -> R) -> R {
show_popover(ctx, self.id, self.width, add)
}
}