feat(text_input): add draw function
This commit is contained in:
+25
-1
@@ -16,5 +16,29 @@ class TextInput:
|
||||
self.border_color = (255, 255, 255)
|
||||
self.active_border_color = (0, 255, 0)
|
||||
self.background_color = (30, 30, 30)
|
||||
|
||||
|
||||
def handle_event(self, event):
|
||||
# todo check keyboard input events
|
||||
pass
|
||||
|
||||
def draw(self, screen):
|
||||
# draw background of input box
|
||||
pygame.draw.rect(screen, self.background_color, self.rect)
|
||||
|
||||
# change border color depending if input box is active or not
|
||||
if self.active:
|
||||
border_color = self.active_border_color
|
||||
else:
|
||||
border_color = self.border_color
|
||||
|
||||
# draw border
|
||||
pygame.draw.rect(screen, border_color, self.rect, 2)
|
||||
|
||||
# draw text
|
||||
text_surface = self.font.render(self.text, True, self.text_color)
|
||||
|
||||
# show text with indentation
|
||||
screen.blit(text_surface, (self.rect.x + 10, self.rect.y + 10))
|
||||
|
||||
def get_text(self):
|
||||
return self.text
|
||||
|
||||
Reference in New Issue
Block a user