Skip to content

Commit 9fa22c2

Browse files
authored
Merge pull request #911 from ColinShorts/VerticalProgressBar
2 parents cf0f1db + 1a4875c commit 9fa22c2

File tree

2 files changed

+30
-6
lines changed

2 files changed

+30
-6
lines changed

library/lcd/lcd_comm.py

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,8 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
326326
bar_color: Color = (0, 0, 0),
327327
bar_outline: bool = True,
328328
background_color: Color = (255, 255, 255),
329-
background_image: Optional[str] = None):
329+
background_image: Optional[str] = None,
330+
inverse_direction: Optional[bool] = False):
330331
# Generate a progress bar and display it
331332
# Provide the background image path to display progress bar with transparent background
332333

@@ -357,11 +358,33 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
357358
bar_image = bar_image.crop(box=(x, y, x + width, y + height))
358359

359360
# Draw progress bar
360-
bar_filled_width = (value / (max_value - min_value) * width) - 1
361-
if bar_filled_width < 0:
362-
bar_filled_width = 0
361+
if width > height:
362+
bar_filled_width = (value / (max_value - min_value) * width) - 1
363+
if bar_filled_width < 0:
364+
bar_filled_width = 0
365+
else:
366+
bar_filled_height = (value / (max_value - min_value) * height) - 1
367+
if bar_filled_height < 0:
368+
bar_filled_height = 0
363369
draw = ImageDraw.Draw(bar_image)
364-
draw.rectangle([0, 0, bar_filled_width, height - 1], fill=bar_color, outline=bar_color)
370+
371+
# most common setting
372+
x1 = 0
373+
y1 = 0
374+
x2 = width - 1
375+
y2 = height - 1
376+
377+
if width > height:
378+
if inverse_direction is True:
379+
x1 = width - bar_filled_width
380+
else:
381+
x1 = bar_filled_width
382+
else:
383+
if inverse_direction is True:
384+
y2 = height - bar_filled_height
385+
else:
386+
y1 = bar_filled_height
387+
draw.rectangle([x1, y1, x2, y2], fill=bar_color, outline=bar_color)
365388

366389
if bar_outline:
367390
# Draw outline

library/stats.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def display_themed_progress_bar(theme_data, value):
153153
bar_color=theme_data.get("BAR_COLOR", (0, 0, 0)),
154154
bar_outline=theme_data.get("BAR_OUTLINE", False),
155155
background_color=theme_data.get("BACKGROUND_COLOR", (255, 255, 255)),
156-
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None))
156+
background_image=get_theme_file_path(theme_data.get("BACKGROUND_IMAGE", None)),
157+
inverse_direction=theme_data.get("INVERSE_DIRECTION", False)
157158
)
158159

159160

0 commit comments

Comments
 (0)