anatoly techtonik avatar anatoly techtonik committed d548415

FilePanel: leave space for border

Comments (0)

Files changed (1)

     # [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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.