summaryrefslogtreecommitdiff
path: root/lib/lvgl/examples/layouts/flex
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/layouts/flex
parent6fd588e970470b15936187980829916d0dbe77bb (diff)
downloadtangara-fw-dd27c3530432ea0b09f01e604bf577f31d8ef841.tar.gz
convert lvgl from submodule to a plain old directory
Diffstat (limited to 'lib/lvgl/examples/layouts/flex')
m---------lib/lvgl0
-rw-r--r--lib/lvgl/examples/layouts/flex/index.rst37
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex.h43
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_1.c44
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_1.py33
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_2.c32
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_2.py22
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_3.c30
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_3.py23
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_4.c26
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_4.py16
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_5.c51
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_5.py47
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_6.c26
-rw-r--r--lib/lvgl/examples/layouts/flex/lv_example_flex_6.py19
15 files changed, 449 insertions, 0 deletions
diff --git a/lib/lvgl b/lib/lvgl
deleted file mode 160000
-Subproject 0732400e7b564dd0e7dc4a924619d8e19c5b23a
diff --git a/lib/lvgl/examples/layouts/flex/index.rst b/lib/lvgl/examples/layouts/flex/index.rst
new file mode 100644
index 00000000..2ff931c0
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/index.rst
@@ -0,0 +1,37 @@
+A simple row and a column layout with flexbox
+"""""""""""""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: layouts/flex/lv_example_flex_1
+ :language: c
+
+Arrange items in rows with wrap and even spacing
+"""""""""""""""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: layouts/flex/lv_example_flex_2
+ :language: c
+
+Demonstrate flex grow
+"""""""""""""""""""""""
+
+.. lv_example:: layouts/flex/lv_example_flex_3
+ :language: c
+
+Demonstrate flex grow.
+"""""""""""""""""""""""
+
+.. lv_example:: layouts/flex/lv_example_flex_4
+ :language: c
+
+Demonstrate column and row gap style properties
+"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: layouts/flex/lv_example_flex_5
+ :language: c
+
+RTL base direction changes order of the items
+"""""""""""""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: layouts/flex/lv_example_flex_6
+ :language: c
+
+
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex.h b/lib/lvgl/examples/layouts/flex/lv_example_flex.h
new file mode 100644
index 00000000..10fabbdc
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex.h
@@ -0,0 +1,43 @@
+/**
+ * @file lv_example_flex.h
+ *
+ */
+
+#ifndef LV_EXAMPLE_FLEX_H
+#define LV_EXAMPLE_FLEX_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************
+ * INCLUDES
+ *********************/
+
+/*********************
+ * DEFINES
+ *********************/
+
+/**********************
+ * TYPEDEFS
+ **********************/
+
+/**********************
+ * GLOBAL PROTOTYPES
+ **********************/
+void lv_example_flex_1(void);
+void lv_example_flex_2(void);
+void lv_example_flex_3(void);
+void lv_example_flex_4(void);
+void lv_example_flex_5(void);
+void lv_example_flex_6(void);
+
+/**********************
+ * MACROS
+ **********************/
+
+#ifdef __cplusplus
+} /*extern "C"*/
+#endif
+
+#endif /*LV_EXAMPLE_FLEX_H*/
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_1.c b/lib/lvgl/examples/layouts/flex/lv_example_flex_1.c
new file mode 100644
index 00000000..6363d37e
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_1.c
@@ -0,0 +1,44 @@
+#include "../../lv_examples.h"
+#if LV_USE_FLEX && LV_BUILD_EXAMPLES
+
+/**
+ * A simple row and a column layout with flexbox
+ */
+void lv_example_flex_1(void)
+{
+ /*Create a container with ROW flex direction*/
+ lv_obj_t * cont_row = lv_obj_create(lv_scr_act());
+ lv_obj_set_size(cont_row, 300, 75);
+ lv_obj_align(cont_row, LV_ALIGN_TOP_MID, 0, 5);
+ lv_obj_set_flex_flow(cont_row, LV_FLEX_FLOW_ROW);
+
+ /*Create a container with COLUMN flex direction*/
+ lv_obj_t * cont_col = lv_obj_create(lv_scr_act());
+ lv_obj_set_size(cont_col, 200, 150);
+ lv_obj_align_to(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5);
+ lv_obj_set_flex_flow(cont_col, LV_FLEX_FLOW_COLUMN);
+
+ uint32_t i;
+ for(i = 0; i < 10; i++) {
+ lv_obj_t * obj;
+ lv_obj_t * label;
+
+ /*Add items to the row*/
+ obj = lv_btn_create(cont_row);
+ lv_obj_set_size(obj, 100, LV_PCT(100));
+
+ label = lv_label_create(obj);
+ lv_label_set_text_fmt(label, "Item: %u", i);
+ lv_obj_center(label);
+
+ /*Add items to the column*/
+ obj = lv_btn_create(cont_col);
+ lv_obj_set_size(obj, LV_PCT(100), LV_SIZE_CONTENT);
+
+ label = lv_label_create(obj);
+ lv_label_set_text_fmt(label, "Item: %"LV_PRIu32, i);
+ lv_obj_center(label);
+ }
+}
+
+#endif
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_1.py b/lib/lvgl/examples/layouts/flex/lv_example_flex_1.py
new file mode 100644
index 00000000..8dc23851
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_1.py
@@ -0,0 +1,33 @@
+#
+# A simple row and a column layout with flexbox
+#
+
+# Create a container with ROW flex direction
+cont_row = lv.obj(lv.scr_act())
+cont_row.set_size(300, 75)
+cont_row.align(lv.ALIGN.TOP_MID, 0, 5)
+cont_row.set_flex_flow(lv.FLEX_FLOW.ROW)
+
+# Create a container with COLUMN flex direction
+cont_col = lv.obj(lv.scr_act())
+cont_col.set_size(200, 150)
+cont_col.align_to(cont_row, lv.ALIGN.OUT_BOTTOM_MID, 0, 5)
+cont_col.set_flex_flow(lv.FLEX_FLOW.COLUMN)
+
+for i in range(10):
+ # Add items to the row
+ obj = lv.btn(cont_row)
+ obj.set_size(100, lv.pct(100))
+
+ label = lv.label(obj)
+ label.set_text("Item: {:d}".format(i))
+ label.center()
+
+ # Add items to the column
+ obj = lv.btn(cont_col)
+ obj.set_size(lv.pct(100), lv.SIZE.CONTENT)
+
+ label = lv.label(obj)
+ label.set_text("Item: {:d}".format(i))
+ label.center()
+
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_2.c b/lib/lvgl/examples/layouts/flex/lv_example_flex_2.c
new file mode 100644
index 00000000..dc60744b
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_2.c
@@ -0,0 +1,32 @@
+#include "../../lv_examples.h"
+#if LV_USE_FLEX && LV_BUILD_EXAMPLES
+
+/**
+ * Arrange items in rows with wrap and place the items to get even space around them.
+ */
+void lv_example_flex_2(void)
+{
+ static lv_style_t style;
+ lv_style_init(&style);
+ lv_style_set_flex_flow(&style, LV_FLEX_FLOW_ROW_WRAP);
+ lv_style_set_flex_main_place(&style, LV_FLEX_ALIGN_SPACE_EVENLY);
+ lv_style_set_layout(&style, LV_LAYOUT_FLEX);
+
+ lv_obj_t * cont = lv_obj_create(lv_scr_act());
+ lv_obj_set_size(cont, 300, 220);
+ lv_obj_center(cont);
+ lv_obj_add_style(cont, &style, 0);
+
+ uint32_t i;
+ for(i = 0; i < 8; i++) {
+ lv_obj_t * obj = lv_obj_create(cont);
+ lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
+ lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE);
+
+ lv_obj_t * label = lv_label_create(obj);
+ lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
+ lv_obj_center(label);
+ }
+}
+
+#endif
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_2.py b/lib/lvgl/examples/layouts/flex/lv_example_flex_2.py
new file mode 100644
index 00000000..7a8012c1
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_2.py
@@ -0,0 +1,22 @@
+#
+# Arrange items in rows with wrap and place the items to get even space around them.
+#
+style = lv.style_t()
+style.init()
+style.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
+style.set_flex_main_place(lv.FLEX_ALIGN.SPACE_EVENLY)
+style.set_layout(lv.LAYOUT_FLEX.value)
+
+cont = lv.obj(lv.scr_act())
+cont.set_size(300, 220)
+cont.center()
+cont.add_style(style, 0)
+
+for i in range(8):
+ obj = lv.obj(cont)
+ obj.set_size(70, lv.SIZE.CONTENT)
+
+ label = lv.label(obj)
+ label.set_text("{:d}".format(i))
+ label.center()
+
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_3.c b/lib/lvgl/examples/layouts/flex/lv_example_flex_3.c
new file mode 100644
index 00000000..65e0f8a3
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_3.c
@@ -0,0 +1,30 @@
+#include "../../lv_examples.h"
+#if LV_USE_FLEX && LV_BUILD_EXAMPLES
+
+/**
+ * Demonstrate flex grow.
+ */
+void lv_example_flex_3(void)
+{
+ lv_obj_t * cont = lv_obj_create(lv_scr_act());
+ lv_obj_set_size(cont, 300, 220);
+ lv_obj_center(cont);
+ lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW);
+
+ lv_obj_t * obj;
+ obj = lv_obj_create(cont);
+ lv_obj_set_size(obj, 40, 40); /*Fix size*/
+
+ obj = lv_obj_create(cont);
+ lv_obj_set_height(obj, 40);
+ lv_obj_set_flex_grow(obj, 1); /*1 portion from the free space*/
+
+ obj = lv_obj_create(cont);
+ lv_obj_set_height(obj, 40);
+ lv_obj_set_flex_grow(obj, 2); /*2 portion from the free space*/
+
+ obj = lv_obj_create(cont);
+ lv_obj_set_size(obj, 40, 40); /*Fix size. It is flushed to the right by the "grow" items*/
+}
+
+#endif
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_3.py b/lib/lvgl/examples/layouts/flex/lv_example_flex_3.py
new file mode 100644
index 00000000..fb60ce91
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_3.py
@@ -0,0 +1,23 @@
+#
+# Demonstrate flex grow.
+#
+
+cont = lv.obj(lv.scr_act())
+cont.set_size(300, 220)
+cont.center()
+cont.set_flex_flow(lv.FLEX_FLOW.ROW)
+
+obj = lv.obj(cont)
+obj.set_size(40, 40) # Fix size
+
+obj = lv.obj(cont)
+obj.set_height(40)
+obj.set_flex_grow(1) # 1 portion from the free space
+
+obj = lv.obj(cont)
+obj.set_height(40)
+obj.set_flex_grow(2) # 2 portion from the free space
+
+obj = lv.obj(cont)
+obj.set_size(40, 40) # Fix size. It is flushed to the right by the "grow" items
+
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_4.c b/lib/lvgl/examples/layouts/flex/lv_example_flex_4.c
new file mode 100644
index 00000000..7aa387f8
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_4.c
@@ -0,0 +1,26 @@
+#include "../../lv_examples.h"
+#if LV_USE_FLEX && LV_BUILD_EXAMPLES
+
+/**
+ * Reverse the order of flex items
+ */
+void lv_example_flex_4(void)
+{
+
+ lv_obj_t * cont = lv_obj_create(lv_scr_act());
+ lv_obj_set_size(cont, 300, 220);
+ lv_obj_center(cont);
+ lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_COLUMN_REVERSE);
+
+ uint32_t i;
+ for(i = 0; i < 6; i++) {
+ lv_obj_t * obj = lv_obj_create(cont);
+ lv_obj_set_size(obj, 100, 50);
+
+ lv_obj_t * label = lv_label_create(obj);
+ lv_label_set_text_fmt(label, "Item: %"LV_PRIu32, i);
+ lv_obj_center(label);
+ }
+}
+
+#endif
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_4.py b/lib/lvgl/examples/layouts/flex/lv_example_flex_4.py
new file mode 100644
index 00000000..4958e938
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_4.py
@@ -0,0 +1,16 @@
+#
+# Reverse the order of flex items
+#
+cont = lv.obj(lv.scr_act())
+cont.set_size(300, 220)
+cont.center()
+cont.set_flex_flow(lv.FLEX_FLOW.COLUMN_REVERSE)
+
+for i in range(6):
+ obj = lv.obj(cont)
+ obj.set_size(100, 50)
+
+ label = lv.label(obj)
+ label.set_text("Item: " + str(i))
+ label.center()
+
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_5.c b/lib/lvgl/examples/layouts/flex/lv_example_flex_5.c
new file mode 100644
index 00000000..2b505184
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_5.c
@@ -0,0 +1,51 @@
+#include "../../lv_examples.h"
+#if LV_USE_FLEX && LV_BUILD_EXAMPLES
+
+static void row_gap_anim(void * obj, int32_t v)
+{
+ lv_obj_set_style_pad_row(obj, v, 0);
+}
+
+static void column_gap_anim(void * obj, int32_t v)
+{
+ lv_obj_set_style_pad_column(obj, v, 0);
+}
+
+/**
+ * Demonstrate the effect of column and row gap style properties
+ */
+void lv_example_flex_5(void)
+{
+ lv_obj_t * cont = lv_obj_create(lv_scr_act());
+ lv_obj_set_size(cont, 300, 220);
+ lv_obj_center(cont);
+ lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);
+
+ uint32_t i;
+ for(i = 0; i < 9; i++) {
+ lv_obj_t * obj = lv_obj_create(cont);
+ lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
+
+ lv_obj_t * label = lv_label_create(obj);
+ lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
+ lv_obj_center(label);
+ }
+
+ lv_anim_t a;
+ lv_anim_init(&a);
+ lv_anim_set_var(&a, cont);
+ lv_anim_set_values(&a, 0, 10);
+ lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE);
+
+ lv_anim_set_exec_cb(&a, row_gap_anim);
+ lv_anim_set_time(&a, 500);
+ lv_anim_set_playback_time(&a, 500);
+ lv_anim_start(&a);
+
+ lv_anim_set_exec_cb(&a, column_gap_anim);
+ lv_anim_set_time(&a, 3000);
+ lv_anim_set_playback_time(&a, 3000);
+ lv_anim_start(&a);
+}
+
+#endif
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_5.py b/lib/lvgl/examples/layouts/flex/lv_example_flex_5.py
new file mode 100644
index 00000000..11e11f96
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_5.py
@@ -0,0 +1,47 @@
+def row_gap_anim(obj, v):
+ obj.set_style_pad_row(v, 0)
+
+
+def column_gap_anim(obj, v):
+ obj.set_style_pad_column(v, 0)
+
+#
+# Demonstrate the effect of column and row gap style properties
+#
+
+cont = lv.obj(lv.scr_act())
+cont.set_size(300, 220)
+cont.center()
+cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
+
+for i in range(9):
+ obj = lv.obj(cont)
+ obj.set_size(70, lv.SIZE.CONTENT)
+
+ label = lv.label(obj)
+ label.set_text(str(i))
+ label.center()
+
+a_row = lv.anim_t()
+a_row.init()
+a_row.set_var(cont)
+a_row.set_values(0, 10)
+a_row.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
+
+a_row.set_time(500)
+a_row.set_playback_time(500)
+a_row.set_custom_exec_cb(lambda a,val: row_gap_anim(cont,val))
+lv.anim_t.start(a_row)
+
+a_col = lv.anim_t()
+a_col.init()
+a_col.set_var(cont)
+a_col.set_values(0, 10)
+a_col.set_repeat_count(lv.ANIM_REPEAT.INFINITE)
+
+a_col.set_time(3000)
+a_col.set_playback_time(3000)
+a_col.set_custom_exec_cb(lambda a,val: column_gap_anim(cont,val))
+
+lv.anim_t.start(a_col)
+
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_6.c b/lib/lvgl/examples/layouts/flex/lv_example_flex_6.c
new file mode 100644
index 00000000..a481af07
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_6.c
@@ -0,0 +1,26 @@
+#include "../../lv_examples.h"
+#if LV_USE_FLEX && LV_BUILD_EXAMPLES
+
+/**
+ * RTL base direction changes order of the items.
+ * Also demonstrate how horizontal scrolling works with RTL.
+ */
+void lv_example_flex_6(void)
+{
+ lv_obj_t * cont = lv_obj_create(lv_scr_act());
+ lv_obj_set_style_base_dir(cont, LV_BASE_DIR_RTL, 0);
+ lv_obj_set_size(cont, 300, 220);
+ lv_obj_center(cont);
+ lv_obj_set_flex_flow(cont, LV_FLEX_FLOW_ROW_WRAP);
+
+ uint32_t i;
+ for(i = 0; i < 20; i++) {
+ lv_obj_t * obj = lv_obj_create(cont);
+ lv_obj_set_size(obj, 70, LV_SIZE_CONTENT);
+
+ lv_obj_t * label = lv_label_create(obj);
+ lv_label_set_text_fmt(label, "%"LV_PRIu32, i);
+ lv_obj_center(label);
+ }
+}
+#endif
diff --git a/lib/lvgl/examples/layouts/flex/lv_example_flex_6.py b/lib/lvgl/examples/layouts/flex/lv_example_flex_6.py
new file mode 100644
index 00000000..1f50433d
--- /dev/null
+++ b/lib/lvgl/examples/layouts/flex/lv_example_flex_6.py
@@ -0,0 +1,19 @@
+#
+# RTL base direction changes order of the items.
+# Also demonstrate how horizontal scrolling works with RTL.
+#
+
+cont = lv.obj(lv.scr_act())
+cont.set_style_base_dir(lv.BASE_DIR.RTL,0)
+cont.set_size(300, 220)
+cont.center()
+cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
+
+for i in range(20):
+ obj = lv.obj(cont)
+ obj.set_size(70, lv.SIZE.CONTENT)
+
+ label = lv.label(obj)
+ label.set_text(str(i))
+ label.center()
+