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
10 changes: 7 additions & 3 deletions library/lcd/lcd_comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,13 +357,17 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
# Crop bitmap to keep only the progress bar background
bar_image = bar_image.crop(box=(x, y, x + width, y + height))

# Draw progress bar
# Draw progress bar. Fill has to be computed from the offset
# into [min_value, max_value], not the raw value; otherwise a
# bar with min_value > 0 (e.g. a 25..95 temperature bar) is
# filled by the wrong fraction. DisplayRadialProgressBar below
# already does this correctly. See issue #954.
if width > height:
bar_filled_width = (value / (max_value - min_value) * width) - 1
bar_filled_width = ((value - min_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
bar_filled_height = ((value - min_value) / (max_value - min_value) * height) - 1
if bar_filled_height < 0:
bar_filled_height = 0
draw = ImageDraw.Draw(bar_image)
Expand Down
Loading