From: Neil Date: Fri, 16 May 2014 22:51:10 +0000 (+0200) Subject: Allow centre=True X-Git-Tag: 0.1~160 X-Git-Url: https://git.ctpug.org.za/?a=commitdiff_plain;h=3ce2165747dd660edcf1ec98f291438bfdddb9c6;p=naja.git Allow centre=True --- 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)