Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 28 additions & 4 deletions library/lcd/lcd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,16 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
bar_color = parse_color(bar_color)
background_color = parse_color(background_color)

inverse = False
# Assume we want to invert the direction is width or height are negative
if width < 0:
inverse = True
width = width * -1

if height < 0:
inverse = True
height = height * -1

assert x <= self.get_width(), 'Progress bar X coordinate must be <= display width'
assert y <= self.get_height(), 'Progress bar Y coordinate must be <= display height'
assert x + width <= self.get_width(), 'Progress bar width exceeds display width'
Expand All @@ -356,11 +366,25 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
bar_image = bar_image.crop(box=(x, y, x + width, y + height))

# Draw progress bar
bar_filled_width = (value / (max_value - min_value) * width) - 1
if bar_filled_width < 0:
bar_filled_width = 0
if width > height:
bar_filled_width = (value / (max_value - min_value) * width) - 1
if bar_filled_width < 0:
bar_filled_width = 0
else:
bar_filled_height = (value / (max_value - min_value) * height) - 1
if bar_filled_height < 0:
bar_filled_height = 0
draw = ImageDraw.Draw(bar_image)
draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color)
if width > height:
if inverse is True:
draw.rectangle([width - bar_filled_width, 0, width -1, height - 1], fill=bar_color, outline=bar_color)
else:
draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color)
else:
if inverse is True:
draw.rectangle([0, 0, width - 1, height - bar_filled_height], fill=bar_color, outline=bar_color)
else:
draw.rectangle([0, bar_filled_height, width - 1, height - 1], fill=bar_color, outline=bar_color)

if bar_outline:
# Draw outline
Expand Down