diff --git a/py/hexagram/speedo.py b/py/hexagram/speedo.py index 41aa1c0..649b14f 100644 --- a/py/hexagram/speedo.py +++ b/py/hexagram/speedo.py @@ -45,6 +45,8 @@ class Speedo(Dial): def draw_fg(self, cr: cairo.Context): super().draw_fg(cr) + text = "%d mph" % self.value + cr.select_font_face("Muli", cairo.FontSlant.ITALIC, cairo.FontWeight.BOLD) @@ -52,7 +54,11 @@ class Speedo(Dial): cr.set_font_size(self.radius * 0.15) cr.set_source_rgb(1, 0.4, 1) - cr.move_to(self.x - (self.radius * 0.21), - self.y + (self.radius * 0.05)) + extents = cr.text_extents(text) + width = extents[2] - extents[0] + height = extents[3] - extents[1] - cr.show_text("%d mph" % self.value) + cr.move_to(self.x - width / 2, + self.y + height / 4) + + cr.show_text(text) diff --git a/py/hexagram/tacho.py b/py/hexagram/tacho.py index fc6f95d..b658c00 100644 --- a/py/hexagram/tacho.py +++ b/py/hexagram/tacho.py @@ -82,12 +82,18 @@ class Tacho(Dial): def draw_fg(self, cr: cairo.Context): super().draw_fg(cr) + text = str(self.gear) + cr.select_font_face("HEX:gon Bold Italic") cr.set_font_size(self.radius * 0.4) cr.set_source_rgb(1, 0.4, 1) - cr.move_to(self.x - (self.radius * 0.21), - self.y + (self.radius * 0.18)) + extents = cr.text_extents(text) + width = extents[2] - extents[0] + height = extents[3] - extents[1] + + cr.move_to(self.x - width / 2, + self.y + height / 4) cr.show_text(str(self.gear))