@@ -332,6 +332,16 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
332332 bar_color = parse_color (bar_color )
333333 background_color = parse_color (background_color )
334334
335+ inverse = False
336+ # Assume we want to invert the direction is width or height are negative
337+ if width < 0 :
338+ inverse = True
339+ width = width * - 1
340+
341+ if height < 0 :
342+ inverse = True
343+ height = height * - 1
344+
335345 assert x <= self .get_width (), 'Progress bar X coordinate must be <= display width'
336346 assert y <= self .get_height (), 'Progress bar Y coordinate must be <= display height'
337347 assert x + width <= self .get_width (), 'Progress bar width exceeds display width'
@@ -366,9 +376,15 @@ def DisplayProgressBar(self, x: int, y: int, width: int, height: int, min_value:
366376 bar_filled_height = 0
367377 draw = ImageDraw .Draw (bar_image )
368378 if width > height :
369- draw .rectangle ([0 , 0 , bar_filled_width , height - 1 ], fill = bar_color , outline = bar_color )
379+ if inverse is True :
380+ draw .rectangle ([width - bar_filled_width , 0 , width - 1 , height - 1 ], fill = bar_color , outline = bar_color )
381+ else :
382+ draw .rectangle ([0 , 0 , bar_filled_width , height - 1 ], fill = bar_color , outline = bar_color )
370383 else :
371- draw .rectangle ([0 , height - bar_filled_height , width - 1 , height - 1 ], fill = bar_color , outline = bar_color )
384+ if inverse is True :
385+ draw .rectangle ([0 , 0 , width - 1 , height - bar_filled_height ], fill = bar_color , outline = bar_color )
386+ else :
387+ draw .rectangle ([0 , bar_filled_height , width - 1 , height - 1 ], fill = bar_color , outline = bar_color )
372388
373389 if bar_outline :
374390 # Draw outline
0 commit comments