-
purpose
Learn and achieve "stick" model similar to the progress bar.
-
Features and functions introduced
-
Features
In littlevGL the bar consists of two parts, a background, a sign in front of the indication. Users can display their progress in the implementation of a task.
To achieve a bar, it needs to be able to create an object, which describes the position displayed in the parent class, its size, background style indicating signs, signs indicating the sliding range, the setting value. And it has a special function, i.e., can be configured to dynamically specified time display to gradually increase.
-
Function Introduction
1, bar creation
lv_obj_t *lv_bar_create(lv_obj_t *par, constlv_obj_t *copy)
功能:为在父类中,创建一个bar变量,同时将copy对象的属性拷贝到新创建bar中返回
par:父类;
copy: 被参考拷贝bar对象;
2, bar and dynamic time value and obtaining
void lv_bar_set_value(lv_obj_t *bar, int16_t value, lv_anim_enable_tanim)//设置
功能:配置bar的初始值value,或者当anim为true时,当前值为一个动态值,结合void lv_bar_set_anim_time(lv_obj_t *bar, uint16_t anim_time)函数使用,此函数设定动态时间,单位ms;
bar:要操作的bar;
value: 被设置的bar值;
anim:如果为true时,当前bar状态随着配置动态时间变化,如果是false,则为value
int16_t lv_bar_get_value(constlv_obj_t *bar)//获取
void lv_bar_set_anim_time(lv_obj_t *bar, uint16_t anim_time)//设置动态时间
uint16_t lv_bar_get_anim_time(lv_obj_t *bar)//获取动态时间
3, the range setting and getting values of bar
int16_t lv_bar_get_min_value(constlv_obj_t *bar)//获取bar可滑动范围的最小值
int16_t lv_bar_get_max_value(constlv_obj_t *bar)//获取最大值
void lv_bar_set_range(lv_obj_t *bar, int16_t min, int16_t max)//配置范围,当没有配置时,默认为0-100
4, bar-style set and get
void lv_bar_set_style(lv_obj_t *bar, lv_bar_style_ttype, const lv_style_t *style)
cost lv_style_t *lv_bar_get_style(constlv_obj_t *bar, lv_bar_style_ttype)
-
Process design and source code
设计一个动态的bar。则需要先创建bar对象,配置显示位置,其大小和动态时间,使能动态功能,同时可以设置其style。
void DrawBar()
{
//1. 创建bar
lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
//2. 设置当前bar外观大小尺寸
lv_obj_set_size(bar1, 200, 30);
//3 .设置其在父类中为中心对齐
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
//4. 设置其为1s变化一次
lv_bar_set_anim_time(bar1, 1000);
//5.设置其初始值为100,并可动态变化
lv_bar_set_value(bar1, 100, LV_ANIM_ON);
}
同前面一样,在main函数调用此函数。
to sum up
There will be a progress bar similar to the bar.