首页 > 其他分享 >lvgl:样式 styles

lvgl:样式 styles

时间:2024-09-29 21:26:23浏览次数:8  
标签:styles lv style obj 样式 STYLE value LV lvgl

1 styles 样式

  styles 样式是用来决定对象obj外观的一大类属性,大概是最重要最常见的一个属性,内容较多;

  obj可以拥有多个style属性,最新添加的属性优先级最高,子对象部分没有设置的属性(eg:text color)可以从父对象继承;

  obj 总是由一种或多种states和parts组成,不同的states和parts可以设置成不同的styles;

  1.1 states 状态

    obj总是由一种或多种states组成;可以通过states来设置回调函数,也可以通过states来设置obj不同states下的styles属性;

    状态通常在用户操作时自动更改,但是也可以代码更改;

    states的优先级和单片机优先级相反,对于states属性而言,数值越大那么优先级属性越高;obj优先显示最高优先级属性;

/**    lv_obj.h
 * Possible states of a widget.
 * OR-ed values are possible
 */
enum {
    LV_STATE_DEFAULT     =  0x0000,	//Normal, released state
    LV_STATE_CHECKED     =  0x0001,	//Toggled or checked state
    LV_STATE_FOCUSED     =  0x0002,	//Focused via keypad or encoder or clicked via touchpad/mouse
    LV_STATE_FOCUS_KEY   =  0x0004,	//Focused via keypad or encoder but not via touchpad/mouse
    LV_STATE_EDITED      =  0x0008,	//Edit by an encoder
    LV_STATE_HOVERED     =  0x0010,	//Hovered by mouse (not supported now)
    LV_STATE_PRESSED     =  0x0020,	//Being pressed
    LV_STATE_SCROLLED    =  0x0040,	//Being scrolled
    LV_STATE_DISABLED    =  0x0080,	//Disabled state

    LV_STATE_USER_1      =  0x1000,
    LV_STATE_USER_2      =  0x2000,
    LV_STATE_USER_3      =  0x4000,
    LV_STATE_USER_4      =  0x8000,

    LV_STATE_ANY = 0xFFFF,    /**< Special value can be used in some functions to target all states*/
};

typedef uint16_t lv_state_t;
/**    //lv_obj.h
 * Add one or more states to the object. The other state bits will remain unchanged.
 * If specified in the styles, transition animation will be started from the previous state to the current.
 * @param obj       pointer to an object
 * @param state     the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED`
 */
void lv_obj_add_state(lv_obj_t *obj, lv_state_t state);

/**
 * Remove one or more states to the object. The other state bits will remain unchanged.
 * If specified in the styles, transition animation will be started from the previous state to the current.
 * @param obj       pointer to an object
 * @param state     the states to add. E.g `LV_STATE_PRESSED | LV_STATE_FOCUSED`
 */
void lv_obj_clear_state(lv_obj_t *obj, lv_state_t state);

  1.2 parts 部分

    obj总是由一种或多种parts构成的;可以通过parts来设置obj不同parts下的styles属性;

    比如basic obj使用main part和scrollbar part,silider使用main part、indicator part、knob part组成;

/**    //lv_obj.h
 * The possible parts of widgets.
 * The parts can be considered as the internal building block of the widgets.
 * E.g. slider = background + indicator + knob
 * Not all parts are used by every widget
 */
enum {
    LV_PART_MAIN         = 0x000000,   /**< A background like rectangle*/
    LV_PART_SCROLLBAR    = 0x010000,   /**< The scrollbar(s)*/
    LV_PART_INDICATOR    = 0x020000,   /**< Indicator, e.g. for slider, bar, switch, or the tick box of the checkbox*/
    LV_PART_KNOB         = 0x030000,   /**< Like handle to grab to adjust the value*/
    LV_PART_SELECTED     = 0x040000,   /**< Indicate the currently selected option or section*/
    LV_PART_ITEMS        = 0x050000,   /**< Used if the widget has multiple similar elements (e.g. table cells)*/
    LV_PART_TICKS        = 0x060000,   /**< Ticks on scale e.g. for a chart or meter*/
    LV_PART_CURSOR       = 0x070000,   /**< Mark a specific place e.g. for text area's cursor or on a chart*/

    LV_PART_CUSTOM_FIRST = 0x080000,    /**< Extension point for custom widgets*/

    LV_PART_ANY          = 0x0F0000,    /**< Special value can be used in some functions to target all parts*/
};

typedef uint32_t lv_part_t;

