Skip to content

Commit

Permalink
[26] Properly handle very tall text in stripe boundary calcs in Strip…
Browse files Browse the repository at this point in the history
…ed card
  • Loading branch information
CollinHeist committed Jul 20, 2024
1 parent 95644aa commit 4ad6f6f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
28 changes: 18 additions & 10 deletions modules/cards/StripedTitleCard.py
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,6 @@ def _x_at(y: float, b: float) -> float:
bottom_y_bound = self.HEIGHT - self.inset

# Limit bounds of y-coordinates to not overlap with text
# log.debug(f'{b0} : {b1} | {_x_at(text_height, b0)} < {text_width}')
if ((self.text_position == 'upper left'
and _x_at(text_height, b0) < text_width)
or (self.text_position == 'upper right'
Expand All @@ -545,17 +544,26 @@ def _x_at(y: float, b: float) -> float:
or (self.text_position == 'lower right'
and _x_at(text_height, b1) > self.WIDTH - text_width)):
bottom_y_bound = self.HEIGHT - text_height
# log.debug(f'Limiting bottom_y to {text_height} from bottom')

# Pick random y-coordinates for the top and bottom of the polygon
top_y = randint(
min(top_y_bound, self._MIN_SHAPE_HEIGHT // 3),
(self.HEIGHT // 2) - (self._MIN_SHAPE_HEIGHT) // 3),
)
bottom_y = randint(
(self.HEIGHT // 2) + (self._MIN_SHAPE_HEIGHT // 3),
max(bottom_y_bound, self._MIN_SHAPE_HEIGHT // 3),
)
try:
top_y = randint(
top_y_bound,
(self.HEIGHT // 2) - (self._MIN_SHAPE_HEIGHT // 3),
)
except ValueError:
# Text too high, limit to any height or only smallest possible
# top_y = randint(self.inset, self.HEIGHT // 2)
top_y = (self.HEIGHT // 2) - (self._MIN_SHAPE_HEIGHT // 3)
try:
bottom_y = randint(
(self.HEIGHT // 2) + (self._MIN_SHAPE_HEIGHT // 3),
bottom_y_bound,
)
except ValueError:
# Text too high, limit to any height or only smallest possible
# bottom_y = randint(self.HEIGHT // 2, self.HEIGHT - self.inset)
bottom_y = (self.HEIGHT // 2) + (self._MIN_SHAPE_HEIGHT // 3)

# For drawing the polygon, "invert" the y-coordinate used in
# the x-coordinate calculation since the canvas 0 is at the
Expand Down
2 changes: 1 addition & 1 deletion modules/ref/version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.16.0-develop25
v1.16.0-develop26

0 comments on commit 4ad6f6f

Please sign in to comment.