From db2600391994bab6339a2c812d90fe535f92b09f Mon Sep 17 00:00:00 2001 From: mohad12211 Date: Fri, 6 Feb 2026 22:43:41 +0300 Subject: [PATCH] Use ink_rect to draw and set alignment before getting dimensions --- discover_overlay/voice_overlay.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/discover_overlay/voice_overlay.py b/discover_overlay/voice_overlay.py index b84e517..a1bb965 100644 --- a/discover_overlay/voice_overlay.py +++ b/discover_overlay/voice_overlay.py @@ -862,6 +862,12 @@ def draw_text(self, context, string, pos_x, pos_y, if font: font = Pango.FontDescription(font) layout.set_font_description(font) + + if self.align_right: + layout.set_alignment(Pango.Alignment.RIGHT) + else: + layout.set_alignment(Pango.Alignment.LEFT) + (ink_rect, logical_rect) = layout.get_pixel_extents() text_height = logical_rect.height text_width = logical_rect.width @@ -883,10 +889,9 @@ def draw_text(self, context, string, pos_x, pos_y, self.col(tx_col) context.move_to( - pos_x - text_width - self.text_pad - ink_rect.x, + (pos_x - self.text_pad) - (ink_rect.x + ink_rect.width), pos_y + text_y_offset ) - layout.set_alignment(Pango.Alignment.RIGHT) PangoCairo.show_layout(self.context, layout) else: context.move_to(0, 0) @@ -901,10 +906,9 @@ def draw_text(self, context, string, pos_x, pos_y, self.col(tx_col) context.move_to( - pos_x + self.text_pad + avatar_size- ink_rect.x, + (pos_x + self.text_pad + avatar_size) - ink_rect.x, pos_y + text_y_offset ) - layout.set_alignment(Pango.Alignment.LEFT) PangoCairo.show_layout(self.context, layout) context.restore() return text_width