Skip to content

Commit 17f13b4

Browse files
committed
DisplayProgressBar: honour min_value when computing fill width
Reported as #954. DisplayProgressBar computes the filled extent from the raw value rather than the value's offset from min_value: bar_filled_width = (value / (max_value - min_value) * width) - 1 When min_value is 0 (default) this happens to be correct, which is why the bug has not surfaced. For any bar with a non-zero minimum (e.g. a temperature bar with min=25, max=95) the fill is wrong: value=25 renders at 36% instead of 0%, value=95 overshoots the bar. DisplayRadialProgressBar already uses the offset-from-min formula a couple of hundred lines down, so the two bar primitives are now consistent. Fixes #954 Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
1 parent 396bdb6 commit 17f13b4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

library/lcd/lcd_comm.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -357,13 +357,17 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
357357
# Crop bitmap to keep only the progress bar background
358358
bar_image = bar_image.crop(box=(x, y, x + width, y + height))
359359

360-
# Draw progress bar
360+
# Draw progress bar. Fill has to be computed from the offset
361+
# into [min_value, max_value], not the raw value; otherwise a
362+
# bar with min_value > 0 (e.g. a 25..95 temperature bar) is
363+
# filled by the wrong fraction. DisplayRadialProgressBar below
364+
# already does this correctly. See issue #954.
361365
if width > height:
362-
bar_filled_width = (value / (max_value - min_value) * width) - 1
366+
bar_filled_width = ((value - min_value) / (max_value - min_value) * width) - 1
363367
if bar_filled_width < 0:
364368
bar_filled_width = 0
365369
else:
366-
bar_filled_height = (value / (max_value - min_value) * height) - 1
370+
bar_filled_height = ((value - min_value) / (max_value - min_value) * height) - 1
367371
if bar_filled_height < 0:
368372
bar_filled_height = 0
369373
draw = ImageDraw.Draw(bar_image)

0 commit comments

Comments
 (0)