Skip to content

Commit

Permalink
Stash
Browse files Browse the repository at this point in the history
  • Loading branch information
jinglemansweep committed Nov 19, 2023
1 parent d4b2b8d commit c3634df
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
18 changes: 17 additions & 1 deletion testing/sprites/lib/tile_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,15 @@ class CellStyle:
text_antialias: bool = True


class IconStyle:
visible: bool = True
icon: str = ""
width: int = TILE_GRID_CELL_HEIGHT # should be height
height: int = TILE_GRID_CELL_HEIGHT
color_background: pygame.Color = pygame.Color(255, 255, 0, 255)
color_foreground: pygame.Color = pygame.Color(255, 255, 255, 255)


# HELPER FUNCTIONS


Expand Down Expand Up @@ -161,6 +170,7 @@ class BaseSprite(pygame.sprite.Sprite):

class TileGridCell(BaseSprite):
style: CellStyle = CellStyle()
icon: IconStyle = IconStyle()
width: int = TILE_GRID_CELL_WIDTH
height: int = TILE_GRID_CELL_HEIGHT
visible: bool = True
Expand All @@ -179,8 +189,14 @@ def update(self):
def render(self, state):
self.image = pygame.Surface((self.rect.width, self.rect.height))
self.image.fill(self.style.color_background)
cx, cy = 0, 0
if self.icon.visible:
icon_surface = pygame.surface.Surface((self.icon.width, self.icon.height))
icon_surface.fill(self.icon.color_background)
self.image.blit(icon_surface, (0, 0))
cx += self.icon.width
label_surface = render_text(self.label, self.style)
self.image.blit(label_surface, (0, 0))
self.image.blit(label_surface, (cx, 0))
self.rect = self.image.get_rect()

def __repr__(self):
Expand Down
6 changes: 3 additions & 3 deletions testing/sprites/tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,34 +25,34 @@ class StyleBlueBackground(CellStyle):


class CellSpeedTestDownload(VerticalCollapseTileGridCell):
label = "Download"
style = StyleRedBackground()

def update(self):
super().update()
v = int(self.state.get("download", 0))
self.label = f"{v}Mb"
open = v > 500
self.height_animator.set(open)


class CellSpeedTestUpload(VerticalCollapseTileGridCell):
label = "Upload"
style = StyleGreenBackground()

def update(self):
super().update()
v = int(self.state.get("upload", 0))
self.label = f"{v}Mb"
open = v > 500
self.height_animator.set(open)


class CellSpeedTestPing(VerticalCollapseTileGridCell):
label = "Ping"
style = StyleBlueBackground()

def update(self):
super().update()
v = int(self.state.get("ping", 0))
self.label = f"{v}ms"
open = v > 25
self.height_animator.set(open)

Expand Down

0 comments on commit c3634df

Please sign in to comment.