From 323bc7355188a02c262c62c84af9ca8b9ec85c32 Mon Sep 17 00:00:00 2001 From: Skullheadx Date: Thu, 13 Apr 2023 21:30:08 -0400 Subject: [PATCH] Create container.py --- container.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 container.py diff --git a/container.py b/container.py new file mode 100644 index 0000000..51c347b --- /dev/null +++ b/container.py @@ -0,0 +1,39 @@ +import pygame +from color import Color +from rectangle import Rectangle +from text import Text, Label +from button import Button + + +class Container: + def __init__(self, x, y, width, height, background_color=Color.WHITE, border_color=Color.BLACK, border_width=0, + border_radius=0, padding=10): + self.x = x + self.y = y + self.width = width + self.height = height + self.background_color = background_color + self.border_color = border_color + self.border_width = border_width + self.border_radius = border_radius + self.padding = padding + + self.children = [] + + def add_child(self, child): + self.children.append(child) + + def remove_child(self, child): + self.children.remove(child) + + def draw(self, screen): + # Draw background + pygame.draw.rect(screen, self.background_color, (self.x, self.y, self.width, self.height), 0, self.border_radius) + + # Draw border + pygame.draw.rect(screen, self.border_color, (self.x, self.y, self.width, self.height), self.border_width, + self.border_radius) + + # Draw children + for child in self.children: + child.draw(screen) \ No newline at end of file -- 2.54.0