Centered font test

This commit is contained in:
Dejvino 2023-04-20 10:29:51 +02:00
parent 206f00e96d
commit 13991f31df

20
test.py
View File

@ -107,18 +107,32 @@ def draw_pattern():
epd.fill_rect(0, 0, epd_resolution[0], free_y, random.randrange(2,7)) epd.fill_rect(0, 0, epd_resolution[0], free_y, random.randrange(2,7))
return [free_x, free_y, free_width, free_height] return [free_x, free_y, free_width, free_height]
def print_text(text, region): def print_text(text, region, center=False):
global epd 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): def draw_extra(region):
fnt = 8 fnt = 8
region[0] += 5
region[1] += 5
if region[2] < fnt or region[3] < fnt: if region[2] < fnt or region[3] < fnt:
print("Not enough space for extra: ", str(region)) print("Not enough space for extra: ", str(region))
return return
#epd.rect(region[0], region[1], region[2], region[3], epd.Black) #epd.rect(region[0], region[1], region[2], region[3], epd.Black)
#region[0] += random.randrange(50) #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 # MAIN