From 5a510e5aef5cd328b5e33eda31a2192533b6737e Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Fri, 19 Jul 2024 00:54:20 -0400 Subject: [PATCH 1/3] add getmetrics to add descent heigh to PSBT Maths and FormattedAddress --- src/seedsigner/gui/components.py | 4 +++- src/seedsigner/gui/screens/psbt_screens.py | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/seedsigner/gui/components.py b/src/seedsigner/gui/components.py index 0706f213..a66afd24 100644 --- a/src/seedsigner/gui/components.py +++ b/src/seedsigner/gui/components.py @@ -22,6 +22,7 @@ class GUIConstants: EDGE_PADDING = 8 COMPONENT_PADDING = 8 LIST_ITEM_PADDING = 4 + FIXED_FONT_HEIGHT_PADDING = 6 BACKGROUND_COLOR = "black" WARNING_COLOR = "#FFD60A" @@ -616,7 +617,8 @@ class FormattedAddress(BaseComponent): # Fixed width font means we only have to measure one max-height character left, top, right, bottom = self.font.getbbox("Q") - char_width, char_height = right - left, bottom - top + ascent, descent = self.font.getmetrics() + char_width, char_height = right - left, bottom - top + descent n = 7 display_str = f"{self.address[:n]} {self.address[n:-1*n]} {self.address[-1*n:]}" diff --git a/src/seedsigner/gui/screens/psbt_screens.py b/src/seedsigner/gui/screens/psbt_screens.py index 502c3921..92211aaf 100644 --- a/src/seedsigner/gui/screens/psbt_screens.py +++ b/src/seedsigner/gui/screens/psbt_screens.py @@ -511,8 +511,9 @@ class PSBTMathScreen(ButtonListScreen): body_font = Fonts.get_font(GUIConstants.BODY_FONT_NAME, (GUIConstants.BODY_FONT_SIZE)*ssf) fixed_width_font = Fonts.get_font(GUIConstants.FIXED_WIDTH_FONT_NAME, (GUIConstants.BODY_FONT_SIZE + 6)*ssf) - left, top, right, bottom = fixed_width_font.getbbox(self.input_amount + "+") - digits_width, digits_height = right - left, bottom - top + left, top, right, bottom = fixed_width_font.getbbox(self.input_amount + "Q") + ascent, descent = fixed_width_font.getmetrics() + digits_width, digits_height = right - left, bottom - top + descent # Draw each line of the equation cur_y = 0 From a18719028fc500c6730bcd60da304ed8afa7e5d6 Mon Sep 17 00:00:00 2001 From: Nick Klockenga Date: Fri, 19 Jul 2024 14:25:20 -0400 Subject: [PATCH 2/3] remove unused constant --- src/seedsigner/gui/components.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/seedsigner/gui/components.py b/src/seedsigner/gui/components.py index a66afd24..a086183c 100644 --- a/src/seedsigner/gui/components.py +++ b/src/seedsigner/gui/components.py @@ -22,7 +22,6 @@ class GUIConstants: EDGE_PADDING = 8 COMPONENT_PADDING = 8 LIST_ITEM_PADDING = 4 - FIXED_FONT_HEIGHT_PADDING = 6 BACKGROUND_COLOR = "black" WARNING_COLOR = "#FFD60A" From 2089f482ca4dfdff8d8b35232814c9966cb91539 Mon Sep 17 00:00:00 2001 From: kdmukai Date: Fri, 19 Jul 2024 17:12:36 -0500 Subject: [PATCH 3/3] Suggested cleanups --- src/seedsigner/gui/components.py | 5 ++--- src/seedsigner/gui/screens/psbt_screens.py | 11 +++++------ 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/seedsigner/gui/components.py b/src/seedsigner/gui/components.py index a086183c..9193e451 100644 --- a/src/seedsigner/gui/components.py +++ b/src/seedsigner/gui/components.py @@ -616,8 +616,7 @@ class FormattedAddress(BaseComponent): # Fixed width font means we only have to measure one max-height character left, top, right, bottom = self.font.getbbox("Q") - ascent, descent = self.font.getmetrics() - char_width, char_height = right - left, bottom - top + descent + char_width, char_height = right - left, bottom - top n = 7 display_str = f"{self.address[:n]} {self.address[n:-1*n]} {self.address[-1*n:]}" @@ -740,7 +739,7 @@ class FormattedAddress(BaseComponent): )) remaining_display_str = remaining_display_str[max_chars_per_line:] - cur_y += char_height + cur_y += char_height + GUIConstants.BODY_LINE_SPACING self.height = cur_y diff --git a/src/seedsigner/gui/screens/psbt_screens.py b/src/seedsigner/gui/screens/psbt_screens.py index 92211aaf..36a2b895 100644 --- a/src/seedsigner/gui/screens/psbt_screens.py +++ b/src/seedsigner/gui/screens/psbt_screens.py @@ -512,8 +512,7 @@ class PSBTMathScreen(ButtonListScreen): body_font = Fonts.get_font(GUIConstants.BODY_FONT_NAME, (GUIConstants.BODY_FONT_SIZE)*ssf) fixed_width_font = Fonts.get_font(GUIConstants.FIXED_WIDTH_FONT_NAME, (GUIConstants.BODY_FONT_SIZE + 6)*ssf) left, top, right, bottom = fixed_width_font.getbbox(self.input_amount + "Q") - ascent, descent = fixed_width_font.getmetrics() - digits_width, digits_height = right - left, bottom - top + descent + digits_width, digits_height = right - left, bottom - top # Draw each line of the equation cur_y = 0 @@ -551,7 +550,7 @@ class PSBTMathScreen(ButtonListScreen): # spend_amount will be zero on self-transfers; only display when there's an # external recipient. if self.num_recipients > 0: - cur_y += int(digits_height * 1.2) + cur_y += digits_height + GUIConstants.BODY_LINE_SPACING * ssf render_amount( cur_y, f"-{self.spend_amount}", @@ -559,16 +558,16 @@ class PSBTMathScreen(ButtonListScreen): info_text=f""" recipient{"s" if self.num_recipients > 1 else ""}""", ) - cur_y += int(digits_height * 1.2) + cur_y += digits_height + GUIConstants.BODY_LINE_SPACING * ssf render_amount( cur_y, f"-{self.fee_amount}", info_text=f""" fee""", ) - cur_y += int(digits_height * 1.2) + 4 * ssf + cur_y += digits_height + GUIConstants.BODY_LINE_SPACING * ssf draw.line((0, cur_y, image.width, cur_y), fill=GUIConstants.BODY_FONT_COLOR, width=1) - cur_y += 8 * ssf + cur_y += GUIConstants.BODY_LINE_SPACING * ssf render_amount( cur_y,