label background color

This commit is contained in:
TheOddGarlic 2022-04-29 22:02:12 +03:00
parent 4ef18b26e8
commit 0e2066e9fe

View file

@ -11,12 +11,16 @@ use crate::{widget::Widget, layout::position::Position};
pub struct Label {
text: String,
color: Color,
fg_color: Color,
bg_color: Color,
}
impl Widget for Label {
fn draw(&self, renderer: &mut Renderer) {
renderer.set_brush(Brush::Solid(self.color));
let pos = self.position(renderer);
renderer.set_brush(Brush::Solid(self.bg_color));
renderer.fill_rect(pos.width(), pos.height());
renderer.set_brush(Brush::Solid(self.fg_color));
renderer.draw_text(&self.text);
}
@ -30,12 +34,18 @@ impl Label {
pub fn new<S: Into<String>>(text: S) -> Self {
Self {
text: text.into(),
color: rgb!(0x000000FF),
fg_color: rgb!(0x000000FF),
bg_color: rgb!(0x00000000),
}
}
pub fn color(mut self, color: Color) -> Self {
self.color = color;
self.fg_color = color;
self
}
pub fn bg_color(mut self, bg: Color) -> Self {
self.bg_color = bg;
self
}
}