3、lvgl字体

LVGL字体

LVGL字体概述

V6版本最高支持4bpp的抗锯齿,支持UTF-8和ASCLL编码.通过配置LV_TXT_ENC修改编码.具体区别如下

  • ASCLL:只支持英文显示
  • UTF-8:支持全球所有字符

需要注意的是,当使用UTF-8编码时,将你使用的IDE的编码也修改为UTF-8.

如何使用字体

LVGL内置了7种字体,相关宏如下所示.

/* https://fonts.google.com/specimen/Roboto  */
#define LV_FONT_ROBOTO_12    1
#define LV_FONT_ROBOTO_16    1
#define LV_FONT_ROBOTO_22    0
#define LV_FONT_ROBOTO_28    0

/* Demonstrate special features */
#define LV_FONT_ROBOTO_12_SUBPX 1
#define LV_FONT_ROBOTO_28_COMPRESSED 1  /*bpp = 3*/

/*Pixel perfect monospace font
 * http://pelulamu.net/unscii/ */
#define LV_FONT_UNSCII_8     0

如果想使用哪个字体,则打开对应的宏定义即可.

具体使用示例如下.

static lv_style_t laebl_style;
lv_style_copy(&laebl_style,&lv_style_plain_color);
laebl_style.text.font = &LV_FONT_ROBOTO_12;
lv_label_set_style(label1, LV_LABEL_STYLE_MAIN,&laebl_style);

备注: 如果在使用的时候没有指定显示文本的字体时,按照LV_FONT_DEFAULT宏的配置去显示.

创建自己的字体

使用如下两款软件

生成c文件后,将该文件导入到工程中.下面是一段简单的测试代码.

    lv_obj_t *consolas_label = lv_label_create(app_window, NULL);
    if(consolas_label == NULL)
    {
        printf("init failed\r\n");
        while(1);
    }
    static lv_style_t consolas_style;
    lv_style_copy(&consolas_style,&lv_style_plain);
    consolas_style.text.font = &consolas;
    lv_label_set_style(consolas_label,LV_LABEL_STYLE_MAIN,&consolas_style);
    lv_label_set_text(consolas_label,"abc");
    lv_label_set_body_draw(consolas_label,true);
    lv_obj_align(consolas_label,NULL,LV_ALIGN_IN_BOTTOM_LEFT,0,0);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值