feat(examples): fix examples and add new scroll examples

This commit is contained in:
Gabor Kiss-Vamosi
2021-02-23 11:31:10 +01:00
parent 1442a0f8bc
commit 00b1c80d3c
7 changed files with 156 additions and 4 deletions

View File

@@ -17,6 +17,7 @@ extern "C" {
#include "get_started/lv_example_get_started.h" #include "get_started/lv_example_get_started.h"
#include "widgets/lv_example_widgets.h" #include "widgets/lv_example_widgets.h"
#include "layouts/lv_example_layout.h" #include "layouts/lv_example_layout.h"
#include "scroll/lv_example_scroll.h"
/********************* /*********************
* DEFINES * DEFINES

View File

@@ -0,0 +1,41 @@
/**
* @file lv_example_scroll.h
*
*/
#ifndef LV_EXAMPLE_SCROLL_H
#define LV_EXAMPLE_SCROLL_H
#ifdef __cplusplus
extern "C" {
#endif
/*********************
* INCLUDES
*********************/
/*********************
* DEFINES
*********************/
/**********************
* TYPEDEFS
**********************/
/**********************
* GLOBAL PROTOTYPES
**********************/
void lv_example_scroll_1(void);
void lv_example_scroll_2(void);
void lv_example_scroll_3(void);
void lv_example_scroll_4(void);
/**********************
* MACROS
**********************/
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /*LV_EXAMPLE_SCROLL_H*/

View File

@@ -0,0 +1,48 @@
#include "../../lvgl.h"
#if LV_BUILD_EXAMPLES
/**
* Demonstrate how scrolling appears automatically
*/
void lv_example_scroll_1(void)
{
/*Create an object with the new style*/
lv_obj_t * panel = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(panel, 200, 200);
lv_obj_center(panel);
lv_obj_t * child;
lv_obj_t * label;
child = lv_obj_create(panel, NULL);
lv_obj_set_pos(child, 0, 0);
label = lv_label_create(child, NULL);
lv_label_set_text(label, "Zero");
lv_obj_center(label);
child = lv_obj_create(panel, NULL);
lv_obj_set_pos(child, -40, 100);
label = lv_label_create(child, NULL);
lv_label_set_text(label, "Left");
lv_obj_center(label);
child = lv_obj_create(panel, NULL);
lv_obj_set_pos(child, 90, -30);
label = lv_label_create(child, NULL);
lv_label_set_text(label, "Top");
lv_obj_center(label);
child = lv_obj_create(panel, NULL);
lv_obj_set_pos(child, 150, 80);
label = lv_label_create(child, NULL);
lv_label_set_text(label, "Right");
lv_obj_center(label);
child = lv_obj_create(panel, NULL);
lv_obj_set_pos(child, 60, 170);
label = lv_label_create(child, NULL);
lv_label_set_text(label, "Bottom");
lv_obj_center(label);
}
#endif

View File

@@ -0,0 +1,51 @@
#include "../../lvgl.h"
#if LV_BUILD_EXAMPLES
static void sw_event_cb(lv_obj_t * sw, lv_event_t e)
{
if(e == LV_EVENT_VALUE_CHANGED) {
lv_obj_t * list = lv_event_get_user_data();
if(lv_obj_has_state(sw, LV_STATE_CHECKED)) lv_obj_add_flag(list, LV_OBJ_FLAG_SCROLL_ONE);
else lv_obj_clear_flag(list, LV_OBJ_FLAG_SCROLL_ONE);
}
}
/**
* Show an example to scroll snap
*/
void lv_example_scroll_2(void)
{
lv_obj_t * list = lv_obj_create(lv_scr_act(), NULL);
lv_obj_set_size(list, 280, 150);
lv_obj_set_scroll_snap_align_x(list, LV_SCROLL_SNAP_ALIGN_CENTER);
lv_obj_set_layout(list, &lv_flex_queue);
uint32_t i;
for(i = 0; i < 10; i++) {
lv_obj_t * btn = lv_btn_create(list, NULL);
lv_obj_set_size(btn, 150, 100);
lv_obj_t * label = lv_label_create(btn, NULL);
if(i == 3) {
lv_label_set_text_fmt(label, "Panel %d\nno snap", i);
lv_obj_clear_flag(btn, LV_OBJ_FLAG_SNAPABLE);
} else {
lv_label_set_text_fmt(label, "Panel %d", i);
}
lv_obj_center(label);
}
lv_obj_update_snap(list, LV_ANIM_ON);
/*Switch between "One scroll" and "Normal scroll" mode*/
lv_obj_t * sw = lv_switch_create(lv_scr_act(), NULL);
lv_obj_align(sw, NULL, LV_ALIGN_IN_TOP_RIGHT, -20, 10);
lv_obj_add_event_cb(sw, sw_event_cb, list);
lv_obj_t * label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(label, "One scroll");
lv_obj_align(label, sw, LV_ALIGN_OUT_BOTTOM_MID, 0, 10);
}
#endif

View File

@@ -1,7 +1,7 @@
#include "../../../lvgl.h" #include "../../../lvgl.h"
#if LV_USE_BAR && LV_BUILD_EXAMPLES #if LV_USE_BAR && LV_BUILD_EXAMPLES
static void set_temp(lv_obj_t * bar, int32_t temp) static void set_temp(void * bar, int32_t temp)
{ {
lv_bar_set_value(bar, temp, LV_ANIM_ON); lv_bar_set_value(bar, temp, LV_ANIM_ON);
@@ -24,13 +24,23 @@ void lv_example_bar_3(void)
lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER); 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_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP);
lv_style_set_content_ofs_x(&style_indic, -3); lv_style_set_content_ofs_x(&style_indic, -3);
lv_style_set_content_color(&style_indic, LV_COLOR_GRAY);
lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL); 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_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic);
lv_obj_set_size(bar, 20, 200); lv_obj_set_size(bar, 20, 200);
lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0); lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0);
lv_bar_set_range(bar, -20, 40); lv_bar_set_range(bar, -20, 40);
set_temp(bar, 30);
lv_anim_t a;
lv_anim_init(&a);
lv_anim_set_exec_cb(&a, set_temp);
lv_anim_set_time(&a, 3000);
lv_anim_set_playback_time(&a, 3000);
lv_anim_set_var(&a, bar);
lv_anim_set_values(&a, -20, 40);
lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
lv_anim_start(&a);
} }

View File

@@ -13,7 +13,7 @@ static void event_cb(lv_obj_t * chart, lv_event_t e)
} }
else if(e == LV_EVENT_DRAW_POST_END) { else if(e == LV_EVENT_DRAW_POST_END) {
int32_t id = lv_chart_get_pressed_point(chart); int32_t id = lv_chart_get_pressed_point(chart);
if(id < 0) return; if(id == LV_CHART_POINT_ID_NONE) return;
LV_LOG_USER("Selected point %d\n", id); LV_LOG_USER("Selected point %d\n", id);

View File

@@ -21,8 +21,9 @@ void lv_example_slider_3(void)
/*Now use only a local style.*/ /*Now use only a local style.*/
lv_obj_set_style_content_ofs_y(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, -20); lv_obj_set_style_content_ofs_y(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, -20);
lv_obj_set_style_content_color(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, LV_COLOR_GRAY);
/*To update the avlue text*/ /*To update the value text*/
lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL);
} }