Mercurial > pyntnclick
changeset 79:d7c0a702a0b4
Factor label width setting method out into a custom class (BoomLabel).
author | Simon Cross <hodgestar+bzr@gmail.com> |
---|---|
date | Mon, 23 Aug 2010 23:09:29 +0200 |
parents | 6bfebfbce42e |
children | b5a216d62669 |
files | gamelib/state.py gamelib/widgets.py |
diffstat | 2 files changed, 21 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- 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)
--- /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) +