2 lv_style_t 结构体

  styles数据的作用域应该和所属obj的作用域一样长,所以styles变量需要定义成全局属性或动态分配内存;

  2.1 lv_style_t 结构体

/**    lv_style.h    styles结构体
 * Descriptor of a style (a collection of properties and values).
 */
typedef struct {
#if LV_USE_ASSERT_STYLE
    uint32_t sentinel;
#endif
    /*If there is only one property store it directly.
     *For more properties allocate an array*/
    union {
        lv_style_value_t value1;                       //lv_style_value_t 结构体
        uint8_t * values_and_props;
        const lv_style_const_prop_t * const_props;     //lv_style_const_prop_t 结构体
    } v_p;
    uint16_t prop1;
    uint8_t has_group;
    uint8_t prop_cnt;
} lv_style_t;

  2.2 lv_style_value_t 结构体

/**    lv_style.h   
 * A common type to handle all the property types in the same way.
 */
typedef union {
    int32_t num;         /**< Number integer number (opacity, enums, booleans or "normal" numbers)*/
    const void * ptr;    /**< Constant pointers  (font, cone text, etc)*/
    lv_color_t color;    /**< Colors  这个后续举个例子放下面,先放着;*/
} lv_style_value_t;

  2.3 lv_style_const_prop_t 结构体

/**    lv_style.h
 * Descriptor of a constant style property.
 */
typedef struct {
    lv_style_prop_t prop;
    lv_style_value_t value;    //lv_style_t中定义了一个lv_style_value_t,这里又定义了一个lv_style_value_t;
} lv_style_const_prop_t;


/**  lv_style.h  styles 属性
 * Enumeration of all built in style properties
 * Props are split into groups of 16. When adding a new prop to a group, ensure it does not overflow into the next one.
 */
