example(tiny_ttf): added MP example (#3707)

This commit is contained in:
Uli Raich
2022-10-26 20:48:12 +02:00
committed by GitHub
parent 677ab54bda
commit 5d50fbc066
3 changed files with 12007 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
from ubuntu_font import ubuntu_font
#
# Load a font with Tiny_TTF
#
#Create style with the new font
style = lv.style_t()
style.init()
font = lv.tiny_ttf_create_data(ubuntu_font, len(ubuntu_font), 30)
style.set_text_font(font)
style.set_text_align(lv.TEXT_ALIGN.CENTER)
# Create a label with the new style
label = lv.label(lv.scr_act())
label.add_style(style, 0)
label.set_text("Hello world\nI'm a font created with Tiny TTF")
label.center()

View File

@@ -0,0 +1,27 @@
import fs_driver
# needed for dynamic font loading
fs_drv = lv.fs_drv_t()
fs_driver.fs_register(fs_drv, 'S')
# get the directory in which the script is running
try:
script_path = __file__[:__file__.rfind('/')] if __file__.find('/') >= 0 else '.'
except NameError:
script_path = ''
#
# Load a font with Tiny_TTF from file
#
# Create style with the new font
style = lv.style_t()
style.init()
font = lv.tiny_ttf_create_file("S:" + script_path + "/Ubuntu-Medium.ttf", 30)
style.set_text_font(font)
style.set_text_align(lv.TEXT_ALIGN.CENTER)
# Create a label with the new style
label = lv.label(lv.scr_act())
label.add_style(style, 0)
label.set_text("Hello world\nI'm a font created with Tiny TTF")
label.center()

File diff suppressed because it is too large Load Diff