update asserts
This commit is contained in:
12
examples/widgets/bar/lv_example_bar_1.c
Normal file
12
examples/widgets/bar/lv_example_bar_1.c
Normal file
@@ -0,0 +1,12 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
void lv_example_bar_1(void)
|
||||
{
|
||||
lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(bar1, 200, 20);
|
||||
lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_value(bar1, 70, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
#endif
|
||||
5
examples/widgets/bar/lv_example_bar_1.py
Normal file
5
examples/widgets/bar/lv_example_bar_1.py
Normal file
@@ -0,0 +1,5 @@
|
||||
bar1 = lv.bar(lv.scr_act())
|
||||
bar1.set_size(200, 30)
|
||||
bar1.align(None, lv.ALIGN.CENTER, 0, 0)
|
||||
bar1.set_anim_time(1000)
|
||||
bar1.set_value(100, lv.ANIM.ON)
|
||||
37
examples/widgets/bar/lv_example_bar_3.c
Normal file
37
examples/widgets/bar/lv_example_bar_3.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
static void set_temp(lv_obj_t * bar, int32_t temp)
|
||||
{
|
||||
lv_bar_set_value(bar, temp, LV_ANIM_ON);
|
||||
|
||||
static char buf[10]; /*Only the pointer t saved so must be static*/
|
||||
lv_snprintf(buf, sizeof(buf), "%d°C", temp);
|
||||
lv_obj_set_style_content_text(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf);
|
||||
}
|
||||
|
||||
/**
|
||||
* A temperature meter example
|
||||
*/
|
||||
void lv_example_bar_3(void)
|
||||
{
|
||||
static lv_style_t style_indic;
|
||||
|
||||
lv_style_init(&style_indic);
|
||||
lv_style_set_bg_opa(&style_indic, LV_OPA_COVER);
|
||||
lv_style_set_bg_color(&style_indic, LV_COLOR_RED);
|
||||
lv_style_set_bg_grad_color(&style_indic, LV_COLOR_BLUE);
|
||||
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER);
|
||||
lv_style_set_content_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP);
|
||||
lv_style_set_content_ofs_x(&style_indic, -3);
|
||||
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
|
||||
lv_obj_set_size(bar, 20, 200);
|
||||
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_range(bar, -20, 40);
|
||||
set_temp(bar, 30);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
27
examples/widgets/bar/lv_example_bar_4.c
Normal file
27
examples/widgets/bar/lv_example_bar_4.c
Normal file
@@ -0,0 +1,27 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
/**
|
||||
* Bar with stripe pattern and ranged value
|
||||
*/
|
||||
void lv_example_bar_4(void)
|
||||
{
|
||||
LV_IMG_DECLARE(img_skew_strip);
|
||||
static lv_style_t style_indic;
|
||||
|
||||
lv_style_init(&style_indic);
|
||||
lv_style_set_bg_img_src(&style_indic, &img_skew_strip);
|
||||
lv_style_set_bg_img_tiled(&style_indic, true);
|
||||
lv_style_set_bg_img_opa(&style_indic, LV_OPA_30);
|
||||
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
|
||||
|
||||
lv_obj_set_size(bar, 260, 20);
|
||||
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
lv_bar_set_type(bar, LV_BAR_TYPE_RANGE);
|
||||
lv_bar_set_value(bar, 90, LV_ANIM_OFF);
|
||||
lv_bar_set_start_value(bar, 20, LV_ANIM_OFF);
|
||||
}
|
||||
|
||||
#endif
|
||||
30
examples/widgets/bar/lv_example_bar_5.c
Normal file
30
examples/widgets/bar/lv_example_bar_5.c
Normal file
@@ -0,0 +1,30 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
/**
|
||||
* Bar with LTR and RTL base direction
|
||||
*/
|
||||
void lv_example_bar_5(void)
|
||||
{
|
||||
static lv_style_t style_bg;
|
||||
lv_style_init(&style_bg);
|
||||
lv_style_set_content_ofs_y(&style_bg, -3);
|
||||
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
|
||||
|
||||
lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_size(bar_ltr, 200, 20);
|
||||
lv_bar_set_value(bar_ltr, 70, LV_ANIM_OFF);
|
||||
lv_obj_align(bar_ltr, NULL, LV_ALIGN_CENTER, 0, -30);
|
||||
lv_obj_add_style(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
|
||||
lv_obj_set_style_content_text(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, "Left to Right base direction");
|
||||
|
||||
lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_set_base_dir(bar_rtl, LV_BIDI_DIR_RTL);
|
||||
lv_obj_set_size(bar_rtl, 200, 20);
|
||||
lv_bar_set_value(bar_rtl, 70, LV_ANIM_OFF);
|
||||
lv_obj_align(bar_rtl, NULL, LV_ALIGN_CENTER, 0, 30);
|
||||
lv_obj_add_style(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg);
|
||||
lv_obj_set_style_content_text(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, "Right to Left base direction");
|
||||
}
|
||||
|
||||
#endif
|
||||
68
examples/widgets/bar/lv_example_bar_6.c
Normal file
68
examples/widgets/bar/lv_example_bar_6.c
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "../../../lvgl.h"
|
||||
#if LV_USE_BAR
|
||||
|
||||
static void event_cb(lv_obj_t * obj, lv_event_t e)
|
||||
{
|
||||
if(e == LV_EVENT_DRAW_POST_END) {
|
||||
lv_bar_t * bar = (lv_bar_t *)obj;
|
||||
|
||||
lv_draw_label_dsc_t dsc;
|
||||
lv_draw_label_dsc_init(&dsc);
|
||||
dsc.font = LV_THEME_FONT_NORMAL;
|
||||
|
||||
char buf[8];
|
||||
lv_snprintf(buf, sizeof(buf), "%d", lv_bar_get_value(obj));
|
||||
|
||||
lv_point_t txt_size;
|
||||
lv_txt_get_size(&txt_size, buf, dsc.font, dsc.letter_space, dsc.line_space, LV_COORD_MAX, dsc.flag);
|
||||
|
||||
lv_area_t txt_area;
|
||||
/*If the indicator is long enough put the text inside on the right*/
|
||||
if(lv_area_get_width(&bar->indic_area) > txt_size.x + 20) {
|
||||
txt_area.x2 = bar->indic_area.x2 - 5;
|
||||
txt_area.x1 = txt_area.x2 - txt_size.x + 1;
|
||||
dsc.color = LV_COLOR_WHITE;
|
||||
}
|
||||
/*If the indicator is still short put the text out of it on the right */
|
||||
else {
|
||||
txt_area.x1 = bar->indic_area.x2 + 5;
|
||||
txt_area.x2 = txt_area.x1 + txt_size.x - 1;
|
||||
dsc.color = LV_COLOR_BLACK;
|
||||
}
|
||||
|
||||
txt_area.y1 = bar->indic_area.y1 + (lv_area_get_height(&bar->indic_area) - txt_size.y) / 2;
|
||||
txt_area.y2 = txt_area.y1 + txt_size.y - 1;
|
||||
|
||||
const lv_area_t * clip_area = lv_event_get_param();
|
||||
lv_draw_label(&txt_area, clip_area, &dsc, buf, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Custom drawer on bar to display the current value
|
||||
*/
|
||||
void lv_example_bar_6(void)
|
||||
{
|
||||
static lv_style_t style_bg;
|
||||
lv_style_init(&style_bg);
|
||||
lv_style_set_content_ofs_y(&style_bg, -3);
|
||||
lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID);
|
||||
|
||||
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL);
|
||||
lv_obj_add_event_cb(bar, event_cb, NULL);
|
||||
lv_obj_set_size(bar, 200, 20);
|
||||
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
|
||||
|
||||
lv_anim_t a;
|
||||
lv_anim_init(&a);
|
||||
lv_anim_set_var(&a, bar);
|
||||
lv_anim_set_values(&a, 0, 100);
|
||||
lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) lv_bar_set_value);
|
||||
lv_anim_set_time(&a, 2000);
|
||||
lv_anim_set_playback_time(&a, 2000);
|
||||
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
|
||||
lv_anim_start(&a);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user