2021-04-08 13:07:48 +02:00
|
|
|
#include "../lv_examples.h"
|
2021-03-23 20:51:39 +01:00
|
|
|
#if LV_BUILD_EXAMPLES && LV_USE_FLEX
|
2021-02-23 11:31:10 +01:00
|
|
|
|
2021-04-14 15:31:54 +02:00
|
|
|
static void sw_event_cb(lv_event_t * e)
|
2021-02-23 11:31:10 +01:00
|
|
|
{
|
2021-04-14 15:31:54 +02:00
|
|
|
lv_event_code_t code = lv_event_get_code(e);
|
|
|
|
lv_obj_t * sw = lv_event_get_target(e);
|
|
|
|
|
|
|
|
if(code == LV_EVENT_VALUE_CHANGED) {
|
|
|
|
lv_obj_t * list = lv_event_get_user_data(e);
|
2021-02-23 11:31:10 +01:00
|
|
|
|
|
|
|
if(lv_obj_has_state(sw, LV_STATE_CHECKED)) lv_obj_add_flag(list, LV_OBJ_FLAG_SCROLL_ONE);
|
2023-10-12 20:37:27 +02:00
|
|
|
else lv_obj_remove_flag(list, LV_OBJ_FLAG_SCROLL_ONE);
|
2021-02-23 11:31:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show an example to scroll snap
|
|
|
|
*/
|
|
|
|
void lv_example_scroll_2(void)
|
|
|
|
{
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * panel = lv_obj_create(lv_screen_active());
|
2021-05-26 16:34:25 +02:00
|
|
|
lv_obj_set_size(panel, 280, 120);
|
2021-02-24 10:00:54 +01:00
|
|
|
lv_obj_set_scroll_snap_x(panel, LV_SCROLL_SNAP_CENTER);
|
2021-03-23 20:51:39 +01:00
|
|
|
lv_obj_set_flex_flow(panel, LV_FLEX_FLOW_ROW);
|
2021-05-26 16:34:25 +02:00
|
|
|
lv_obj_align(panel, LV_ALIGN_CENTER, 0, 20);
|
2021-02-23 11:31:10 +01:00
|
|
|
|
2021-12-20 03:52:07 -05:00
|
|
|
uint32_t i;
|
2021-02-23 11:31:10 +01:00
|
|
|
for(i = 0; i < 10; i++) {
|
2023-09-14 20:12:31 +02:00
|
|
|
lv_obj_t * btn = lv_button_create(panel);
|
2021-05-26 16:34:25 +02:00
|
|
|
lv_obj_set_size(btn, 150, lv_pct(100));
|
2021-02-23 11:31:10 +01:00
|
|
|
|
2021-03-25 13:36:50 +01:00
|
|
|
lv_obj_t * label = lv_label_create(btn);
|
2021-02-23 11:31:10 +01:00
|
|
|
if(i == 3) {
|
2021-12-20 03:52:07 -05:00
|
|
|
lv_label_set_text_fmt(label, "Panel %"LV_PRIu32"\nno snap", i);
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_remove_flag(btn, LV_OBJ_FLAG_SNAPPABLE);
|
2022-02-13 13:59:17 -05:00
|
|
|
}
|
|
|
|
else {
|
2021-12-20 03:52:07 -05:00
|
|
|
lv_label_set_text_fmt(label, "Panel %"LV_PRIu32, i);
|
2021-02-23 11:31:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
lv_obj_center(label);
|
|
|
|
}
|
2021-02-24 10:00:54 +01:00
|
|
|
lv_obj_update_snap(panel, LV_ANIM_ON);
|
2021-02-23 11:31:10 +01:00
|
|
|
|
2021-03-18 17:03:36 +01:00
|
|
|
#if LV_USE_SWITCH
|
2021-02-23 11:31:10 +01:00
|
|
|
/*Switch between "One scroll" and "Normal scroll" mode*/
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * sw = lv_switch_create(lv_screen_active());
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align(sw, LV_ALIGN_TOP_RIGHT, -20, 10);
|
2023-02-20 20:50:58 +01:00
|
|
|
lv_obj_add_event(sw, sw_event_cb, LV_EVENT_ALL, panel);
|
2023-10-12 20:37:27 +02:00
|
|
|
lv_obj_t * label = lv_label_create(lv_screen_active());
|
2021-02-23 11:31:10 +01:00
|
|
|
lv_label_set_text(label, "One scroll");
|
2021-03-25 16:14:17 +01:00
|
|
|
lv_obj_align_to(label, sw, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
|
2021-03-18 17:03:36 +01:00
|
|
|
#endif
|
2021-02-23 11:31:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|