typedef enum {
    LV_STYLE_PROP_INV               = 0,

    /*Group 0*/
    LV_STYLE_WIDTH                  = 1,
    LV_STYLE_MIN_WIDTH              = 2,
    LV_STYLE_MAX_WIDTH              = 3,
    LV_STYLE_HEIGHT                 = 4,
    LV_STYLE_MIN_HEIGHT             = 5,
    LV_STYLE_MAX_HEIGHT             = 6,
    LV_STYLE_X                      = 7,
    LV_STYLE_Y                      = 8,
    LV_STYLE_ALIGN                  = 9,
    LV_STYLE_LAYOUT                 = 10,
    LV_STYLE_RADIUS                 = 11,

    /*Group 1*/
    LV_STYLE_PAD_TOP                = 16,
    LV_STYLE_PAD_BOTTOM             = 17,
    LV_STYLE_PAD_LEFT               = 18,
    LV_STYLE_PAD_RIGHT              = 19,
    LV_STYLE_PAD_ROW                = 20,
    LV_STYLE_PAD_COLUMN             = 21,
    LV_STYLE_BASE_DIR               = 22,
    LV_STYLE_CLIP_CORNER            = 23,

    /*Group 2*/
    LV_STYLE_BG_COLOR               = 32,
    LV_STYLE_BG_OPA                 = 33,
    LV_STYLE_BG_GRAD_COLOR          = 34,
    LV_STYLE_BG_GRAD_DIR            = 35,
    LV_STYLE_BG_MAIN_STOP           = 36,
    LV_STYLE_BG_GRAD_STOP           = 37,
    LV_STYLE_BG_GRAD                = 38,
    LV_STYLE_BG_DITHER_MODE         = 39,
    LV_STYLE_BG_IMG_SRC             = 40,
    LV_STYLE_BG_IMG_OPA             = 41,
    LV_STYLE_BG_IMG_RECOLOR         = 42,
    LV_STYLE_BG_IMG_RECOLOR_OPA     = 43,
    LV_STYLE_BG_IMG_TILED           = 44,

    /*Group 3*/
    LV_STYLE_BORDER_COLOR           = 48,
    LV_STYLE_BORDER_OPA             = 49,
    LV_STYLE_BORDER_WIDTH           = 50,
    LV_STYLE_BORDER_SIDE            = 51,
    LV_STYLE_BORDER_POST            = 52,
    LV_STYLE_OUTLINE_WIDTH          = 53,
    LV_STYLE_OUTLINE_COLOR          = 54,
    LV_STYLE_OUTLINE_OPA            = 55,
    LV_STYLE_OUTLINE_PAD            = 56,

    /*Group 4*/
    LV_STYLE_SHADOW_WIDTH           = 64,
    LV_STYLE_SHADOW_OFS_X           = 65,
    LV_STYLE_SHADOW_OFS_Y           = 66,
    LV_STYLE_SHADOW_SPREAD          = 67,
    LV_STYLE_SHADOW_COLOR           = 68,
    LV_STYLE_SHADOW_OPA             = 69,
    LV_STYLE_IMG_OPA                = 70,
    LV_STYLE_IMG_RECOLOR            = 71,
    LV_STYLE_IMG_RECOLOR_OPA        = 72,
    LV_STYLE_LINE_WIDTH             = 73,
    LV_STYLE_LINE_DASH_WIDTH        = 74,
    LV_STYLE_LINE_DASH_GAP          = 75,
    LV_STYLE_LINE_ROUNDED           = 76,
    LV_STYLE_LINE_COLOR             = 77,
    LV_STYLE_LINE_OPA               = 78,

    /*Group 5*/
    LV_STYLE_ARC_WIDTH              = 80,
    LV_STYLE_ARC_ROUNDED            = 81,
    LV_STYLE_ARC_COLOR              = 82,
    LV_STYLE_ARC_OPA                = 83,
    LV_STYLE_ARC_IMG_SRC            = 84,
    LV_STYLE_TEXT_COLOR             = 85,
    LV_STYLE_TEXT_OPA               = 86,
    LV_STYLE_TEXT_FONT              = 87,
    LV_STYLE_TEXT_LETTER_SPACE      = 88,
    LV_STYLE_TEXT_LINE_SPACE        = 89,
    LV_STYLE_TEXT_DECOR             = 90,
    LV_STYLE_TEXT_ALIGN             = 91,

    /*Group 6*/
    LV_STYLE_OPA                    = 96,
    LV_STYLE_COLOR_FILTER_DSC       = 97,
    LV_STYLE_COLOR_FILTER_OPA       = 98,
    LV_STYLE_ANIM                   = 99,
    LV_STYLE_ANIM_TIME              = 100,
    LV_STYLE_ANIM_SPEED             = 101,
    LV_STYLE_TRANSITION             = 102,
    LV_STYLE_BLEND_MODE             = 103,
    LV_STYLE_TRANSFORM_WIDTH        = 104,
    LV_STYLE_TRANSFORM_HEIGHT       = 105,
    LV_STYLE_TRANSLATE_X            = 106,
    LV_STYLE_TRANSLATE_Y            = 107,
    LV_STYLE_TRANSFORM_ZOOM         = 108,
    LV_STYLE_TRANSFORM_ANGLE        = 109,
    LV_STYLE_TRANSFORM_PIVOT_X      = 110,
    LV_STYLE_TRANSFORM_PIVOT_Y      = 111,

    _LV_STYLE_LAST_BUILT_IN_PROP     = 111,
    _LV_STYLE_NUM_BUILT_IN_PROPS     = _LV_STYLE_LAST_BUILT_IN_PROP + 1,

    LV_STYLE_PROP_ANY                = 0xFFFF,
    _LV_STYLE_PROP_CONST             = 0xFFFF /* magic value for const styles */
} lv_style_prop_t;

3 lv_style_t 使用

  3.1 styles 初始化

/**       lv_styles.h  styles在使用之前应该先初始化;
 * Initialize a style
 * @param style pointer to a style to initialize
 * @note Do not call `lv_style_init` on styles that already have some properties
 *       because this function won't free the used memory, just sets a default state for the style.
 *       In other words be sure to initialize styles only once!
 */
void lv_style_init(lv_style_t * style);

  3.2 styles 属性设置

//lv_style.h     10来个函数:styles 的pad,size设置,prop属性的设置函数
static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value);
void lv_style_init(lv_style_t * style);
void lv_style_reset(lv_style_t * style);
bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop);
void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value);

//lv_style_gen.h   80多个函数:styles 的各种属性设置  格式lv_style_set_<property_name>(&style, <value>);
void lv_style_set_width(lv_style_t * style, lv_coord_t value);
void lv_style_set_pad_top(lv_style_t * style, lv_coord_t value);
void lv_style_set_bg_color(lv_style_t * style, lv_color_t value);
void lv_style_set_bg_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_text_opa(lv_style_t * style, lv_opa_t value);
void lv_style_set_text_font(lv_style_t * style, const lv_font_t * value);
void lv_style_set_anim(lv_style_t * style, const lv_anim_t * value);
void lv_style_set_anim_time(lv_style_t * style, uint32_t value);

  3.3 styles 属性赋值

