Explorar o código

Replace magic number 20 with const

Thomas Dy %!s(int64=7) %!d(string=hai) anos
pai
achega
c93c4aa50b
Modificáronse 3 ficheiros con 10 adicións e 8 borrados
  1. 4 3
      src/ui/draw_context.rs
  2. 3 2
      src/ui/panel.rs
  3. 3 3
      src/widgets/tray.rs

+ 4 - 3
src/ui/draw_context.rs

@@ -1,4 +1,5 @@
 use xcb;
+use ui;
 use ui::font;
 use ui::color;
 
@@ -37,7 +38,7 @@ impl DrawContext {
             xcb::render::PICT_OP_SRC as u8,
             self.picture,
             self.bg_color,
-            &[xcb::Rectangle::new(x as i16, 0, width, 20)]
+            &[xcb::Rectangle::new(x as i16, 0, width, ui::SIZE)]
         );
     }
 
@@ -54,7 +55,7 @@ impl DrawContext {
     pub fn draw_text(&self, name: &str, x: u16) {
         if !name.is_empty() {
             let text = self.fonts.create_renderable_text(name);
-            let baseline = 20 - self.fonts.default_offset(20);
+            let baseline = ui::SIZE as i16 - self.fonts.default_offset(ui::SIZE);
             text.render(&self.conn, self.pen, self.picture, x, baseline as u16);
         }
     }
@@ -64,7 +65,7 @@ impl DrawContext {
             &self.conn,
             self.picture,
             0, 0,
-            &[xcb::Rectangle::new(x as i16, 0, width, 20)]
+            &[xcb::Rectangle::new(x as i16, 0, width, ui::SIZE)]
         );
 
         self.draw_text(name, x);

+ 3 - 2
src/ui/panel.rs

@@ -1,5 +1,6 @@
 use config::Config;
 use xcb;
+use ui;
 use ui::color;
 use ui::draw_context::DrawContext;
 use ui::ext;
@@ -69,7 +70,7 @@ impl Panel {
             self.window,
             root,
             0, 0,
-            width, 20,
+            width, ui::SIZE,
             0,
             xcb::WINDOW_CLASS_INPUT_OUTPUT as u16,
             xcb::COPY_FROM_PARENT,
@@ -180,7 +181,7 @@ impl Panel {
             xcb::render::PICT_OP_SRC as u8,
             self.picture,
             color::BLACK,
-            &[xcb::Rectangle::new(0, 0, self.width, 20)]
+            &[xcb::Rectangle::new(0, 0, self.width, ui::SIZE)]
         );
 
         // measure

+ 3 - 3
src/widgets/tray.rs

@@ -88,15 +88,15 @@ impl Tray {
 
 impl Widget for Tray {
     fn width(&mut self) -> u16 {
-        (self.children.len() * 20) as u16
+        (self.children.len() as u16) * ui::SIZE
     }
 
     fn render(&mut self, x: u16, _w: u16) {
         for (index, child) in self.children.iter().enumerate() {
             let window = *child;
-            let xpos = x as u32 + index as u32 * 20;
+            let xpos = x + index as u16 * ui::SIZE;
             xcb::configure_window(&self.conn, window, &[
-                (xcb::CONFIG_WINDOW_X as u16, xpos)
+                (xcb::CONFIG_WINDOW_X as u16, xpos as u32)
             ]);
         }
     }