From 0e2066e9fe477c33a604daca91a095bff26e8a8e Mon Sep 17 00:00:00 2001 From: TheOddGarlic Date: Fri, 29 Apr 2022 22:02:12 +0300 Subject: [PATCH] label background color --- src/widget/label.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/widget/label.rs b/src/widget/label.rs index 30fb04c..5434b9f 100755 --- a/src/widget/label.rs +++ b/src/widget/label.rs @@ -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>(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 } }