Skip to content

Commit

Permalink
fix(layouts): get width once
Browse files Browse the repository at this point in the history
  • Loading branch information
loiccoyle committed Jun 19, 2024
1 parent 716c02c commit 7cba866
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions tinyticker/layouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,10 @@ def _adjust_text_width(text: Text, max_width: int, fontsize: int) -> Text:
"""
# try the provided fontsize
text.set_fontsize(fontsize)
if text.get_window_extent().width > max_width:
text_width = text.get_window_extent().width
if text_width > max_width:
# adjust the fontsize to fit within the width
text.set_fontsize(fontsize * max_width / text.get_window_extent().width)
text.set_fontsize(fontsize * max_width / text_width)
return text


Expand Down

0 comments on commit 7cba866

Please sign in to comment.