Skip to content

Commit 1bedfcb

Browse files
committed
Check for negative width for progress bar
1 parent 4e2e1aa commit 1bedfcb

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

library/lcd/lcd_comm.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,11 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
262262
bar_image = bar_image.crop(box=(x, y, x + width, y + height))
263263

264264
# Draw progress bar
265-
bar_filled_width = value / (max_value - min_value) * width
265+
bar_filled_width = (value / (max_value - min_value) * width) - 1
266+
if bar_filled_width < 0:
267+
bar_filled_width = 0
266268
draw = ImageDraw.Draw(bar_image)
267-
draw.rectangle([0, 0, bar_filled_width - 1, height - 1], fill=bar_color, outline=bar_color)
269+
draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color)
268270

269271
if bar_outline:
270272
# Draw outline

0 commit comments

Comments
 (0)