93
|
1 import pygame
|
|
2
|
|
3 from mamba.widgets.text import TextWidget
|
|
4
|
|
5
|
|
6 class ImageButtonWidget(TextWidget):
|
|
7 """Text label with image on the left"""
|
|
8
|
|
9 def __init__(self, rect, image, text, fontsize=16, color='black'):
|
|
10 self.image = image
|
|
11 super(ImageButtonWidget, self).__init__(rect, text, fontsize, color)
|
|
12
|
|
13 def prepare(self):
|
|
14 super(ImageButtonWidget, self).prepare()
|
|
15 text_surface = self.font.render(self.text, True, self.color)
|
|
16 # Image is already a surface
|
|
17 self.rect.width = text_surface.get_width() + self.image.get_width() + 5
|
|
18 self.rect.height = text_surface.get_height() + self.image.get_height()
|
|
19 self.surface = pygame.Surface((self.rect.width, self.rect.height))
|
|
20 self.surface.blit(self.image, (0, 0))
|
|
21 self.surface.blit(text_surface, (self.image.get_width() + 5, 0))
|