浏览代码

Add spacing between bspwm and title

Thomas Dy 7 年之前
父节点
当前提交
75fcafa156
共有 3 个文件被更改,包括 34 次插入4 次删除
  1. 4 0
      src/ui/mod.rs
  2. 24 0
      src/ui/spacer.rs
  3. 6 4
      src/ui/title.rs

+ 4 - 0
src/ui/mod.rs

@@ -5,6 +5,7 @@ mod title;
 mod tray;
 mod sensors;
 mod bspwm;
+mod spacer;
 mod util;
 mod widget;
 mod x11;
@@ -49,6 +50,9 @@ pub fn ui_main(cfg: &Config) -> i32 {
         let bspwm = bspwm::Bspwm::new(tx.clone(), panel.make_draw_context());
         panel.add_left_widget(Box::new(bspwm));
 
+        let spacer = spacer::create(panel.make_draw_context(), 4, 0x6666, 0x6666, 0x6666, 0xFFFF);
+        panel.add_left_widget(Box::new(spacer));
+
         let title = title::Title::new(panel.conn.clone(), panel.make_draw_context());
         panel.add_left_widget(Box::new(title));
 

+ 24 - 0
src/ui/spacer.rs

@@ -0,0 +1,24 @@
+use ui::widget;
+
+pub struct Spacer {
+    context: widget::DrawContext,
+    width: u16
+}
+
+pub fn create(mut context: widget::DrawContext, width: u16, red: u16, green: u16, blue: u16, alpha: u16) -> Spacer {
+    context.set_bg_color(red, green, blue, alpha);
+    Spacer {
+        context: context,
+        width: width
+    }
+}
+
+impl widget::Widget for Spacer {
+    fn render(&mut self, x: u16) {
+        self.context.draw_bg(x, self.width);
+    }
+
+    fn width(&mut self) -> u16 {
+        self.width
+    }
+}

+ 6 - 4
src/ui/title.rs

@@ -5,6 +5,8 @@ use xcb;
 
 use std::sync::Arc;
 
+const MARGIN: u16 = 7;
+
 pub struct Title {
     conn: Arc<x11::Connection>,
     context: widget::DrawContext,
@@ -28,8 +30,8 @@ impl Title {
 
     pub fn redraw(&mut self) {
         self.context.draw_bg(self.last_pos, self.last_width);
-        self.context.draw_text(&self.title, self.last_pos);
-        self.last_width = self.context.measure_text(&self.title);
+        self.context.draw_text(&self.title, self.last_pos + MARGIN);
+        self.last_width = self.context.measure_text(&self.title) + MARGIN;
         self.conn.flush();
     }
 }
@@ -45,8 +47,8 @@ impl Widget for Title {
 
     fn render(&mut self, x: u16) {
         self.last_pos = x;
-        self.context.draw_text(&self.title, self.last_pos);
-        self.last_width = self.context.measure_text(&self.title);
+        self.context.draw_text(&self.title, self.last_pos + MARGIN);
+        self.last_width = self.context.measure_text(&self.title) + MARGIN;
     }
 
     fn width(&mut self) -> u16 {