Skip to content

Commit

Permalink
We actually already have a UI class in here.
Browse files Browse the repository at this point in the history
  • Loading branch information
skytreader committed Mar 24, 2018
1 parent c4c66a6 commit d8e4587
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 56 deletions.
50 changes: 28 additions & 22 deletions components/common_ui.py
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]))
34 changes: 0 additions & 34 deletions components/ui.py

This file was deleted.

0 comments on commit d8e4587

Please sign in to comment.