microPython环境下的lvgl开发心得

microPython环境下的lvgl是c代码通过pycparser转换成python代码的。因此没有python环境下的源文件。发开需依靠REPL(交互式控制台)调出文档配合c源码进行。
以变换内置主题为例,记录下开发思路。
打开REPL,输入

import lvgl as lv
help(lv)

在这里插入图片描述
得到类lv下所有的方法和类,查找theme相关,有如下方法:

  theme_set_current -- <function>
  theme_get_current -- <function>
  theme_templ_init -- <function>
  theme_get_templ -- <function>
  theme_default_init -- <function>
  theme_get_default -- <function>
  theme_alien_init -- <function>
  theme_get_alien -- <function>
  theme_night_init -- <function>
  theme_get_night -- <function>
  theme_zen_init -- <function>
  theme_get_zen -- <function>
  theme_mono_init -- <function>
  theme_get_mono -- <function>
  theme_nemo_init -- <function>
  theme_get_nemo -- <function>
  theme_material_init -- <function>
  theme_get_material -- <function>

打开c源码在lv_theme.h中有相关源码的注释

/**
 * Set a theme for the system.
 * From now, all the created objects will use styles from this theme by default
 * @param th pointer to theme (return value of: 'lv_theme_init_xxx()')
 */
void lv_theme_set_current(lv_theme_t * th);

经解释器转换后为lv.theme_set_current,用于设置整个系统的默认主题。

以及lv_theme_night,h中的

/**
 * Initialize the night theme
 * @param hue [0..360] hue value from HSV color space to define the theme's base color
 * @param font pointer to a font (NULL to use the default)
 * @return pointer to the initialized theme
 */
lv_theme_t * lv_theme_night_init(uint16_t hue, lv_font_t * font);

经解释器转换后为lv.theme_night_init,为内置的night主题。两个输入参数,hue为色调,范围(0-360),font为字体,在刚刚REPL的输出中查找lv_font_t型,得到

  font_roboto_16 -- struct lv_font_t
  font_roboto_28 -- struct lv_font_t

所以设置默认主题的py代码如下

lv.theme_set_current(lv.theme_night_init(360,lv.font_roboto_16))

更改指定控件主题

以常用的按钮为例,在c源码lv_btn.h

/**
 * Set a style of a button.
 * @param btn pointer to button object
 * @param type which style should be set
 * @param style pointer to a style
 *  */
void lv_btn_set_style(lv_obj_t * btn, lv_btn_style_t type, const lv_style_t * style);

对应py代码lv.btn.set_style

scr = lv.obj()
btn = lv.btn(scr)
theme1=lv.theme_alien_init(100,lv.font_roboto_16)
btn.set_style(btn.STYLE.REL,theme1.style.btn.rel)
btn.set_style(btn.STYLE.PR,theme1.style.btn.pr)
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值