/**   lv_obj_style.h
 * Add a style to an object.
 * @param obj       pointer to an object
 * @param style     pointer to a style to add
 * @param selector  OR-ed value of parts and state to which the style should be added 
 *                  用来选择将styles加到哪part的哪state上;所以这个selector里是有两个参数或在一块的;
 * @example         lv_obj_add_style(btn, &style_btn, 0); //Default button style
 * @example         lv_obj_add_style(btn, &btn_red, LV_STATE_PRESSED); //Overwrite only some colors to red when pressed
 */
void lv_obj_add_style(struct _lv_obj_t * obj, lv_style_t * style, lv_style_selector_t selector);

  

  

 

标签:styles,lv,style,obj,样式,STYLE,value,LV,lvgl
From: https://www.cnblogs.com/caesura-k/p/17664642.html

相关文章

  • 【前端样式】Sweetalert2简单用法
    1、先安装sweetalert2库:        npminstallsweetalert22、引用SweetAlert2库:        importSwalfrom'sweetalert2';3、代码拷过去直接去测试,vue代码<template><div><el-buttonstyle="color:#C03639"@click="test">......
  • 常间的css样式问题处理
    flex导致文字省略失效单独使用文字省略,按预期工作:给元素加上flex,文字省略失效:解决方案:flex和文字省略不要放到一个元素上。flex布局中,文字溢出省略不生效的问题问题展示.container{display:flex;width:400px;border:1pxsolid#000;}.content{flex:1;......
  • PbootCMS默认面包屑导航样式修改及自定义的设置方法
    在使用PBootCMS建站时,如果需要对系统默认的面包屑标签进行样式修改,可以通过调整相应的参数来实现。以下是具体的步骤和示例代码:修改面包屑标签的样式自定义分隔符修改首页文本添加首页图标添加分割图标示例代码假设你需要修改面包屑标签的分隔符、首页文本以及图标,可以按......
  • CSS常用样式及示例
    CSS常用样式及示例 一、简介   层叠样式表(英文全称:CascadingStyleSheets)是一种用来表现HTML(标准通用标记语言的一个应用)或XML(标准通用标记语言的一个子集)等文件样式的计算机语言。CSS目前最新版本为CSS3,是能够真正做到网页表现与内容分离的一种样式......
  • 自定义表格样式
     HTML:<divclass="table-container"><tablestyle="width:90%;margin-left:5%"><trclass="table-title"><thstyle="width:33%&qu......
  • 如何在低成本ARM平台部署LVGL免费图形库,基于全志T113-i
    LVGL简介LVGL(LittlevGraphicsLibrary)是一个开源的图形库,主要用于嵌入式系统创建图形用户界面(GUI),采用C语言编写,具有高效性和可定制性,在各种微控制器平台和显示硬件上开发用户界面时备受欢迎。LVGL具社区免费开源、控件资源丰富、跨平台可移植等特点。社区免费开源:完全免费,......
  • Vue修改全局样式 v-style指令详解
    Vue修改全局样式v-style指令详解基本概念与作用基础用法示例一:动态修改单个元素的样式示例二:使用计算属性动态设置样式示例三:全局样式动态化示例四:使用Vue生命周期钩子设置样式示例五:通过Vuex管理全局样式实际开发中的使用技巧在Vue.js的开发过程中,有时我们......
  • 万象更新 Html5 - dom: DOM 获取元素,修改元素的样式
    源码https://github.com/webabcd/Html5作者webabcd万象更新Html5-dom:DOM获取元素,修改元素的样式示例如下:dom\demo1.html<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><title>DOM获取元素,修改元素的样式</t......
  • 第四章 CSS样式基础
    4.1CSS概述CSS(CascadingStyleSheets,层叠样式表)是一种用于描述网页内容显示方式的样式语言。它与HTML一起使用,通过分离内容与样式,提供更高效的网页设计和维护。CSS的主要作用是控制网页的布局、颜色、字体、间距等视觉表现。 1.CSS的基本概念1.选择器(Selector):用于指定H......
  • 网站后台样式错乱,文章详情页打不开
    根据您提供的信息,网站后台样式错乱、文章详情页打不开,以及前台页面无法访问的问题,可能是由于服务器防火墙拦截了某些URL导致的。具体原因如下:可能的原因中毒导致:确认网站是否被植入恶意代码或病毒。升级到最新版本,并进行查毒处理。服务器防火墙拦截:宝塔面板或其他防......