Skip to content

Commit 8a72116

Browse files
committed
Handle both fill directions
Handles bottom-to-top and top-to-bottom for vertical, and left-to-right as well as right-to-left for horizontal
1 parent e6a0c73 commit 8a72116

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

adafruit_progressbar/__init__.py

+1-10
Original file line numberDiff line numberDiff line change
@@ -491,13 +491,11 @@ def _adjust_size_for_range_limits(
491491
# If we have *ANY* value other than "zero" (minimum), we should
492492
# have at least one element showing
493493
if _new_value_size == 0 and _new_value > self.minimum:
494-
print(f"Adjust 1 up for {_new_value}")
495494
_new_value_size = 1
496495

497496
# Conversely, if we have *ANY* value other than 100% (maximum),
498497
# we should NOT show a full bar.
499498
if _new_value_size == self._get_max_fill_size() and _new_value < self.maximum:
500-
print(f"Adjust 1 down for {_new_value}")
501499
_new_value_size -= 1
502500

503501
return _new_value_size
@@ -550,7 +548,6 @@ def _render(
550548
_new_value_size = self._adjust_size_for_range_limits(
551549
_new_value_size, _new_value
552550
)
553-
_render_offset = self.margin_size + self.border_thickness
554551

555552
# Default values for increasing value
556553
_color = 2
@@ -569,13 +566,7 @@ def _render(
569566
if _new_value == self.minimum:
570567
_start += 1
571568

572-
# if self._invert_fill_direction():
573-
# _ref_pos = self.widget_height - _render_offset
574-
# self._debug("Ref pos: ", _ref_pos)
575-
# _end = _ref_pos - _end # Those pesky "off-by-one" issues
576-
# _start = _ref_pos - _start
577-
# _incr = -1 if _start > _end else 1
578-
# _color = 0 if _old_value > _new_value else 2
569+
_render_offset = self.margin_size + self.border_thickness
579570

580571
vert_start, vert_end, vert_incr = self._get_vertical_fill(_start, _end, _incr)
581572
horiz_start, horiz_end, horiz_incr = self._get_horizontal_fill(

adafruit_progressbar/horizontalprogressbar.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,12 @@ def _get_value_sizes(self, _old_ratio: float, _new_ratio: float) -> Tuple[int, i
147147
def _get_horizontal_fill(
148148
self, _start: int, _end: int, _incr: int
149149
) -> Tuple[int, int, int]:
150-
return _start, _end, _incr
150+
if not self._invert_fill_direction():
151+
return _start, _end, _incr
152+
153+
base_offset = self.fill_width() - 1
154+
155+
return base_offset - _start, base_offset - _end, _incr * -1
151156

152157
def _invert_fill_direction(self) -> bool:
153158
return self._direction == HorizontalFillDirection.RIGHT_TO_LEFT

adafruit_progressbar/verticalprogressbar.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,12 @@ def _get_value_sizes(self, _old_ratio: float, _new_ratio: float) -> Tuple[int, i
149149
def _get_vertical_fill(
150150
self, _start: int, _end: int, _incr: int
151151
) -> Tuple[int, int, int]:
152-
return _start, _end, _incr
152+
if not self._invert_fill_direction():
153+
return _start, _end, _incr
154+
155+
base_offset = self.fill_height() - 1
156+
157+
return base_offset - _start, base_offset - _end, _incr * -1
153158

154159
def _invert_fill_direction(self) -> bool:
155160
return self._direction == VerticalFillDirection.BOTTOM_TO_TOP

0 commit comments

Comments
 (0)