您当前的位置: 首页 > 

仙剑情缘

暂无认证

  • 0浏览

    0关注

    333博文

    0收益

  • 0浏览

    0点赞

    0打赏

    0留言

私信
关注
热门博文

LVGL V8之Size style

仙剑情缘 发布时间:2021-08-15 18:40:59 ,浏览量:0

创建style
  • 定义初时化style
    static lv_style_t style;
    lv_style_init(&style);
  • 设置倒角为45
 lv_style_set_radius(&style, 45);
  • 设置宽度为150
 lv_style_set_width(&style, 150);
  • 设置高度为LV_SIZE_CONTENT
 lv_style_set_height(&style, LV_SIZE_CONTENT);
  • 设置padding top 和padding bottom都为30
lv_style_set_pad_ver(&style, 30);
  • 设置padding left为65
 lv_style_set_pad_left(&style, 65);
  • 设置x坐标为屏幕的50%,lv_pct转换百分比到坐标值
lv_style_set_x(&style, lv_pct(50));
  • 设置y坐标为屏幕顶端向下60
 lv_style_set_y(&style, 60);
创建obj对象
  • 在当前活动界面创建obj对象
lv_obj_t* obj = lv_obj_create(lv_scr_act());
  • 添加size style
 lv_obj_add_style(obj, &style, 0);
  • 在obj对象上创建lable并显示Hello
    lv_obj_t* label = lv_label_create(obj);
    lv_label_set_text(label, "Hello");
完整代码,仅供参考
static void lv_example_style_1(void)
{
    static lv_style_t style;
    lv_style_init(&style);
    lv_style_set_radius(&style, 45);
    /*Make a gradient*/
    lv_style_set_width(&style, 150);
    lv_style_set_height(&style, LV_SIZE_CONTENT);
    lv_style_set_pad_ver(&style, 30);
    lv_style_set_pad_left(&style, 65);
    lv_style_set_x(&style, lv_pct(50));
    lv_style_set_y(&style, 60);
    /*Create an object with the new style*/
    lv_obj_t* obj = lv_obj_create(lv_scr_act());
    lv_obj_add_style(obj, &style, 0);
    lv_obj_t* label = lv_label_create(obj);
    lv_label_set_text(label, "Hello");
}
调用lv_example_style_1运行效果

在这里插入图片描述

  • 分解注释图 在这里插入图片描述
关注
打赏
1658017818
查看更多评论
立即登录/注册

微信扫码登录

0.1035s