def color_chg_event_cb(sw, e): if e == lv.EVENT.VALUE_CHANGED: flag = lv.THEME_MATERIAL_FLAG.LIGHT if sw.get_state(): flag = lv.THEME_MATERIAL_FLAG.DARK theme = lv.theme_material_init(LV_THEME_DEFAULT_COLOR_PRIMARY, LV_THEME_DEFAULT_COLOR_SECONDARY, flag, lv.theme_get_font_small(), lv.theme_get_font_normal(), lv.theme_get_font_subtitle(), lv.theme_get_font_title())
def init(): """ GUI initialization function. Should be called once in the very beginning. """ # init the gui library lv.init() # init the hardware library SDL.init() # Register SDL display driver disp_buf1 = lv.disp_buf_t() buf1_1 = bytearray(HOR_RES*10) lv.disp_buf_init(disp_buf1,buf1_1, None, len(buf1_1)//4) disp_drv = lv.disp_drv_t() lv.disp_drv_init(disp_drv) disp_drv.buffer = disp_buf1 disp_drv.flush_cb = SDL.monitor_flush disp_drv.hor_res = HOR_RES disp_drv.ver_res = VER_RES lv.disp_drv_register(disp_drv) # Regsiter SDL mouse driver indev_drv = lv.indev_drv_t() lv.indev_drv_init(indev_drv) indev_drv.type = lv.INDEV_TYPE.POINTER; indev_drv.read_cb = SDL.mouse_read; lv.indev_drv_register(indev_drv); # Set up material theme # First argument (210) is a hue - theme color shift, # Second - default font to use. Builtin: roboto_16, roboto_28 th = lv.theme_material_init(210, lv.font_roboto_22) lv.theme_set_current(th) # Create a screen and load it # To access active screen use lv.scr_act() scr = lv.obj() lv.scr_load(scr) # Initialize the styles styles["title"] = lv.style_t() # Title style - just a default style with larger font lv.style_copy(styles["title"], lv.style_plain) styles["title"].text.font = lv.font_roboto_28
def init(): display.init() # Set up material theme # First argument (210) is a hue - theme color shift, # Second - default font to use. Builtin: roboto_16, roboto_28 th = lv.theme_material_init(210, lv.font_roboto_22) lv.theme_set_current(th) # Create a screen and load it # To access active screen use lv.scr_act() scr = lv.obj() lv.scr_load(scr) # Initialize the styles styles["title"] = lv.style_t() # Title style - just a default style with larger font lv.style_copy(styles["title"], lv.style_plain) styles["title"].text.font = lv.font_roboto_28
def set_theme(): # setup theme th = lv.theme_material_init(210, lv.font_roboto_22) lv.theme_set_current(th)
lv.disp_drv_init(disp_drv) disp_drv.buffer = disp_buf1 disp_drv.flush_cb = lcd.flush disp_drv.gpu_blend_cb = lcd.gpu_blend disp_drv.gpu_fill_cb = lcd.gpu_fill disp_drv.hor_res = hres disp_drv.ver_res = vres lv.disp_drv_register(disp_drv) indev_drv = lv.indev_drv_t() lv.indev_drv_init(indev_drv) indev_drv.type = lv.INDEV_TYPE.POINTER indev_drv.read_cb = lcd.ts_read lv.indev_drv_register(indev_drv) th = lv.theme_material_init(10, lv.font_roboto_16) # th = lv.theme_alien_init(160, lv.font_roboto_16) # th = lv.theme_zen_init(120, lv.font_roboto_16) # th = lv.theme_nemo_init(180, lv.font_roboto_16) lv.theme_set_current(th) scr1 = lv.obj() scr2 = lv.obj() lv.scr_load(scr1) slider = lv.slider(scr2) slider.set_width(200) slider.align(scr2, lv.ALIGN.IN_TOP_MID, 0, 15) btn1 = lv.btn(scr1) btn1.align(scr1, lv.ALIGN.IN_TOP_RIGHT, -5, 5)
def init_styles(dark=True): if dark: # Set theme th = lv.theme_night_init(210, lv.font_roboto_22) # adjusting theme # background color cbg = lv.color_hex(0x192432) # ctxt = lv.color_hex(0x7f8fa4) ctxt = lv.color_hex(0xFFFFFF) cbtnrel = lv.color_hex(0x506072) cbtnpr = lv.color_hex(0x405062) chl = lv.color_hex(0x313E50) else: # Set theme to light # TODO: work in progress... th = lv.theme_material_init(210, lv.font_roboto_22) # adjusting theme # background color cbg = lv.color_hex(0xEEEEEE) # ctxt = lv.color_hex(0x7f8fa4) ctxt = lv.color_hex(0) cbtnrel = lv.color_hex(0x506072) cbtnpr = lv.color_hex(0x405062) chl = lv.color_hex(0x313E50) th.style.label.sec.text.color = cbtnrel th.style.scr.body.main_color = cbg th.style.scr.body.grad_color = cbg # text color th.style.scr.text.color = ctxt # buttons # btn released th.style.btn.rel.body.main_color = cbtnrel th.style.btn.rel.body.grad_color = cbtnrel th.style.btn.rel.body.shadow.width = 0 th.style.btn.rel.body.border.width = 0 th.style.btn.rel.body.radius = 10 # btn pressed lv.style_copy(th.style.btn.pr, th.style.btn.rel) th.style.btn.pr.body.main_color = cbtnpr th.style.btn.pr.body.grad_color = cbtnpr # button map released th.style.btnm.btn.rel.body.main_color = cbg th.style.btnm.btn.rel.body.grad_color = cbg th.style.btnm.btn.rel.body.radius = 0 th.style.btnm.btn.rel.body.border.width = 0 th.style.btnm.btn.rel.body.shadow.width = 0 th.style.btnm.btn.rel.text.color = ctxt # button map pressed lv.style_copy(th.style.btnm.btn.pr, th.style.btnm.btn.rel) th.style.btnm.btn.pr.body.main_color = chl th.style.btnm.btn.pr.body.grad_color = chl # button map toggled lv.style_copy(th.style.btnm.btn.tgl_pr, th.style.btnm.btn.pr) lv.style_copy(th.style.btnm.btn.tgl_rel, th.style.btnm.btn.pr) # button map inactive lv.style_copy(th.style.btnm.btn.ina, th.style.btnm.btn.rel) th.style.btnm.btn.ina.text.opa = 80 # button map background th.style.btnm.bg.body.opa = 0 th.style.btnm.bg.body.border.width = 0 th.style.btnm.bg.body.shadow.width = 0 # textarea th.style.ta.oneline.body.opa = 0 th.style.ta.oneline.body.border.width = 0 th.style.ta.oneline.text.font = lv.font_roboto_28 th.style.ta.oneline.text.color = ctxt # slider th.style.slider.knob.body.main_color = cbtnrel th.style.slider.knob.body.grad_color = cbtnrel th.style.slider.knob.body.radius = 5 th.style.slider.knob.body.border.width = 0 # page th.style.page.bg.body.opa = 0 th.style.page.scrl.body.opa = 0 th.style.page.bg.body.border.width = 0 th.style.page.bg.body.padding.left = 0 th.style.page.bg.body.padding.right = 0 th.style.page.bg.body.padding.top = 0 th.style.page.bg.body.padding.bottom = 0 th.style.page.scrl.body.border.width = 0 th.style.page.scrl.body.padding.left = 0 th.style.page.scrl.body.padding.right = 0 th.style.page.scrl.body.padding.top = 0 th.style.page.scrl.body.padding.bottom = 0 lv.theme_set_current(th) styles["theme"] = th # Title style - just a default style with larger font styles["title"] = lv.style_t() lv.style_copy(styles["title"], th.style.label.prim) styles["title"].text.font = lv.font_roboto_28 styles["title"].text.color = ctxt styles["hint"] = lv.style_t() lv.style_copy(styles["hint"], th.style.label.sec) styles["hint"].text.font = lv.font_roboto_16 styles["small"] = lv.style_t() lv.style_copy(styles["small"], styles["hint"]) styles["small"].text.color = ctxt
def init_ui(self): display.init() theme = lv.theme_material_init(210, lv.font_roboto_mono_28) lv.theme_set_current(theme)
import lvgl as lv import lib.screen.widgets as w import lib.screen.icons as i import lib.game.game as g import time as t import gc NIGHT_THEME = lv.theme_night_init(210, lv.font_roboto_16) DEFAULT_THEME = lv.theme_default_init(210, lv.font_roboto_16) MATERIAL_THEME = lv.theme_material_init(210, lv.font_roboto_16) DISP_SCALE = 4 SCR_Y = 32 SCR_X = 40 class App(): def __init__(self, name, display, buttons, timer, **kwargs): gc.collect() self.disp = display self.buttons = buttons self.tim = timer # self.theme = th self.group = lv.group_create() # lv.theme_set_current(self.theme) self.scr = lv.obj() self.name = name self.items = {} self.item_ids = {} self.cont = w.Container(self.scr) self.set_buttons(