Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Control Board: Use Pillow 10 API for getting text size #1400

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions python/ctrlboard/src/menu/menu_renderer.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def __init__(self, config: MenuRendererConfig):
self.draw = ImageDraw.Draw(self.image)
self.font = ImageFont.truetype(config.font_path, size=config.font_size)
# just a sample text to work with the font height
_, self.font_height = self.font.getsize("ABCabc")
self.font_height = self.font.getbbox("ABCabc")[3]
self.cursor_position = 0
self.frame_start_row = 0
self.render_timestamp = None
Expand Down Expand Up @@ -153,7 +153,8 @@ def draw_row(self, row_number: int, text: str, selected: bool):

def draw_fullsceen_message(self, text: str):
"""Draws a fullscreen message, i.e., a full-screen message."""
font_width, font_height = self.font.getsize(text)
font_width = self.font.getlength(text)
font_height = self.font.getbbox(text)[3]
centered_width = (self.disp.width - font_width) / 2
centered_height = (self.disp.height - font_height) / 2

Expand All @@ -171,7 +172,7 @@ def draw_fullsceen_message(self, text: str):
def draw_mini_message(self, text: str):
"""Draws a fullscreen message, i.e., a message covering only the center portion of
the screen. The remaining areas stay visible."""
font_width, _ = self.font.getsize(text)
font_width = self.font.getlength(text)
centered_width = (self.disp.width - font_width) / 2
centered_height = (self.disp.height - self.font_height) / 2

Expand Down Expand Up @@ -270,7 +271,7 @@ def render(self, display_on_device=True):

def setup_horizontal_scrolling(self, text):
"""Configure horizontal scrolling based on the configured screen dimensions."""
font_width, _ = self.font.getsize(text)
font_width = self.font.getlength(text)
self._current_line_horizontal_overlap = font_width - self.disp.width

def update(self):
Expand Down