Commits

anatoly techtonik committed 0e9ce74

FilePanel: Strip too long panel title with ... in the middle.

  • Participants
  • Parent commits 672d03a

Comments (0)

Files changed (1)

         for label in self.border_labels:
             label.draw()
             
-        # draw layer1 - title
+        # draw layer1 - panel title
         avail_width = self.width-2-2  # width-border-margin
         label_title = ' ' + self.title + ' '
         if len(self.title) > avail_width:
-            # [ ] TODO: crop symbols from the middle
-            label_title = self.title[:len(self.width)-5] + '...'
+            # cut long panel title with ...
+            if avail_width < 4:
+                label_title = self.title[avail_width]
+            else:
+                # replace extra symbols at about 20% from the start
+                startr = int(avail_width*0.2)
+                endr = len(self.title) - (avail_width-startr-3)
+                label_title = self.title[:startr] + '...' + self.title[endr:]
+            
         # center title label
-        xpos = 3 + avail_width//2 - len(label_title)//2
+        xpos = 2 + (avail_width - len(label_title))//2
         label = pyglet.text.Label(label_title, anchor_y='top',
                     font_name=font_family,
                     x=font_width*xpos, y=font_height*self.height)
         label.set_style('background_color', palette.background_active)
         label.draw()
         
+        # draw layer2 - panel entries
         yspace = self.height-2
         for idx, (name, label) in enumerate(self.items):
             if idx >= self.offset and idx < self.offset + yspace: