diff options
Diffstat (limited to 'lib/lvgl/examples/widgets/dropdown')
| m--------- | lib/lvgl | 0 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/index.rst | 20 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.c | 35 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.py | 26 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.c | 39 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.py | 34 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.c | 43 | ||||
| -rw-r--r-- | lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.py | 53 |
8 files changed, 250 insertions, 0 deletions
diff --git a/lib/lvgl b/lib/lvgl deleted file mode 160000 -Subproject 0732400e7b564dd0e7dc4a924619d8e19c5b23a diff --git a/lib/lvgl/examples/widgets/dropdown/index.rst b/lib/lvgl/examples/widgets/dropdown/index.rst new file mode 100644 index 00000000..c396361a --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/index.rst @@ -0,0 +1,20 @@ + +Simple Drop down list +"""""""""""""""""""""" + +.. lv_example:: widgets/dropdown/lv_example_dropdown_1 + :language: c + +Drop down in four directions +"""""""""""""""""""""""""""" + +.. lv_example:: widgets/dropdown/lv_example_dropdown_2 + :language: c + + +Menu +"""""""""""" + +.. lv_example:: widgets/dropdown/lv_example_dropdown_3 + :language: c + diff --git a/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.c b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.c new file mode 100644 index 00000000..275e6cf6 --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.c @@ -0,0 +1,35 @@ +#include "../../lv_examples.h" +#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES + +static void event_handler(lv_event_t * e) +{ + lv_event_code_t code = lv_event_get_code(e); + lv_obj_t * obj = lv_event_get_target(e); + if(code == LV_EVENT_VALUE_CHANGED) { + char buf[32]; + lv_dropdown_get_selected_str(obj, buf, sizeof(buf)); + LV_LOG_USER("Option: %s", buf); + } +} + +void lv_example_dropdown_1(void) +{ + + /*Create a normal drop down list*/ + lv_obj_t * dd = lv_dropdown_create(lv_scr_act()); + lv_dropdown_set_options(dd, "Apple\n" + "Banana\n" + "Orange\n" + "Cherry\n" + "Grape\n" + "Raspberry\n" + "Melon\n" + "Orange\n" + "Lemon\n" + "Nuts"); + + lv_obj_align(dd, LV_ALIGN_TOP_MID, 0, 20); + lv_obj_add_event_cb(dd, event_handler, LV_EVENT_ALL, NULL); +} + +#endif diff --git a/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.py b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.py new file mode 100644 index 00000000..ad7621e1 --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_1.py @@ -0,0 +1,26 @@ +def event_handler(e): + code = e.get_code() + obj = e.get_target() + if code == lv.EVENT.VALUE_CHANGED: + option = " "*10 # should be large enough to store the option + obj.get_selected_str(option, len(option)) + # .strip() removes trailing spaces + print("Option: \"%s\"" % option.strip()) + +# Create a normal drop down list +dd = lv.dropdown(lv.scr_act()) +dd.set_options("\n".join([ + "Apple", + "Banana", + "Orange", + "Cherry", + "Grape", + "Raspberry", + "Melon", + "Orange", + "Lemon", + "Nuts"])) + +dd.align(lv.ALIGN.TOP_MID, 0, 20) +dd.add_event_cb(event_handler, lv.EVENT.ALL, None) + diff --git a/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.c b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.c new file mode 100644 index 00000000..77f15791 --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.c @@ -0,0 +1,39 @@ +#include "../../lv_examples.h" +#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES + + +/** + * Create a drop down, up, left and right menus + */ +void lv_example_dropdown_2(void) +{ + static const char * opts = "Apple\n" + "Banana\n" + "Orange\n" + "Melon"; + + lv_obj_t * dd; + dd = lv_dropdown_create(lv_scr_act()); + lv_dropdown_set_options_static(dd, opts); + lv_obj_align(dd, LV_ALIGN_TOP_MID, 0, 10); + + dd = lv_dropdown_create(lv_scr_act()); + lv_dropdown_set_options_static(dd, opts); + lv_dropdown_set_dir(dd, LV_DIR_BOTTOM); + lv_dropdown_set_symbol(dd, LV_SYMBOL_UP); + lv_obj_align(dd, LV_ALIGN_BOTTOM_MID, 0, -10); + + dd = lv_dropdown_create(lv_scr_act()); + lv_dropdown_set_options_static(dd, opts); + lv_dropdown_set_dir(dd, LV_DIR_RIGHT); + lv_dropdown_set_symbol(dd, LV_SYMBOL_RIGHT); + lv_obj_align(dd, LV_ALIGN_LEFT_MID, 10, 0); + + dd = lv_dropdown_create(lv_scr_act()); + lv_dropdown_set_options_static(dd, opts); + lv_dropdown_set_dir(dd, LV_DIR_LEFT); + lv_dropdown_set_symbol(dd, LV_SYMBOL_LEFT); + lv_obj_align(dd, LV_ALIGN_RIGHT_MID, -10, 0); +} + +#endif diff --git a/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.py b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.py new file mode 100644 index 00000000..49271137 --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_2.py @@ -0,0 +1,34 @@ +# +# Create a drop down, up, left and right menus +# + +opts = "\n".join([ + "Apple", + "Banana", + "Orange", + "Melon", + "Grape", + "Raspberry"]) + +dd = lv.dropdown(lv.scr_act()) +dd.set_options_static(opts) +dd.align(lv.ALIGN.TOP_MID, 0, 10) +dd = lv.dropdown(lv.scr_act()) +dd.set_options_static(opts) +dd.set_dir(lv.DIR.BOTTOM) +dd.set_symbol(lv.SYMBOL.UP) +dd.align(lv.ALIGN.BOTTOM_MID, 0, -10) + +dd = lv.dropdown(lv.scr_act()) +dd.set_options_static(opts) +dd.set_dir(lv.DIR.RIGHT) +dd.set_symbol(lv.SYMBOL.RIGHT) +dd.align(lv.ALIGN.LEFT_MID, 10, 0) + +dd = lv.dropdown(lv.scr_act()) +dd.set_options_static(opts) +dd.set_dir(lv.DIR.LEFT) +dd.set_symbol(lv.SYMBOL.LEFT) +dd.align(lv.ALIGN.RIGHT_MID, -10, 0) + + diff --git a/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.c b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.c new file mode 100644 index 00000000..123cb8dd --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.c @@ -0,0 +1,43 @@ +#include "../../lv_examples.h" +#if LV_USE_DROPDOWN && LV_BUILD_EXAMPLES + +static void event_cb(lv_event_t * e) +{ + lv_obj_t * dropdown = lv_event_get_target(e); + char buf[64]; + lv_dropdown_get_selected_str(dropdown, buf, sizeof(buf)); + LV_LOG_USER("'%s' is selected", buf); +} + +/** + * Create a menu from a drop-down list and show some drop-down list features and styling + */ +void lv_example_dropdown_3(void) +{ + /*Create a drop down list*/ + lv_obj_t * dropdown = lv_dropdown_create(lv_scr_act()); + lv_obj_align(dropdown, LV_ALIGN_TOP_LEFT, 10, 10); + lv_dropdown_set_options(dropdown, "New project\n" + "New file\n" + "Save\n" + "Save as ...\n" + "Open project\n" + "Recent projects\n" + "Preferences\n" + "Exit"); + + /*Set a fixed text to display on the button of the drop-down list*/ + lv_dropdown_set_text(dropdown, "Menu"); + + /*Use a custom image as down icon and flip it when the list is opened*/ + LV_IMG_DECLARE(img_caret_down) + lv_dropdown_set_symbol(dropdown, &img_caret_down); + lv_obj_set_style_transform_angle(dropdown, 1800, LV_PART_INDICATOR | LV_STATE_CHECKED); + + /*In a menu we don't need to show the last clicked item*/ + lv_dropdown_set_selected_highlight(dropdown, false); + + lv_obj_add_event_cb(dropdown, event_cb, LV_EVENT_VALUE_CHANGED, NULL); +} + +#endif diff --git a/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.py b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.py new file mode 100644 index 00000000..07ba0718 --- /dev/null +++ b/lib/lvgl/examples/widgets/dropdown/lv_example_dropdown_3.py @@ -0,0 +1,53 @@ +from imagetools import get_png_info, open_png + +# Register PNG image decoder +decoder = lv.img.decoder_create() +decoder.info_cb = get_png_info +decoder.open_cb = open_png + +# Create an image from the png file +try: + with open('../../assets/img_caret_down.png','rb') as f: + png_data = f.read() +except: + print("Could not find img_caret_down.png") + sys.exit() + +img_caret_down_argb = lv.img_dsc_t({ + 'data_size': len(png_data), + 'data': png_data +}) + +def event_cb(e): + dropdown = e.get_target() + option = " "*64 # should be large enough to store the option + dropdown.get_selected_str(option, len(option)) + print(option.strip() +" is selected") +# +# Create a menu from a drop-down list and show some drop-down list features and styling +# + +# Create a drop down list +dropdown = lv.dropdown(lv.scr_act()) +dropdown.align(lv.ALIGN.TOP_LEFT, 10, 10) +dropdown.set_options("\n".join([ + "New project", + "New file", + "Open project", + "Recent projects", + "Preferences", + "Exit"])) + +# Set a fixed text to display on the button of the drop-down list +dropdown.set_text("Menu") + +# Use a custom image as down icon and flip it when the list is opened +# LV_IMG_DECLARE(img_caret_down) +dropdown.set_symbol(img_caret_down_argb) +dropdown.set_style_transform_angle(1800, lv.PART.INDICATOR | lv.STATE.CHECKED) + +# In a menu we don't need to show the last clicked item +dropdown.set_selected_highlight(False) + +dropdown.add_event_cb(event_cb, lv.EVENT.VALUE_CHANGED, None) + |
