use egui::{Response, RichText, Ui};
use crate::components::Component;
use crate::components::style::{Size, Tone};
pub struct Label<'a> {
text: &'a str,
size: Size,
tone: Tone,
strong: bool,
}
impl<'a> Label<'a> {
pub fn new(text: &'a str) -> Self {
Self {
text,
size: Size::Md,
tone: Tone::Neutral,
strong: false,
}
}
pub fn size(mut self, size: Size) -> Self {
self.size = size;
self
}
pub fn tone(mut self, tone: Tone) -> Self {
self.tone = tone;
self
}
pub fn strong(mut self) -> Self {
self.strong = true;
self
}
}
impl Component for Label<'_> {
type Output = Response;
fn show(self, ui: &mut Ui) -> Response {
let mut rich = RichText::new(self.text)
.size(crate::style::get(ui.ctx()).text(self.size))
.color(self.tone.text(ui.visuals()));
if self.strong {
rich = rich.strong();
}
ui.label(rich)
}
}