label background color
This commit is contained in:
parent
4ef18b26e8
commit
0e2066e9fe
|
@ -11,12 +11,16 @@ use crate::{widget::Widget, layout::position::Position};
|
||||||
|
|
||||||
pub struct Label {
|
pub struct Label {
|
||||||
text: String,
|
text: String,
|
||||||
color: Color,
|
fg_color: Color,
|
||||||
|
bg_color: Color,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Widget for Label {
|
impl Widget for Label {
|
||||||
fn draw(&self, renderer: &mut Renderer) {
|
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);
|
renderer.draw_text(&self.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,12 +34,18 @@ impl Label {
|
||||||
pub fn new<S: Into<String>>(text: S) -> Self {
|
pub fn new<S: Into<String>>(text: S) -> Self {
|
||||||
Self {
|
Self {
|
||||||
text: text.into(),
|
text: text.into(),
|
||||||
color: rgb!(0x000000FF),
|
fg_color: rgb!(0x000000FF),
|
||||||
|
bg_color: rgb!(0x00000000),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn color(mut self, color: Color) -> Self {
|
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
|
self
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue