-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
We actually already have a UI class in here.
- Loading branch information
1 parent
c4c66a6
commit d8e4587
Showing
2 changed files
with
28 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,34 @@ | ||
from common_shapes import Rectangle | ||
from drawable import Drawable | ||
|
||
from core import Colors | ||
class Button(Drawable): | ||
|
||
from drawable import Drawable | ||
DEFAULT_FONT = pygame.font.Font(None, 24) | ||
VPADDING = 18 | ||
HPADDING = 18 | ||
|
||
from shapes import Point | ||
from shapes import PointShape | ||
def __init__(self, label, color, position, draw_offset, label_font=None): | ||
""" | ||
Draws a rectangular button. | ||
""" | ||
This module manages some common-UI functionalities like buttons | ||
and menus. | ||
position is the position of the upper-left corner of the button. | ||
""" | ||
self.label = label | ||
self.color = color | ||
self.position = position | ||
self.__action = lambda event: event | ||
# TODO Handle labels that are too long. | ||
size = Button.DEFAULT_FONT.size(label) | ||
super(Button, self).__init__( | ||
draw_offset, size[1] + Button.VPADDING, size[0] + Button.HPADDING | ||
) | ||
|
||
TODO: Maybe, integrate this with common_shapes ? | ||
TODO: If we are to use common shapes with this, we must have a facility | ||
to flood fill PointShapes. | ||
""" | ||
@property | ||
def action(self): | ||
return self.__action | ||
|
||
class Button(Drawable): | ||
""" | ||
A button has three states: untouched, hover, and pushed. | ||
""" | ||
|
||
def __init__(self, upper_left, lower_right, text, draw_offset=0, btn_color=Colors.LUCID_DARK, text_color=Colors.WHITE): | ||
self.button_area = Rectangle(upper_left, lower_right) | ||
self.button_text = text | ||
self.text_color = text_color | ||
super(Button, self).__init__(draw_offset) | ||
@action.setter | ||
def action(self, handler): | ||
self.__action = handler | ||
|
||
def draw(self, window, screen, **kwargs): | ||
pygame.draw.rect(window, self.color, (self.position[1], self.position[0], self.max_size[0], self.max_size[1])) |
This file was deleted.
Oops, something went wrong.