feat(gridnav): single axis movement flags (#6044)
This commit is contained in:
@@ -21,4 +21,10 @@ Simple navigation on a list widget
|
||||
----------------------------------
|
||||
|
||||
.. lv_example:: others/gridnav/lv_example_gridnav_4
|
||||
:language: c
|
||||
:language: c
|
||||
|
||||
Grid navigation for only one axis
|
||||
---------------------------------
|
||||
|
||||
.. lv_example:: others/gridnav/lv_example_gridnav_5
|
||||
:language: c
|
||||
|
||||
@@ -29,6 +29,7 @@ void lv_example_gridnav_1(void);
|
||||
void lv_example_gridnav_2(void);
|
||||
void lv_example_gridnav_3(void);
|
||||
void lv_example_gridnav_4(void);
|
||||
void lv_example_gridnav_5(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
|
||||
69
examples/others/gridnav/lv_example_gridnav_5.c
Normal file
69
examples/others/gridnav/lv_example_gridnav_5.c
Normal file
@@ -0,0 +1,69 @@
|
||||
#include "../../lv_examples.h"
|
||||
#if LV_USE_GRIDNAV && LV_USE_FLEX && LV_BUILD_EXAMPLES
|
||||
|
||||
static const char * opts[] = {"0\n1\n2\n3\n4\n5", "0\n1\n2\n3\n4\n5\n6\n7\n8\n9", "s\nm\nh"};
|
||||
static const int32_t opts_counts[] = {6, 10, 3};
|
||||
|
||||
static lv_obj_t * sliders[3];
|
||||
static lv_obj_t * rollers[3];
|
||||
|
||||
static void slider_key_cb(lv_event_t * e)
|
||||
{
|
||||
uint8_t i = (uint32_t)(uintptr_t)lv_event_get_user_data(e);
|
||||
lv_roller_set_selected(rollers[i], lv_slider_get_value(sliders[i]), LV_ANIM_ON);
|
||||
}
|
||||
static void roller_key_cb(lv_event_t * e)
|
||||
{
|
||||
uint8_t i = (uint32_t)(uintptr_t)lv_event_get_user_data(e);
|
||||
lv_slider_set_value(sliders[i], lv_roller_get_selected(rollers[i]), LV_ANIM_ON);
|
||||
}
|
||||
|
||||
/**
|
||||
* Grid navigation for only one axis
|
||||
*/
|
||||
void lv_example_gridnav_5(void)
|
||||
{
|
||||
/*It's assumed that the default group is set and
|
||||
*there is a keyboard indev*/
|
||||
|
||||
lv_group_t * group = lv_group_get_default();
|
||||
lv_obj_t * cont;
|
||||
|
||||
cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN);
|
||||
lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_size(cont, lv_pct(100), lv_pct(50));
|
||||
lv_obj_align(cont, LV_ALIGN_TOP_MID, 0, 0);
|
||||
/* only up/down keys will be used for grid navigation in this container. */
|
||||
/* left/right will be sent to the sliders */
|
||||
lv_gridnav_add(cont, LV_GRIDNAV_CTRL_VERTICAL_MOVE_ONLY);
|
||||
lv_group_add_obj(group, cont);
|
||||
for(uint32_t i = 0; i < 3; i++) {
|
||||
lv_obj_t * slider = lv_slider_create(cont);
|
||||
lv_slider_set_range(slider, 0, opts_counts[i] - 1);
|
||||
lv_group_remove_obj(slider);
|
||||
lv_obj_set_width(slider, lv_pct(85));
|
||||
sliders[i] = slider;
|
||||
lv_obj_add_event_cb(slider, slider_key_cb, LV_EVENT_KEY, (void *)(uintptr_t)i);
|
||||
}
|
||||
|
||||
cont = lv_obj_create(lv_screen_active());
|
||||
lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
|
||||
lv_obj_set_flex_align(cont, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_CENTER);
|
||||
lv_obj_set_size(cont, lv_pct(100), lv_pct(50));
|
||||
lv_obj_align(cont, LV_ALIGN_BOTTOM_MID, 0, 0);
|
||||
/* only left/right keys will be used for grid navigation in this container. */
|
||||
/* up/down will be sent to the rollers */
|
||||
lv_gridnav_add(cont, LV_GRIDNAV_CTRL_HORIZONTAL_MOVE_ONLY);
|
||||
lv_group_add_obj(group, cont);
|
||||
for(uint32_t i = 0; i < 3; i++) {
|
||||
lv_obj_t * roller = lv_roller_create(cont);
|
||||
lv_roller_set_options(roller, opts[i], LV_ROLLER_MODE_INFINITE);
|
||||
lv_obj_set_size(roller, lv_pct(30), lv_pct(100));
|
||||
lv_group_remove_obj(roller);
|
||||
rollers[i] = roller;
|
||||
lv_obj_add_event_cb(roller, roller_key_cb, LV_EVENT_KEY, (void *)(uintptr_t)i);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user