From 13991f31dfcc1df094ce8e4d47f1abbfc74a1673 Mon Sep 17 00:00:00 2001 From: Dejvino Date: Thu, 20 Apr 2023 10:29:51 +0200 Subject: [PATCH] Centered font test --- test.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/test.py b/test.py index 54f2d79..af9da70 100644 --- a/test.py +++ b/test.py @@ -107,18 +107,32 @@ def draw_pattern(): epd.fill_rect(0, 0, epd_resolution[0], free_y, random.randrange(2,7)) return [free_x, free_y, free_width, free_height] -def print_text(text, region): +def print_text(text, region, center=False): global epd - epd.text(text, region[0]+5, region[1]+5, epd.Black) + fnt = 8 + x = region[0] + y = region[1] + w = region[2] + h = region[3] + if center: + x = (w - len(text)*fnt) // 2 + epd.text(text, x, y, epd.Black) def draw_extra(region): fnt = 8 + region[0] += 5 + region[1] += 5 if region[2] < fnt or region[3] < fnt: print("Not enough space for extra: ", str(region)) return #epd.rect(region[0], region[1], region[2], region[3], epd.Black) #region[0] += random.randrange(50) - print_text("Lorem ipsum: " + str(random.randrange(1000, 999999)), region) + print_text(str(time.localtime()), region, center=True) + region[1] += fnt * 3 + print_text(" Today: Rainy, 24 C", region) + + region[1] += fnt * 2 + print_text("Tomorrow: Sunshine, 26 C", region) # MAIN