1. anatoly techtonik
  2. index

Commits

anatoly techtonik  committed d548415

FilePanel: leave space for border

  • Participants
  • Parent commits df8ad46
  • Branches default

Comments (0)

Files changed (1)

File index.py

View file
  • Ignore whitespace
     # [x] up/down arrows move cursor
     # [x] scrolling
     def __init__(self, width, height):
+        # file panel dimensions with the border
         self.height = height
         self.width = width
-        # offset of starting visible element from the items list
-        self.offset = 0
-        # [ ] resize - correct offset when window height shrinked
         
         # every item is (filename, label)
         self.items = []
         self.item_idx = 0
+        # offset of starting visible element from the items list
+        self.offset = 0
+        # [ ] resize - correct offset when window height shrinked
 
     def _is_item_visible(self, idx):
         """True if item with given idx is visible in panel"""
         """Change position of visible label on the canvas. If idx is not None,
            refresh coordinate for label with given idx.
         """
+        xspace = self.width-2  # size of content area (panel size - border)
+        yspace = self.height-2
+        xstart = 1  # leave space for border
+        ystart = 1
+        # TODO [ ] crop right side
         if idx is not None:
-            if idx not in range(self.offset, self.height):
+            if idx not in range(self.offset, yspace):
                 return
-            position = idx - self.offset 
-            self.items[idx][1].y = (self.height - position) * font_height
+            position = ystart + idx - self.offset - 1
+            self.items[idx][1].x = xstart * font_width
+            self.items[idx][1].y = (ystart + (yspace - position)) * font_height
         else:
-            items = self.items[self.offset:self.offset+self.height]
+            items = self.items[self.offset:self.offset+yspace]
             for position,item in enumerate(items):
-                item[1].y = (self.height - position) * font_height
+                item[1].x = xstart * font_width
+                item[1].y = (ystart + (yspace - position)) * font_height
         
     def up(self):
         """Move cursor up"""
 
     def down(self):
         """Move cursor down"""
+        yspace = self.height-2
         if self.item_idx == len(filepanel.items)-1:
             # stop if last element of list is reached
             return
         self._color_entry(self.item_idx, palette.active,
                                          palette.background_active)
 
-        if self.item_idx - self.offset == self.height:
+        if self.item_idx - self.offset == yspace:
             self.offset += 1
             self._refresh_label_positions()
             
+    def draw_border(self):
+        pass        
+        
     def draw(self):
+        yspace = self.height-2
         for idx, (name, label) in enumerate(self.items):
-            if idx >= self.offset and idx < self.offset + self.height:
+            if idx >= self.offset and idx < self.offset + yspace:
                 label.draw()
         
     # --- content methods