From 3ce2165747dd660edcf1ec98f291438bfdddb9c6 Mon Sep 17 00:00:00 2001 From: Neil Date: Sat, 17 May 2014 00:51:10 +0200 Subject: [PATCH] Allow centre=True --- naja/widgets/text.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/naja/widgets/text.py b/naja/widgets/text.py index 7c1039f..02de03f 100644 --- a/naja/widgets/text.py +++ b/naja/widgets/text.py @@ -40,7 +40,8 @@ class TextWidget(Widget): VIEW_PORT_DY = 50 def __init__(self, pos, text, fontname=None, fontsize=None, - colour=None, unselectable_colour=None, view_port=None): + colour=None, unselectable_colour=None, view_port=None, + centre=False): super(TextWidget, self).__init__(pos) self.text = text @@ -52,6 +53,8 @@ class TextWidget(Widget): self.unselectable_colour = unselectable_colour self.view_port = ( pygame.Rect((0, 0), view_port) if view_port is not None else None) + self.centre = centre + self.centre_pos = pos def render_line(self, text): colour = self.colour @@ -68,6 +71,9 @@ class TextWidget(Widget): self.size = self.view_port.size else: self.size = self.surface.get_rect().size + if self.centre: + self.pos = (self.centre_pos[0] - self.size[0] // 2, + self.centre_pos[1]) def prepare(self): self.font = resources.get_font(self.fontname, self.fontsize) -- 2.34.1