# Show mixed LTR, RTL and Chinese label # ltr_label = lv.label(lv.scr_act()) ltr_label.set_text( "In modern terminology, a microcontroller is similar to a system on a chip (SoC)." ) # ltr_label.set_style_text_font(ltr_label, &lv_font_montserrat_16, 0); fs_drv = lv.fs_drv_t() fs_driver.fs_register(fs_drv, 'S') try: ltr_label.set_style_text_font(ltr_label, lv.font_montserrat_16, 0) except: font_montserrat_16 = lv.font_load("S:../assets/font/montserrat-16.fnt") ltr_label.set_style_text_font(font_montserrat_16, 0) ltr_label.set_width(310) ltr_label.align(lv.ALIGN.TOP_LEFT, 5, 5) rtl_label = lv.label(lv.scr_act()) rtl_label.set_text( "מעבד, או בשמו המלא יחידת עיבוד מרכזית (באנגלית: CPU - Central Processing Unit)." ) rtl_label.set_style_base_dir(lv.BASE_DIR.RTL, 0) rtl_label.set_style_text_font(lv.font_dejavu_16_persian_hebrew, 0) rtl_label.set_width(310) rtl_label.align(lv.ALIGN.LEFT_MID, 5, 0) font_simsun_16_cjk = lv.font_load("S:../assets/font/lv_font_simsun_16_cjk.fnt")
{'short': 'Jun', 'long': 'June', 'num': 6}, {'short': 'Jul', 'long': 'July', 'num': 7}, {'short': 'Aug', 'long': 'August', 'num': 8}, {'short': 'Sep', 'long': 'September', 'num': 9}, {'short': 'Oct', 'long': 'October', 'num': 10}, {'short': 'Nov', 'long': 'November', 'num': 11}, {'short': 'Dec', 'long': 'December', 'num': 12}, ] # 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'] # File system driver for Font loading fs_drv = lv.fs_drv_t() lvgl_fs_driver.fs_register(fs_drv, 'S') myfont_cn = lv.font_t() myfont_cn = lv.font_load("S:/fonts/font_ds_digital_20.bin") class SymbolButton(lv.btn): def __init__(self, parent, symbol, text): super().__init__(parent) self.symbol = lv.label(self) self.symbol.set_text(symbol) self.symbol.set_style(symbolstyle) self.label = lv.label(self) self.label.set_text(text) # Default Styles default_watchface_styles = { "transparent": "yes", "text": {
''' load the font file from filesystem(For me is flash ) How to convert font files refer here: https://github.com/lvgl/lv_font_conv font-PHT-en-20.bin: lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf --range 0x20-0x7f --no-compress -o font-PHT-en-20.bin font-PHT-cn-20.bin: lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf --range 0x4e00-0x4e56 --no-compress -o font-PHT-cn-20.bin font-PHT-jp-20.bin: lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf --range 0x3042-0x3093 --no-compress -o font-PHT-jp-20.bin ''' scr = lv.scr_act() scr.clean() myfont_cn = lv.font_load("S:font/font-PHT-cn-20.bin") style1 = lv.style_t() style1.init() label1 = lv.label(scr) style1.set_text_font(lv.STATE.DEFAULT, myfont_cn) # set font label1.add_style(label1.PART.MAIN, style1) label1.set_text("上中下乎") label1.align(None, lv.ALIGN.CENTER, 0, -25) myfont_en = lv.font_load("S:font/font-PHT-en-20.bin") style2 = lv.style_t() style2.init()
def __init__(self,script_dir,high_res): self.LV_HOR_RES = lv.scr_act().get_disp().driver.hor_res self.LV_VER_RES = lv.scr_act().get_disp().driver.ver_res # # dynamically load fonts # # FS driver init. fs_drv = lv.fs_drv_t() fs_driver.fs_register(fs_drv, 'S') # print( script_dir) # print("S:" + script_dir + "font/montserrat-22.bin") if high_res: self.font_montserrat_small = lv.font_load("S:" + script_dir + "font/montserrat-22.bin") self.font_montserrat_big = lv.font_load("S:" + script_dir + "font/montserrat-28.bin") else: self.font_montserrat_small = lv.font_load("S:" + script_dir + "font/montserrat-10.bin") self.font_montserrat_big = lv.font_load("S:" + script_dir + "font/montserrat-14.bin") self.log = logging.getLogger("Theme") self.log.setLevel(logging.ERROR) self.style_ddbox_pad = lv.style_t() self.style_ddbox_pad.init() self.style_ddbox_pad.set_pad_left(lv.STATE.DEFAULT, 5) self.style_ddbox_pad.set_pad_right(lv.STATE.DEFAULT, 5) self.style_ddbox_pad.set_pad_inner(lv.STATE.DEFAULT, 5) self.style_pad = lv.style_t() self.style_pad.init() self.style_pad.set_pad_top(lv.STATE.DEFAULT, self.LV_VER_RES // 30) self.style_pad.set_pad_bottom(lv.STATE.DEFAULT, self.LV_VER_RES // 30) self.style_pad.set_pad_left(lv.STATE.DEFAULT, self.LV_VER_RES // 40) self.style_pad.set_pad_right(lv.STATE.DEFAULT, self.LV_VER_RES // 40) self.style_circle = lv.style_t() self.style_circle.init() self.style_circle.set_radius(lv.STATE.DEFAULT, LV_RADIUS_CIRCLE) self.style_bg = lv.style_t() self.style_bg.init() self.style_bg.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_bg.set_bg_color(lv.STATE.DEFAULT,LV_DEMO_PRINTER_LIGHT) self.style_bg.set_text_font(lv.STATE.DEFAULT, self.get_font_normal()) self.style_box = lv.style_t() self.style_box.init() self.style_box.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_box.set_radius(lv.STATE.DEFAULT, 2) self.style_box.set_value_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_box.set_value_font(lv.STATE.DEFAULT, self.get_font_normal()) self.style_box_border = lv.style_t() self.style_box_border.init() self.style_box_border.set_border_width(lv.STATE.DEFAULT, 2) self.style_box_border.set_border_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_GRAY) self.style_box_border.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_title = lv.style_t() self.style_title.init() self.style_title.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_title.set_text_font(lv.STATE.DEFAULT, self.get_font_subtitle()) self.style_label = lv.style_t() self.style_label.init() self.style_label.set_text_font(lv.STATE.DEFAULT, self.get_font_normal()) self.style_label_white = lv.style_t() self.style_label_white.init() self.style_label_white.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn = lv.style_t() self.style_btn.init() self.style_btn.set_radius(lv.STATE.DEFAULT, 10) self.style_btn.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_btn.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_btn.set_bg_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_BLUE.color_darken(lv.OPA._20)) self.style_btn.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn.set_value_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn.set_text_font(lv.STATE.DEFAULT, self.get_font_subtitle()) self.style_btn.set_pad_top(lv.STATE.DEFAULT, self.LV_VER_RES // 40) self.style_btn.set_pad_bottom(lv.STATE.DEFAULT, self.LV_VER_RES // 40) self.style_btn.set_transform_width(lv.STATE.PRESSED, self.LV_HOR_RES // 100) self.style_btn.set_transform_height(lv.STATE.PRESSED, self.LV_HOR_RES // 150) self.style_btn.set_transition_time(lv.STATE.DEFAULT, 100) self.style_btn.set_transition_delay(lv.STATE.PRESSED, 0) self.style_btn.set_transition_delay(lv.STATE.DEFAULT, 70) self.style_btn.set_transition_prop_1(lv.STATE.DEFAULT, lv.STYLE.TRANSFORM_WIDTH) self.style_btn.set_transition_prop_2(lv.STATE.DEFAULT, lv.STYLE.TRANSFORM_HEIGHT) self.style_btn_border = lv.style_t() self.style_btn_border.init() self.style_btn_border.set_radius(lv.STATE.DEFAULT, LV_RADIUS_CIRCLE) self.style_btn_border.set_border_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn_border.set_border_width(lv.STATE.DEFAULT, 2) self.style_btn_border.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.TRANSP) self.style_btn_border.set_bg_opa(lv.STATE.PRESSED, lv.OPA._30) self.style_btn_border.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn_border.set_bg_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_WHITE) self.style_btn_border.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn_border.set_value_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_btn_border.set_transition_prop_3(lv.STATE.DEFAULT, lv.STYLE.BG_OPA) self.style_icon = lv.style_t() self.style_icon.init() self.style_icon.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_icon.set_transform_zoom(lv.STATE.PRESSED, 245) self.style_icon.set_transition_time(lv.STATE.DEFAULT, 100) self.style_icon.set_transition_delay(lv.STATE.PRESSED, 0) self.style_icon.set_transition_delay(lv.STATE.DEFAULT, 70) self.style_icon.set_transition_prop_1(lv.STATE.DEFAULT, lv.STYLE.TRANSFORM_ZOOM) self.style_icon.set_value_font(lv.STATE.DEFAULT, self.get_font_subtitle()) self.style_back = lv.style_t() self.style_back.init() self.style_back.set_value_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_back.set_value_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_LIGHT_GRAY) self.style_back.set_border_width(lv.STATE.DEFAULT,0) self.style_back.set_bg_color(lv.STATE.DEFAULT,LV_DEMO_PRINTER_BLUE) self.style_back.set_value_str(lv.STATE.DEFAULT, lv.SYMBOL.LEFT) self.style_back.set_value_font(lv.STATE.DEFAULT, self.get_font_subtitle()) self.style_bar_indic = lv.style_t() self.style_bar_indic.init() self.style_bar_indic.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_bar_indic.set_radius(lv.STATE.DEFAULT, 10) self.style_scrollbar = lv.style_t() self.style_scrollbar.init() self.style_scrollbar.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_scrollbar.set_radius(lv.STATE.DEFAULT, LV_RADIUS_CIRCLE) self.style_scrollbar.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_LIGHT_GRAY) self.style_scrollbar.set_size(lv.STATE.DEFAULT, self.LV_HOR_RES // 80) self.style_scrollbar.set_pad_right(lv.STATE.DEFAULT, self.LV_HOR_RES // 60) self.style_list_btn = lv.style_t() self.style_list_btn.init() self.style_list_btn.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_list_btn.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_list_btn.set_bg_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_LIGHT_GRAY) self.style_list_btn.set_bg_color(lv.STATE.CHECKED, LV_DEMO_PRINTER_GRAY) self.style_list_btn.set_bg_color(lv.STATE.CHECKED | lv.STATE.PRESSED, LV_DEMO_PRINTER_GRAY.color_darken(lv.OPA._20)) self.style_list_btn.set_text_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_list_btn.set_text_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_BLUE.color_darken(lv.OPA._20)) self.style_list_btn.set_text_color(lv.STATE.CHECKED, LV_DEMO_PRINTER_WHITE) self.style_list_btn.set_text_color(lv.STATE.CHECKED | lv.STATE.PRESSED, LV_DEMO_PRINTER_WHITE) self.style_list_btn.set_image_recolor(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_list_btn.set_image_recolor(lv.STATE.PRESSED, LV_DEMO_PRINTER_BLUE.color_darken(lv.OPA._20)) self.style_list_btn.set_image_recolor(lv.STATE.CHECKED, LV_DEMO_PRINTER_WHITE) self.style_list_btn.set_image_recolor(lv.STATE.CHECKED | lv.STATE.PRESSED, LV_DEMO_PRINTER_WHITE) self.style_list_btn.set_pad_left(lv.STATE.DEFAULT, self.LV_HOR_RES // 25) self.style_list_btn.set_pad_right(lv.STATE.DEFAULT, self.LV_HOR_RES // 25) self.style_list_btn.set_pad_top(lv.STATE.DEFAULT, self.LV_HOR_RES // 100) self.style_list_btn.set_pad_bottom(lv.STATE.DEFAULT, self.LV_HOR_RES // 100) self.style_list_btn.set_pad_inner(lv.STATE.DEFAULT, self.LV_HOR_RES // 50) self.style_ddlist_bg = lv.style_t() self.style_ddlist_bg.init() self.style_ddlist_bg.set_radius(lv.STATE.DEFAULT,10) self.style_ddlist_bg.set_bg_color(lv.STATE.DEFAULT,LV_DEMO_PRINTER_BLUE) self.style_ddlist_bg.set_text_color(lv.STATE.DEFAULT,lv_colors.WHITE) self.style_ddlist_bg.set_text_color(lv.STATE.PRESSED,LV_DEMO_PRINTER_WHITE) self.style_ddlist_bg.set_text_font(lv.STATE.DEFAULT,self.font_montserrat_small) self.style_ddlist_list = lv.style_t() self.style_ddlist_list.init() self.style_ddlist_list.set_text_font(lv.STATE.DEFAULT,self.font_montserrat_small) self.style_ddlist_list.set_shadow_width(lv.STATE.DEFAULT, self.LV_VER_RES // 20) self.style_ddlist_list.set_shadow_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_GRAY) self.style_ddlist_selected = lv.style_t() self.style_ddlist_selected.copy(self.style_ddlist_list) self.style_ddlist_selected.set_bg_color(lv.STATE.DEFAULT,LV_DEMO_PRINTER_BLUE) self.style_ddlist_selected.set_bg_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_LIGHT_GRAY) self.style_ddlist_selected.set_text_color(lv.STATE.PRESSED, LV_DEMO_PRINTER_GRAY.color_darken(lv.OPA._20)) self.style_sw_bg = lv.style_t() self.style_sw_bg.init() self.style_sw_bg.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_sw_bg.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_LIGHT_GRAY) self.style_sw_bg.set_radius(lv.STATE.DEFAULT, lv.RADIUS.CIRCLE) self.style_sw_bg.set_value_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_sw_indic = lv.style_t() self.style_sw_indic.init() self.style_sw_indic.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_sw_indic.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_GREEN); self.style_sw_knob = lv.style_t() self.style_sw_knob.init() self.style_sw_knob.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_sw_knob.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_sw_knob.set_radius(lv.STATE.DEFAULT, LV_RADIUS_CIRCLE) self.style_sw_knob.set_pad_top(lv.STATE.DEFAULT, - 4) self.style_sw_knob.set_pad_bottom(lv.STATE.DEFAULT, - 4) self.style_sw_knob.set_pad_left(lv.STATE.DEFAULT, - 4) self.style_sw_knob.set_pad_right(lv.STATE.DEFAULT, - 4) self.style_slider_knob = lv.style_t() self.style_slider_knob.init() self.style_slider_knob.set_bg_opa(lv.STATE.DEFAULT, lv.OPA.COVER) self.style_slider_knob.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_slider_knob.set_border_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_slider_knob.set_border_width(lv.STATE.DEFAULT, 3) self.style_slider_knob.set_radius(lv.STATE.DEFAULT, LV_RADIUS_CIRCLE) if high_res: knob_size = 10 pressed_knob_size = 14 else: knob_size = 5 pressed_knob_size = 8 self.style_slider_knob.set_pad_top(lv.STATE.DEFAULT, knob_size) self.style_slider_knob.set_pad_bottom(lv.STATE.DEFAULT, knob_size) self.style_slider_knob.set_pad_left(lv.STATE.DEFAULT, knob_size) self.style_slider_knob.set_pad_right(lv.STATE.DEFAULT, knob_size) self.style_slider_knob.set_pad_top(lv.STATE.PRESSED, pressed_knob_size) self.style_slider_knob.set_pad_bottom(lv.STATE.PRESSED, pressed_knob_size) self.style_slider_knob.set_pad_left(lv.STATE.PRESSED, pressed_knob_size) self.style_slider_knob.set_pad_right(lv.STATE.PRESSED, pressed_knob_size) self.style_slider_knob.set_transition_time(lv.STATE.DEFAULT, 150) self.style_slider_knob.set_transition_delay(lv.STATE.PRESSED, 0) self.style_slider_knob.set_transition_delay(lv.STATE.DEFAULT, 70) self.style_slider_knob.set_transition_prop_1(lv.STATE.DEFAULT, lv.STYLE.PAD_BOTTOM) self.style_slider_knob.set_transition_prop_2(lv.STATE.DEFAULT, lv.STYLE.PAD_TOP) self.style_slider_knob.set_transition_prop_3(lv.STATE.DEFAULT, lv.STYLE.PAD_LEFT) self.style_slider_knob.set_transition_prop_4(lv.STATE.DEFAULT, lv.STYLE.PAD_RIGHT) self.style_arc_indic = lv.style_t() self.style_arc_indic.init() if high_res: self.style_arc_indic.set_line_width(lv.STATE.DEFAULT, 5) else: self.style_arc_indic.set_line_width(lv.STATE.DEFAULT, 3) self.style_arc_indic.set_line_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_arc_bg = lv.style_t() self.style_arc_bg.init() self.style_arc_bg.set_value_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_WHITE) self.style_arc_bg.set_bg_color(lv.STATE.DEFAULT, LV_DEMO_PRINTER_BLUE) self.style_arc_bg.set_value_font(lv.STATE.DEFAULT, self.get_font_normal()) self.style_arc_bg.set_border_width(lv.STATE.DEFAULT,0)
# # Roller with various alignments and larger text in the selected area # # A style to make the selected option larger style_sel = lv.style_t() style_sel.init() try: style_sel.set_text_font(lv.font_montserrat_22) except: fs_drv = lv.fs_drv_t() fs_driver.fs_register(fs_drv, 'S') print( "montserrat-22 not enabled in lv_conf.h, dynamically loading the font") font_montserrat_22 = lv.font_load("S:" + "../assets/font/montserrat-22.fnt") style_sel.set_text_font(font_montserrat_22) opts = "\n".join(["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]) # A roller on the left with left aligned text, and custom width roller = lv.roller(lv.scr_act()) roller.set_options(opts, lv.roller.MODE.NORMAL) roller.set_visible_row_count(2) roller.set_width(100) roller.add_style(style_sel, lv.PART.SELECTED) roller.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0) roller.align(lv.ALIGN.LEFT_MID, 10, 0) roller.add_event_cb(event_handler, lv.EVENT.ALL, None) roller.set_selected(2, lv.ANIM.OFF)
fs_driver.fs_register(fs_drv, 'S') ''' load the font file from filesystem(For me is flash ) How to convert font files refer here: https://github.com/lvgl/lv_font_conv font-PHT-en-20.bin: lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf --range 0x20-0x7f --no-compress -o font-PHT-en-20.bin font-PHT-cn-20.bin: lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf --range 0x4e00-0x4e56 --no-compress -o font-PHT-cn-20.bin font-PHT-jp-20.bin: lv_font_conv --size 20 --format bin --bpp 1 --font Alibaba-PuHuiTi-Medium.subset.ttf --range 0x3042-0x3093 --no-compress -o font-PHT-jp-20.bin ''' scr = lv.scr_act() scr.clean() myfont_cn = lv.font_load("S:%s/font/font-PHT-cn-20.bin" % script_path) label1 = lv.label(scr) label1.set_style_text_font(myfont_cn, 0) # set the font label1.set_text("上中下乎") label1.align(lv.ALIGN.CENTER, 0, -25) myfont_en = lv.font_load("S:%s/font/font-PHT-en-20.bin" % script_path) label2 = lv.label(scr) label2.set_style_text_font(myfont_en, 0) # set the font label2.set_text("Hello LVGL!") label2.align(lv.ALIGN.CENTER, 0, 25) myfont_jp = lv.font_load("S:%s/font/font-PHT-jp-20.bin" % script_path)