Skip to content

DisplayProgressBar: honour min_value when computing fill width#987

Open
SAY-5 wants to merge 1 commit intomathoudebine:mainfrom
SAY-5:fix-progressbar-min-value-954
Open

DisplayProgressBar: honour min_value when computing fill width#987
SAY-5 wants to merge 1 commit intomathoudebine:mainfrom
SAY-5:fix-progressbar-min-value-954

Conversation

@SAY-5
Copy link
Copy Markdown

@SAY-5 SAY-5 commented Apr 17, 2026

Fixes #954.

Problem

DisplayProgressBar in library/lcd/lcd_comm.py computes the filled extent from the raw value, not the value's offset from min_value:

bar_filled_width = (value / (max_value - min_value) * width) - 1

When min_value == 0 (default) this is correct, which is why the bug has gone unnoticed. For any bar with a non-zero minimum (e.g. a 25..95 temperature bar) the fill is wrong:

value min max buggy fill correct fill
25 25 95 36% 0%
60 25 95 86% 50%
95 25 95 136% 100%

DisplayRadialProgressBar (around line 560) already uses the offset-from-min form:

pct = (value - min_value) / (max_value - min_value)

Fix

Subtract min_value in both the horizontal and vertical branches of DisplayProgressBar so the two bar primitives agree. One-character change per branch.

Signed off per DCO.

Reported as mathoudebine#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 mathoudebine#954

Signed-off-by: Sai Asish Y <say.apm35@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DisplayProgressBar: min_value ignored in fill width calculation

1 participant