summaryrefslogtreecommitdiff
path: root/lib/lvgl/examples/get_started
diff options
context:
space:
mode:
Diffstat (limited to 'lib/lvgl/examples/get_started')
m---------lib/lvgl0
-rw-r--r--lib/lvgl/examples/get_started/index.rst18
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started.h40
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started_1.c34
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started_1.py29
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started_2.c83
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started_2.py62
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started_3.c33
-rw-r--r--lib/lvgl/examples/get_started/lv_example_get_started_3.py22
9 files changed, 321 insertions, 0 deletions
diff --git a/lib/lvgl b/lib/lvgl
deleted file mode 160000
-Subproject 0732400e7b564dd0e7dc4a924619d8e19c5b23a
diff --git a/lib/lvgl/examples/get_started/index.rst b/lib/lvgl/examples/get_started/index.rst
new file mode 100644
index 00000000..f1faccbf
--- /dev/null
+++ b/lib/lvgl/examples/get_started/index.rst
@@ -0,0 +1,18 @@
+
+A button with a label and react on click event
+"""""""""""""""""""""""""""""""""""""""""""""""""
+
+.. lv_example:: get_started/lv_example_get_started_1
+ :language: c
+
+Create styles from scratch for buttons
+"""""""""""""""""""""""""""""""""""""""
+.. lv_example:: get_started/lv_example_get_started_2
+ :language: c
+
+Create a slider and write its value on a label
+"""""""""""""""""""""""""""""""""""""""""""""""
+.. lv_example:: get_started/lv_example_get_started_3
+ :language: c
+
+
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started.h b/lib/lvgl/examples/get_started/lv_example_get_started.h
new file mode 100644
index 00000000..02a998c8
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started.h
@@ -0,0 +1,40 @@
+/**
+ * @file lv_example_get_started.h
+ *
+ */
+
+#ifndef LV_EX_GET_STARTED_H
+#define LV_EX_GET_STARTED_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*********************
+ * INCLUDES
+ *********************/
+
+/*********************
+ * DEFINES
+ *********************/
+
+/**********************
+ * TYPEDEFS
+ **********************/
+
+/**********************
+ * GLOBAL PROTOTYPES
+ **********************/
+void lv_example_get_started_1(void);
+void lv_example_get_started_2(void);
+void lv_example_get_started_3(void);
+
+/**********************
+ * MACROS
+ **********************/
+
+#ifdef __cplusplus
+} /*extern "C"*/
+#endif
+
+#endif /*LV_EX_GET_STARTED_H*/
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started_1.c b/lib/lvgl/examples/get_started/lv_example_get_started_1.c
new file mode 100644
index 00000000..c63e94d0
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started_1.c
@@ -0,0 +1,34 @@
+#include "../lv_examples.h"
+#if LV_BUILD_EXAMPLES && LV_USE_BTN
+
+static void btn_event_cb(lv_event_t * e)
+{
+ lv_event_code_t code = lv_event_get_code(e);
+ lv_obj_t * btn = lv_event_get_target(e);
+ if(code == LV_EVENT_CLICKED) {
+ static uint8_t cnt = 0;
+ cnt++;
+
+ /*Get the first child of the button which is the label and change its text*/
+ lv_obj_t * label = lv_obj_get_child(btn, 0);
+ lv_label_set_text_fmt(label, "Button: %d", cnt);
+ }
+}
+
+/**
+ * Create a button with a label and react on click event.
+ */
+void lv_example_get_started_1(void)
+{
+ lv_obj_t * btn = lv_btn_create(lv_scr_act()); /*Add a button the current screen*/
+ lv_obj_set_pos(btn, 10, 10); /*Set its position*/
+ lv_obj_set_size(btn, 120, 50); /*Set its size*/
+ lv_obj_add_event_cb(btn, btn_event_cb, LV_EVENT_ALL, NULL); /*Assign a callback to the button*/
+
+ lv_obj_t * label = lv_label_create(btn); /*Add a label to the button*/
+ lv_label_set_text(label, "Button"); /*Set the labels text*/
+ lv_obj_center(label);
+}
+
+#endif
+
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started_1.py b/lib/lvgl/examples/get_started/lv_example_get_started_1.py
new file mode 100644
index 00000000..8adfbdd0
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started_1.py
@@ -0,0 +1,29 @@
+class CounterBtn():
+ def __init__(self):
+ self.cnt = 0
+ #
+ # Create a button with a label and react on click event.
+ #
+
+ btn = lv.btn(lv.scr_act()) # Add a button the current screen
+ btn.set_pos(10, 10) # Set its position
+ btn.set_size(120, 50) # Set its size
+ btn.align(lv.ALIGN.CENTER,0,0)
+ btn.add_event_cb(self.btn_event_cb, lv.EVENT.ALL, None) # Assign a callback to the button
+ label = lv.label(btn) # Add a label to the button
+ label.set_text("Button") # Set the labels text
+ label.center()
+
+ def btn_event_cb(self,evt):
+ code = evt.get_code()
+ btn = evt.get_target()
+ if code == lv.EVENT.CLICKED:
+ self.cnt += 1
+
+ # Get the first child of the button which is the label and change its text
+ label = btn.get_child(0)
+ label.set_text("Button: " + str(self.cnt))
+
+
+counterBtn = CounterBtn()
+
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started_2.c b/lib/lvgl/examples/get_started/lv_example_get_started_2.c
new file mode 100644
index 00000000..66f2cc48
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started_2.c
@@ -0,0 +1,83 @@
+#include "../lv_examples.h"
+#if LV_USE_BTN && LV_BUILD_EXAMPLES
+
+static lv_style_t style_btn;
+static lv_style_t style_btn_pressed;
+static lv_style_t style_btn_red;
+
+static lv_color_t darken(const lv_color_filter_dsc_t * dsc, lv_color_t color, lv_opa_t opa)
+{
+ LV_UNUSED(dsc);
+ return lv_color_darken(color, opa);
+}
+
+static void style_init(void)
+{
+ /*Create a simple button style*/
+ lv_style_init(&style_btn);
+ lv_style_set_radius(&style_btn, 10);
+ lv_style_set_bg_opa(&style_btn, LV_OPA_COVER);
+ lv_style_set_bg_color(&style_btn, lv_palette_lighten(LV_PALETTE_GREY, 3));
+ lv_style_set_bg_grad_color(&style_btn, lv_palette_main(LV_PALETTE_GREY));
+ lv_style_set_bg_grad_dir(&style_btn, LV_GRAD_DIR_VER);
+
+ lv_style_set_border_color(&style_btn, lv_color_black());
+ lv_style_set_border_opa(&style_btn, LV_OPA_20);
+ lv_style_set_border_width(&style_btn, 2);
+
+ lv_style_set_text_color(&style_btn, lv_color_black());
+
+ /*Create a style for the pressed state.
+ *Use a color filter to simply modify all colors in this state*/
+ static lv_color_filter_dsc_t color_filter;
+ lv_color_filter_dsc_init(&color_filter, darken);
+ lv_style_init(&style_btn_pressed);
+ lv_style_set_color_filter_dsc(&style_btn_pressed, &color_filter);
+ lv_style_set_color_filter_opa(&style_btn_pressed, LV_OPA_20);
+
+ /*Create a red style. Change only some colors.*/
+ lv_style_init(&style_btn_red);
+ lv_style_set_bg_color(&style_btn_red, lv_palette_main(LV_PALETTE_RED));
+ lv_style_set_bg_grad_color(&style_btn_red, lv_palette_lighten(LV_PALETTE_RED, 3));
+}
+
+/**
+ * Create styles from scratch for buttons.
+ */
+void lv_example_get_started_2(void)
+{
+ /*Initialize the style*/
+ style_init();
+
+ /*Create a button and use the new styles*/
+ lv_obj_t * btn = lv_btn_create(lv_scr_act());
+ /* Remove the styles coming from the theme
+ * Note that size and position are also stored as style properties
+ * so lv_obj_remove_style_all will remove the set size and position too */
+ lv_obj_remove_style_all(btn);
+ lv_obj_set_pos(btn, 10, 10);
+ lv_obj_set_size(btn, 120, 50);
+ lv_obj_add_style(btn, &style_btn, 0);
+ lv_obj_add_style(btn, &style_btn_pressed, LV_STATE_PRESSED);
+
+ /*Add a label to the button*/
+ lv_obj_t * label = lv_label_create(btn);
+ lv_label_set_text(label, "Button");
+ lv_obj_center(label);
+
+ /*Create another button and use the red style too*/
+ lv_obj_t * btn2 = lv_btn_create(lv_scr_act());
+ lv_obj_remove_style_all(btn2); /*Remove the styles coming from the theme*/
+ lv_obj_set_pos(btn2, 10, 80);
+ lv_obj_set_size(btn2, 120, 50);
+ lv_obj_add_style(btn2, &style_btn, 0);
+ lv_obj_add_style(btn2, &style_btn_red, 0);
+ lv_obj_add_style(btn2, &style_btn_pressed, LV_STATE_PRESSED);
+ lv_obj_set_style_radius(btn2, LV_RADIUS_CIRCLE, 0); /*Add a local style too*/
+
+ label = lv_label_create(btn2);
+ lv_label_set_text(label, "Button 2");
+ lv_obj_center(label);
+}
+
+#endif
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started_2.py b/lib/lvgl/examples/get_started/lv_example_get_started_2.py
new file mode 100644
index 00000000..431ba03e
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started_2.py
@@ -0,0 +1,62 @@
+#
+# Create styles from scratch for buttons.
+#
+style_btn = lv.style_t()
+style_btn_red = lv.style_t()
+style_btn_pressed = lv.style_t()
+
+# Create a simple button style
+style_btn.init()
+style_btn.set_radius(10)
+style_btn.set_bg_opa(lv.OPA.COVER)
+style_btn.set_bg_color(lv.palette_lighten(lv.PALETTE.GREY, 3))
+style_btn.set_bg_grad_color(lv.palette_main(lv.PALETTE.GREY))
+style_btn.set_bg_grad_dir(lv.GRAD_DIR.VER)
+
+# Add a border
+style_btn.set_border_color(lv.color_white())
+style_btn.set_border_opa(lv.OPA._70)
+style_btn.set_border_width(2)
+
+# Set the text style
+style_btn.set_text_color(lv.color_white())
+
+# Create a red style. Change only some colors.
+style_btn_red.init()
+style_btn_red.set_bg_color(lv.palette_main(lv.PALETTE.RED))
+style_btn_red.set_bg_grad_color(lv.palette_lighten(lv.PALETTE.RED, 2))
+
+# Create a style for the pressed state.
+style_btn_pressed.init()
+style_btn_pressed.set_bg_color(lv.palette_main(lv.PALETTE.BLUE))
+style_btn_pressed.set_bg_grad_color(lv.palette_darken(lv.PALETTE.RED, 3))
+
+# Create a button and use the new styles
+btn = lv.btn(lv.scr_act()) # Add a button the current screen
+# Remove the styles coming from the theme
+# Note that size and position are also stored as style properties
+# so lv_obj_remove_style_all will remove the set size and position too
+btn.remove_style_all() # Remove the styles coming from the theme
+btn.set_pos(10, 10) # Set its position
+btn.set_size(120, 50) # Set its size
+btn.add_style(style_btn, 0)
+btn.add_style(style_btn_pressed, lv.STATE.PRESSED)
+
+label = lv.label(btn) # Add a label to the button
+label.set_text("Button") # Set the labels text
+label.center()
+
+# Create another button and use the red style too
+btn2 = lv.btn(lv.scr_act())
+btn2.remove_style_all() # Remove the styles coming from the theme
+btn2.set_pos(10, 80) # Set its position
+btn2.set_size(120, 50) # Set its size
+btn2.add_style(style_btn, 0)
+btn2.add_style(style_btn_red, 0)
+btn2.add_style(style_btn_pressed, lv.STATE.PRESSED)
+btn2.set_style_radius(lv.RADIUS.CIRCLE, 0) # Add a local style
+
+label = lv.label(btn2) # Add a label to the button
+label.set_text("Button 2") # Set the labels text
+label.center()
+
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started_3.c b/lib/lvgl/examples/get_started/lv_example_get_started_3.c
new file mode 100644
index 00000000..2f6d6167
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started_3.c
@@ -0,0 +1,33 @@
+#include "../lv_examples.h"
+#if LV_BUILD_EXAMPLES && LV_USE_SLIDER
+
+static lv_obj_t * label;
+
+static void slider_event_cb(lv_event_t * e)
+{
+ lv_obj_t * slider = lv_event_get_target(e);
+
+ /*Refresh the text*/
+ lv_label_set_text_fmt(label, "%"LV_PRId32, lv_slider_get_value(slider));
+ lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/
+}
+
+/**
+ * Create a slider and write its value on a label.
+ */
+void lv_example_get_started_3(void)
+{
+ /*Create a slider in the center of the display*/
+ lv_obj_t * slider = lv_slider_create(lv_scr_act());
+ lv_obj_set_width(slider, 200); /*Set the width*/
+ lv_obj_center(slider); /*Align to the center of the parent (screen)*/
+ lv_obj_add_event_cb(slider, slider_event_cb, LV_EVENT_VALUE_CHANGED, NULL); /*Assign an event function*/
+
+ /*Create a label above the slider*/
+ label = lv_label_create(lv_scr_act());
+ lv_label_set_text(label, "0");
+ lv_obj_align_to(label, slider, LV_ALIGN_OUT_TOP_MID, 0, -15); /*Align top of the slider*/
+}
+
+#endif
+
diff --git a/lib/lvgl/examples/get_started/lv_example_get_started_3.py b/lib/lvgl/examples/get_started/lv_example_get_started_3.py
new file mode 100644
index 00000000..b41a1c06
--- /dev/null
+++ b/lib/lvgl/examples/get_started/lv_example_get_started_3.py
@@ -0,0 +1,22 @@
+def slider_event_cb(evt):
+ slider = evt.get_target()
+
+ # Refresh the text
+ label.set_text(str(slider.get_value()))
+
+#
+# Create a slider and write its value on a label.
+#
+
+# Create a slider in the center of the display
+slider = lv.slider(lv.scr_act())
+slider.set_width(200) # Set the width
+slider.center() # Align to the center of the parent (screen)
+slider.add_event_cb(slider_event_cb, lv.EVENT.VALUE_CHANGED, None) # Assign an event function
+
+# Create a label above the slider
+label = lv.label(lv.scr_act())
+label.set_text("0")
+label.align_to(slider, lv.ALIGN.OUT_TOP_MID, 0, -15) # Align below the slider
+
+