Changeset 237:6995dbefdbfb for nagslang


Ignore:
Timestamp:
Sep 4, 2013, 8:06:55 PM (7 years ago)
Author:
Neil Muller <drnlmuller@…>
Branch:
default
Message:

Add multiline widget

File:
1 edited

Legend:

Unmodified
Added
Removed
  • nagslang/widgets/text.py

    r196 r237  
     1from nagslang.constants import FONT, FONT_SIZE
     2from nagslang.widgets.base import Widget
    13import pygame
    24
    3 from nagslang.constants import FONT, FONT_SIZE
    4 from nagslang.widgets.base import Widget
    55from nagslang.utils import convert_colour
    66from nagslang.resources import resources
     
    3232
    3333
     34class MultiLineWidget(TextWidget):
     35
     36    def prepare(self):
     37        self.font = resources.get_font(self.fontname, self.fontsize)
     38        surfaces = []
     39        height = 0
     40        width = 0
     41        for line in self.text.split('\n'):
     42            surface = self.font.render(line, True, self.colour)
     43            width = max(width, surface.get_rect().width)
     44            height += surface.get_rect().height
     45            surfaces.append(surface)
     46        self.surface = pygame.surface.Surface((width, height))
     47        self.surface.fill(pygame.Color('white'))
     48        y = 0
     49        for surface in surfaces:
     50            self.surface.blit(surface, (0, y))
     51            y += surface.get_rect().height
     52
     53
    3454class LabelWidget(TextWidget):
    3555    def __init__(self, *args, **kwargs):
Note: See TracChangeset for help on using the changeset viewer.