Override dh_python2's idea of supported python versions, for wider installability
[naja.git] / naja / widgets / text.py
index 4cc4272f7435d9a7bf16ef530a3c1bb004a29c7a..3df09488e3a170502426b79d7724b196d2d22c32 100644 (file)
@@ -133,6 +133,8 @@ class TextBoxWidget(TextWidget):
                                                        PALETTE.BLACK))
         self.box_width = kwargs.pop('box_width', 0)
 
+        self.full_width = kwargs.pop('full_width', True)
+
         super(TextBoxWidget, self).__init__(*args, **kwargs)
 
     def lines(self, image_map):
@@ -170,7 +172,7 @@ class TextBoxWidget(TextWidget):
     def _wrapped_lines(self, image_map):
         def words_fit(words):
             words_line = ' '.join(words)
-            width = self.font.size(words_line)[0]
+            width = self.font.size(words_line)[0] * EIGHT_BIT_SCALE
             if width < self.box_width:
                 return True
             elif len(words) == 1:
@@ -219,6 +221,9 @@ class TextBoxWidget(TextWidget):
             width = max(width, line_rect.width + self.padding * 2)
             height += line_rect.height
 
+        if self.full_width:
+            width = max(width, self.box_width)
+
         self.surface = pygame.surface.Surface((width, height),
                                               pygame.locals.SRCALPHA)
         self.surface.fill(self.bg_colour)
@@ -226,6 +231,9 @@ class TextBoxWidget(TextWidget):
 
         x, y = self.padding, self.padding
         for line_surface in rendered_lines:
+            if self.centre:
+                x = (width - line_surface.get_rect().width) / 2
+                x += self.padding
             self.surface.blit(line_surface, (x, y))
             y += line_surface.get_rect().height
         for pos, img in image_map.items():