# HG changeset patch # User Simon Cross # Date 1282597769 -7200 # Node ID d7c0a702a0b420a3e061c07bb2107e8b217373d2 # Parent 6bfebfbce42e94c903a0ba52a33de7ebfd7be4a8 Factor label width setting method out into a custom class (BoomLabel). diff -r 6bfebfbce42e -r d7c0a702a0b4 gamelib/state.py --- a/gamelib/state.py Mon Aug 23 23:05:55 2010 +0200 +++ b/gamelib/state.py Mon Aug 23 23:09:29 2010 +0200 @@ -2,7 +2,7 @@ from albow.resource import get_image, get_sound from albow.utils import frame_rect -from albow.controls import Label +from widgets import BoomLabel from pygame.locals import BLEND_ADD from pygame.rect import Rect from pygame.color import Color @@ -137,13 +137,8 @@ def _make_description(self, text): if text is None: return None - label = Label(text) - # TODO: create derived label class that does this - # manually recalculate size - d = 5 - w, h = label.size - label.margin = d - label.size = (w+2*d, h+2*d) + label = BoomLabel(text) + label.set_margin(5) label.border_width = 1 label.border_color = (0, 0, 0) label.bg_color = (127, 127, 127) diff -r 6bfebfbce42e -r d7c0a702a0b4 gamelib/widgets.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gamelib/widgets.py Mon Aug 23 23:09:29 2010 +0200 @@ -0,0 +1,18 @@ +# widgets.py +# Copyright Boomslang team, 2010 (see COPYING File) + +"""Custom Albow widgets""" + +import albow.controls + + +class BoomLabel(albow.controls.Label): + + def set_margin(self, margin): + """Add a set_margin method that recalculates the label size""" + old_margin = self.margin + w, h = self.size + d = margin - old_margin + self.margin = margin + self.size = (w + 2 * d, h + 2 * d) +