Browse Source

Allow customizing bg color of DrawContext

Thomas Dy 7 years ago
parent
commit
10f33653b8
1 changed files with 6 additions and 7 deletions
  1. 6 7
      src/ui/widget.rs

+ 6 - 7
src/ui/widget.rs

@@ -42,17 +42,11 @@ impl DrawContext {
     }
 
     pub fn draw_bg(&self, x: u16, width: u16) {
-        let color = xcb::render::Color::new(
-            self.bg_color.red(),
-            self.bg_color.green(),
-            self.bg_color.blue(),
-            self.bg_color.alpha()
-        );
         xcb::render::fill_rectangles(
             &self.conn,
             xcb::render::PICT_OP_SRC as u8,
             self.picture,
-            color,
+            self.bg_color,
             &[xcb::Rectangle::new(x as i16, 0, width, 20)]
         );
     }
@@ -62,6 +56,11 @@ impl DrawContext {
         text.width
     }
 
+    pub fn set_bg_color(&mut self, red: u16, blue: u16, green: u16, alpha: u16) {
+        self.bg_color = xcb::render::Color::new(red, blue, green, alpha);
+    }
+
+
     pub fn draw_text(&self, name: &str, x: u16) {
         if !name.is_empty() {
             let text = self.fonts.create_renderable_text(name);