Skip to content

Fix DisplayProgressBar horizontal bar filling wrong side (fixes #982)#984

Merged
mathoudebine merged 1 commit intomathoudebine:mainfrom
MondoBoricua:fix/progress-bar-horizontal-direction
Apr 15, 2026
Merged

Fix DisplayProgressBar horizontal bar filling wrong side (fixes #982)#984
mathoudebine merged 1 commit intomathoudebine:mainfrom
MondoBoricua:fix/progress-bar-horizontal-direction

Conversation

@MondoBoricua
Copy link
Copy Markdown
Contributor

Summary

Fixes #982 — horizontal progress bars rendered the empty portion in BAR_COLOR instead of the filled portion.

Root cause

In commit db59686 ("refactor code, inverse now a graph setting"), DisplayProgressBar() was refactored to use shared x1/y1/x2/y2 defaults (x1=0, y1=0, x2=width-1, y2=height-1) and assign one coordinate per branch. The horizontal non-reverse branch assigned the wrong one:

if width > height:
    if reverse_direction is True:
        x1 = width - bar_filled_width   # correct — draws [w-bfw, 0, w-1, h-1]
    else:
        x1 = bar_filled_width           # BUG — draws [bfw, 0, w-1, h-1] (empty side)

Pre-refactor code drew rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color) — i.e. x2 was the variable being assigned, not x1.

Fix

One-line change: assign x2 = bar_filled_width instead of x1. The vertical branches and the reverse_direction=True horizontal branch were already correct after the refactor and are unchanged.

Testing

Verified on a UsbMonitor 3.5" (Revision A) with the DragonBall theme — horizontal CPU/DISK/GPU bars now fill from the left as expected, matching pre-refactor behavior.

The refactor in db59686 ("refactor code, inverse now a graph setting")
introduced shared x1/y1/x2/y2 defaults and assigned the wrong coordinate
in the horizontal non-reverse branch: x1 was set to bar_filled_width
instead of x2, which caused the bar to render the empty portion in
BAR_COLOR and the filled portion in BACKGROUND_COLOR.

Pre-refactor code drew [0, 0, bar_filled_width, height - 1] — i.e. x2
was the variable, not x1. Restoring that behavior fixes the inversion
while leaving the reverse_direction and vertical branches unchanged
(those were already correct after the refactor).

Fixes mathoudebine#982
Copilot AI review requested due to automatic review settings April 15, 2026 18:42
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a regression in DisplayProgressBar() where horizontal (width > height), non-reversed progress bars were drawing the empty portion with BAR_COLOR instead of the filled portion, restoring pre-refactor fill behavior.

Changes:

  • Correct the horizontal non-reverse branch to set x2 (filled end) rather than x1 (filled start).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread library/lcd/lcd_comm.py
@@ -378,7 +378,7 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
if reverse_direction is True:
x1 = width - bar_filled_width
@mathoudebine mathoudebine merged commit a598520 into mathoudebine:main Apr 15, 2026
42 of 43 checks passed
@mathoudebine
Copy link
Copy Markdown
Owner

Thank you for the PR! I also needed to add a hotfix because the vertical bars were not drawing the expected state e.g. for 25% the bar was displaying 75%. Everything is now on the main branch

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: horizontal bar fills wrong side (empty portion colored instead of filled portion)

3 participants