summaryrefslogtreecommitdiff
path: root/lib/lvgl/examples/widgets/roller
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-06-01 15:41:47 +1000
committerjacqueline <me@jacqueline.id.au>2023-06-01 15:41:47 +1000
commitdd27c3530432ea0b09f01e604bf577f31d8ef841 (patch)
treebbf86cf81a78f0ff0b07f31f1c390db473f26fd3 /lib/lvgl/examples/widgets/roller
parent6fd588e970470b15936187980829916d0dbe77bb (diff)
downloadtangara-fw-dd27c3530432ea0b09f01e604bf577f31d8ef841.tar.gz
convert lvgl from submodule to a plain old directory
Diffstat (limited to 'lib/lvgl/examples/widgets/roller')
m---------lib/lvgl0
-rw-r--r--lib/lvgl/examples/widgets/roller/index.rst19
-rw-r--r--lib/lvgl/examples/widgets/roller/lv_example_roller_1.c41
-rw-r--r--lib/lvgl/examples/widgets/roller/lv_example_roller_1.py31
-rw-r--r--lib/lvgl/examples/widgets/roller/lv_example_roller_2.c60
-rw-r--r--lib/lvgl/examples/widgets/roller/lv_example_roller_2.py60
-rw-r--r--lib/lvgl/examples/widgets/roller/lv_example_roller_3.c96
-rw-r--r--lib/lvgl/examples/widgets/roller/lv_example_roller_3.py99
8 files changed, 406 insertions, 0 deletions
diff --git a/lib/lvgl b/lib/lvgl
deleted file mode 160000
-Subproject 0732400e7b564dd0e7dc4a924619d8e19c5b23a
diff --git a/lib/lvgl/examples/widgets/roller/index.rst b/lib/lvgl/examples/widgets/roller/index.rst
new file mode 100644
index 00000000..23a81d68
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/index.rst
@@ -0,0 +1,19 @@
+
+Simple Roller
+""""""""""""""""
+
+.. lv_example:: widgets/roller/lv_example_roller_1
+ :language: c
+
+Styling the roller
+""""""""""""""""""
+
+.. lv_example:: widgets/roller/lv_example_roller_2
+ :language: c
+
+add fade mask to roller
+"""""""""""""""""""""""
+
+.. lv_example:: widgets/roller/lv_example_roller_3
+ :language: c
+
diff --git a/lib/lvgl/examples/widgets/roller/lv_example_roller_1.c b/lib/lvgl/examples/widgets/roller/lv_example_roller_1.c
new file mode 100644
index 00000000..93dd0be1
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/lv_example_roller_1.c
@@ -0,0 +1,41 @@
+#include "../../lv_examples.h"
+#if LV_USE_ROLLER && 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_roller_get_selected_str(obj, buf, sizeof(buf));
+ LV_LOG_USER("Selected month: %s\n", buf);
+ }
+}
+
+/**
+ * An infinite roller with the name of the months
+ */
+void lv_example_roller_1(void)
+{
+ lv_obj_t * roller1 = lv_roller_create(lv_scr_act());
+ lv_roller_set_options(roller1,
+ "January\n"
+ "February\n"
+ "March\n"
+ "April\n"
+ "May\n"
+ "June\n"
+ "July\n"
+ "August\n"
+ "September\n"
+ "October\n"
+ "November\n"
+ "December",
+ LV_ROLLER_MODE_INFINITE);
+
+ lv_roller_set_visible_row_count(roller1, 4);
+ lv_obj_center(roller1);
+ lv_obj_add_event_cb(roller1, event_handler, LV_EVENT_ALL, NULL);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/roller/lv_example_roller_1.py b/lib/lvgl/examples/widgets/roller/lv_example_roller_1.py
new file mode 100644
index 00000000..a638321b
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/lv_example_roller_1.py
@@ -0,0 +1,31 @@
+def event_handler(e):
+ code = e.get_code()
+ obj = e.get_target()
+ if code == lv.EVENT.VALUE_CHANGED:
+ option = " "*10
+ obj.get_selected_str(option, len(option))
+ print("Selected month: " + option.strip())
+
+#
+# An infinite roller with the name of the months
+#
+
+roller1 = lv.roller(lv.scr_act())
+roller1.set_options("\n".join([
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December"]),lv.roller.MODE.INFINITE)
+
+roller1.set_visible_row_count(4)
+roller1.center()
+roller1.add_event_cb(event_handler, lv.EVENT.ALL, None)
+
diff --git a/lib/lvgl/examples/widgets/roller/lv_example_roller_2.c b/lib/lvgl/examples/widgets/roller/lv_example_roller_2.c
new file mode 100644
index 00000000..8c4b6fd2
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/lv_example_roller_2.c
@@ -0,0 +1,60 @@
+#include "../../lv_examples.h"
+#if LV_USE_ROLLER && LV_FONT_MONTSERRAT_22 && 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_roller_get_selected_str(obj, buf, sizeof(buf));
+ LV_LOG_USER("Selected value: %s", buf);
+ }
+}
+
+/**
+ * Roller with various alignments and larger text in the selected area
+ */
+void lv_example_roller_2(void)
+{
+ /*A style to make the selected option larger*/
+ static lv_style_t style_sel;
+ lv_style_init(&style_sel);
+ lv_style_set_text_font(&style_sel, &lv_font_montserrat_22);
+
+ const char * opts = "1\n2\n3\n4\n5\n6\n7\n8\n9\n10";
+ lv_obj_t * roller;
+
+ /*A roller on the left with left aligned text, and custom width*/
+ roller = lv_roller_create(lv_scr_act());
+ lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);
+ lv_roller_set_visible_row_count(roller, 2);
+ lv_obj_set_width(roller, 100);
+ lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);
+ lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_LEFT, 0);
+ lv_obj_align(roller, LV_ALIGN_LEFT_MID, 10, 0);
+ lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL);
+ lv_roller_set_selected(roller, 2, LV_ANIM_OFF);
+
+ /*A roller on the middle with center aligned text, and auto (default) width*/
+ roller = lv_roller_create(lv_scr_act());
+ lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);
+ lv_roller_set_visible_row_count(roller, 3);
+ lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);
+ lv_obj_align(roller, LV_ALIGN_CENTER, 0, 0);
+ lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL);
+ lv_roller_set_selected(roller, 5, LV_ANIM_OFF);
+
+ /*A roller on the right with right aligned text, and custom width*/
+ roller = lv_roller_create(lv_scr_act());
+ lv_roller_set_options(roller, opts, LV_ROLLER_MODE_NORMAL);
+ lv_roller_set_visible_row_count(roller, 4);
+ lv_obj_set_width(roller, 80);
+ lv_obj_add_style(roller, &style_sel, LV_PART_SELECTED);
+ lv_obj_set_style_text_align(roller, LV_TEXT_ALIGN_RIGHT, 0);
+ lv_obj_align(roller, LV_ALIGN_RIGHT_MID, -10, 0);
+ lv_obj_add_event_cb(roller, event_handler, LV_EVENT_ALL, NULL);
+ lv_roller_set_selected(roller, 8, LV_ANIM_OFF);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/roller/lv_example_roller_2.py b/lib/lvgl/examples/widgets/roller/lv_example_roller_2.py
new file mode 100644
index 00000000..7f8f7b3b
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/lv_example_roller_2.py
@@ -0,0 +1,60 @@
+import fs_driver
+
+
+def event_handler(e):
+ code = e.get_code()
+ obj = e.get_target()
+ if code == lv.EVENT.VALUE_CHANGED:
+ option = " "*10
+ obj.get_selected_str(option, len(option))
+ print("Selected value: %s\n" + option.strip())
+
+#
+# Roller with various alignments and larger text in the selected area
+#
+
+# A style to make the selected option larger
+style_sel = lv.style_t()
+style_sel.init()
+
+try:
+ style_sel.set_text_font(lv.font_montserrat_22)
+except:
+ fs_drv = lv.fs_drv_t()
+ fs_driver.fs_register(fs_drv, 'S')
+ print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
+ font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.fnt")
+ style_sel.set_text_font(font_montserrat_22)
+
+opts = "\n".join(["1","2","3","4","5","6","7","8","9","10"])
+
+# A roller on the left with left aligned text, and custom width
+roller = lv.roller(lv.scr_act())
+roller.set_options(opts, lv.roller.MODE.NORMAL)
+roller.set_visible_row_count(2)
+roller.set_width(100)
+roller.add_style(style_sel, lv.PART.SELECTED)
+roller.set_style_text_align(lv.TEXT_ALIGN.LEFT, 0)
+roller.align(lv.ALIGN.LEFT_MID, 10, 0)
+roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
+roller.set_selected(2, lv.ANIM.OFF)
+
+# A roller in the middle with center aligned text, and auto (default) width
+roller = lv.roller(lv.scr_act())
+roller.set_options(opts, lv.roller.MODE.NORMAL)
+roller.set_visible_row_count(3)
+roller.add_style(style_sel, lv.PART.SELECTED)
+roller.align(lv.ALIGN.CENTER, 0, 0)
+roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
+roller.set_selected(5, lv.ANIM.OFF)
+
+# A roller on the right with right aligned text, and custom width
+roller = lv.roller(lv.scr_act())
+roller.set_options(opts, lv.roller.MODE.NORMAL)
+roller.set_visible_row_count(4)
+roller.set_width(80)
+roller.add_style(style_sel, lv.PART.SELECTED)
+roller.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
+roller.align(lv.ALIGN.RIGHT_MID, -10, 0)
+roller.add_event_cb(event_handler, lv.EVENT.ALL, None)
+roller.set_selected(8, lv.ANIM.OFF)
diff --git a/lib/lvgl/examples/widgets/roller/lv_example_roller_3.c b/lib/lvgl/examples/widgets/roller/lv_example_roller_3.c
new file mode 100644
index 00000000..c1e70ff8
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/lv_example_roller_3.c
@@ -0,0 +1,96 @@
+#include "../../lv_examples.h"
+#if LV_USE_ROLLER && LV_DRAW_COMPLEX && LV_BUILD_EXAMPLES
+
+static void mask_event_cb(lv_event_t * e)
+{
+ lv_event_code_t code = lv_event_get_code(e);
+ lv_obj_t * obj = lv_event_get_target(e);
+
+ static int16_t mask_top_id = -1;
+ static int16_t mask_bottom_id = -1;
+
+ if(code == LV_EVENT_COVER_CHECK) {
+ lv_event_set_cover_res(e, LV_COVER_RES_MASKED);
+
+ }
+ else if(code == LV_EVENT_DRAW_MAIN_BEGIN) {
+ /* add mask */
+ const lv_font_t * font = lv_obj_get_style_text_font(obj, LV_PART_MAIN);
+ lv_coord_t line_space = lv_obj_get_style_text_line_space(obj, LV_PART_MAIN);
+ lv_coord_t font_h = lv_font_get_line_height(font);
+
+ lv_area_t roller_coords;
+ lv_obj_get_coords(obj, &roller_coords);
+
+ lv_area_t rect_area;
+ rect_area.x1 = roller_coords.x1;
+ rect_area.x2 = roller_coords.x2;
+ rect_area.y1 = roller_coords.y1;
+ rect_area.y2 = roller_coords.y1 + (lv_obj_get_height(obj) - font_h - line_space) / 2;
+
+ lv_draw_mask_fade_param_t * fade_mask_top = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t));
+ lv_draw_mask_fade_init(fade_mask_top, &rect_area, LV_OPA_TRANSP, rect_area.y1, LV_OPA_COVER, rect_area.y2);
+ mask_top_id = lv_draw_mask_add(fade_mask_top, NULL);
+
+ rect_area.y1 = rect_area.y2 + font_h + line_space - 1;
+ rect_area.y2 = roller_coords.y2;
+
+ lv_draw_mask_fade_param_t * fade_mask_bottom = lv_mem_buf_get(sizeof(lv_draw_mask_fade_param_t));
+ lv_draw_mask_fade_init(fade_mask_bottom, &rect_area, LV_OPA_COVER, rect_area.y1, LV_OPA_TRANSP, rect_area.y2);
+ mask_bottom_id = lv_draw_mask_add(fade_mask_bottom, NULL);
+
+ }
+ else if(code == LV_EVENT_DRAW_POST_END) {
+ lv_draw_mask_fade_param_t * fade_mask_top = lv_draw_mask_remove_id(mask_top_id);
+ lv_draw_mask_fade_param_t * fade_mask_bottom = lv_draw_mask_remove_id(mask_bottom_id);
+ lv_draw_mask_free_param(fade_mask_top);
+ lv_draw_mask_free_param(fade_mask_bottom);
+ lv_mem_buf_release(fade_mask_top);
+ lv_mem_buf_release(fade_mask_bottom);
+ mask_top_id = -1;
+ mask_bottom_id = -1;
+ }
+}
+
+/**
+ * Add a fade mask to roller.
+ */
+void lv_example_roller_3(void)
+{
+ static lv_style_t style;
+ lv_style_init(&style);
+ lv_style_set_bg_color(&style, lv_color_black());
+ lv_style_set_text_color(&style, lv_color_white());
+ lv_style_set_border_width(&style, 0);
+ lv_style_set_pad_all(&style, 0);
+ lv_obj_add_style(lv_scr_act(), &style, 0);
+
+ lv_obj_t * roller1 = lv_roller_create(lv_scr_act());
+ lv_obj_add_style(roller1, &style, 0);
+ lv_obj_set_style_bg_opa(roller1, LV_OPA_TRANSP, LV_PART_SELECTED);
+
+#if LV_FONT_MONTSERRAT_22
+ lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED);
+#endif
+
+ lv_roller_set_options(roller1,
+ "January\n"
+ "February\n"
+ "March\n"
+ "April\n"
+ "May\n"
+ "June\n"
+ "July\n"
+ "August\n"
+ "September\n"
+ "October\n"
+ "November\n"
+ "December",
+ LV_ROLLER_MODE_NORMAL);
+
+ lv_obj_center(roller1);
+ lv_roller_set_visible_row_count(roller1, 3);
+ lv_obj_add_event_cb(roller1, mask_event_cb, LV_EVENT_ALL, NULL);
+}
+
+#endif
diff --git a/lib/lvgl/examples/widgets/roller/lv_example_roller_3.py b/lib/lvgl/examples/widgets/roller/lv_example_roller_3.py
new file mode 100644
index 00000000..13c9e9fb
--- /dev/null
+++ b/lib/lvgl/examples/widgets/roller/lv_example_roller_3.py
@@ -0,0 +1,99 @@
+import fs_driver
+import sys
+
+class Lv_Roller_3():
+
+ def __init__(self):
+ self.mask_top_id = -1
+ self.mask_bottom_id = -1
+
+ #
+ # Add a fade mask to roller.
+ #
+ style = lv.style_t()
+ style.init()
+ style.set_bg_color(lv.color_black())
+ style.set_text_color(lv.color_white())
+
+ lv.scr_act().add_style(style, 0)
+
+ roller1 = lv.roller(lv.scr_act())
+ roller1.add_style(style, 0)
+ roller1.set_style_border_width(0, 0)
+ roller1.set_style_pad_all(0, 0)
+ roller1.set_style_bg_opa(lv.OPA.TRANSP, lv.PART.SELECTED)
+
+ #if LV_FONT_MONTSERRAT_22
+ # lv_obj_set_style_text_font(roller1, &lv_font_montserrat_22, LV_PART_SELECTED);
+ #endif
+ try:
+ roller1.set_style_text_font(lv.font_montserrat_22,lv.PART.SELECTED)
+ except:
+ fs_drv = lv.fs_drv_t()
+ fs_driver.fs_register(fs_drv, 'S')
+ print("montserrat-22 not enabled in lv_conf.h, dynamically loading the font")
+ font_montserrat_22 = lv.font_load("S:" + "../../assets/font/montserrat-22.fnt")
+ roller1.set_style_text_font(font_montserrat_22,lv.PART.SELECTED)
+
+ roller1.set_options("\n".join([
+ "January",
+ "February",
+ "March",
+ "April",
+ "May",
+ "June",
+ "July",
+ "August",
+ "September",
+ "October",
+ "November",
+ "December"]),lv.roller.MODE.NORMAL)
+
+ roller1.center()
+ roller1.set_visible_row_count(3)
+ roller1.add_event_cb(self.mask_event_cb, lv.EVENT.ALL, None)
+
+ def mask_event_cb(self,e):
+
+ code = e.get_code()
+ obj = e.get_target()
+
+ if code == lv.EVENT.COVER_CHECK:
+ e.set_cover_res(lv.COVER_RES.MASKED)
+
+ elif code == lv.EVENT.DRAW_MAIN_BEGIN:
+ # add mask
+ font = obj.get_style_text_font(lv.PART.MAIN)
+ line_space = obj.get_style_text_line_space(lv.PART.MAIN)
+ font_h = font.get_line_height()
+
+ roller_coords = lv.area_t()
+ obj.get_coords(roller_coords)
+
+ rect_area = lv.area_t()
+ rect_area.x1 = roller_coords.x1
+ rect_area.x2 = roller_coords.x2
+ rect_area.y1 = roller_coords.y1
+ rect_area.y2 = roller_coords.y1 + (obj.get_height() - font_h - line_space) // 2
+
+ fade_mask_top = lv.draw_mask_fade_param_t()
+ fade_mask_top.init(rect_area, lv.OPA.TRANSP, rect_area.y1, lv.OPA.COVER, rect_area.y2)
+ self.mask_top_id = lv.draw_mask_add(fade_mask_top,None)
+
+ rect_area.y1 = rect_area.y2 + font_h + line_space - 1
+ rect_area.y2 = roller_coords.y2
+
+ fade_mask_bottom = lv.draw_mask_fade_param_t()
+ fade_mask_bottom.init(rect_area, lv.OPA.COVER, rect_area.y1, lv.OPA.TRANSP, rect_area.y2)
+ self.mask_bottom_id = lv.draw_mask_add(fade_mask_bottom, None)
+
+ elif code == lv.EVENT.DRAW_POST_END:
+ fade_mask_top = lv.draw_mask_remove_id(self.mask_top_id)
+ fade_mask_bottom = lv.draw_mask_remove_id(self.mask_bottom_id)
+ # Remove the masks
+ lv.draw_mask_remove_id(self.mask_top_id)
+ lv.draw_mask_remove_id(self.mask_bottom_id)
+ self.mask_top_id = -1
+ self.mask_bottom_id = -1
+
+roller3 = Lv_Roller_3()