You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ac...@apache.org on 2020/04/15 14:38:40 UTC
[incubator-nuttx-apps] 08/15: apps/examples/lvgldemo: Port new
simple demo from LVGL V6.1.2
This is an automated email from the ASF dual-hosted git repository.
acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 13606dc253fce671519e267d5765565a412e093c
Author: Qi Huang <hu...@xiaomi.com>
AuthorDate: Tue Apr 7 01:37:14 2020 +0000
apps/examples/lvgldemo: Port new simple demo from LVGL V6.1.2
Signed-off-by: Qi Huang <hu...@xiaomi.com>
Change-Id: I1051edc15b6f66ce34d2f813964e0e8630ec351f
---
examples/lvgldemo/demo.c | 529 ++++++++++++++++++++++++++---------------------
1 file changed, 293 insertions(+), 236 deletions(-)
diff --git a/examples/lvgldemo/demo.c b/examples/lvgldemo/demo.c
index 5b3e189..b7d3723 100644
--- a/examples/lvgldemo/demo.c
+++ b/examples/lvgldemo/demo.c
@@ -52,16 +52,17 @@
****************************************************************************/
static void write_create(lv_obj_t *parent);
-static lv_res_t keyboard_open_close(lv_obj_t *ta);
-static lv_res_t keyboard_hide_action(lv_obj_t *keyboard);
-static void kb_hide_anim_end(lv_obj_t *keyboard);
+static void text_area_event_handler(lv_obj_t *text_area, lv_event_t event);
+static void keyboard_event_cb(lv_obj_t *keyboard, lv_event_t event);
+#if LV_USE_ANIMATION
+static void kb_hide_anim_end(lv_anim_t *a);
+#endif
static void list_create(lv_obj_t *parent);
static void chart_create(lv_obj_t *parent);
-static lv_res_t slider_action(lv_obj_t *slider);
-static lv_res_t list_btn_action(lv_obj_t *slider);
-
+static void slider_event_handler(lv_obj_t *slider, lv_event_t event);
+static void list_btn_event_handler(lv_obj_t *slider, lv_event_t event);
#if LV_DEMO_SLIDE_SHOW
-static void tab_switcher(void *tv);
+static void tab_switcher(lv_task_t *task);
#endif
/****************************************************************************
@@ -72,12 +73,18 @@ FAR static lv_obj_t *chart;
FAR static lv_obj_t *ta;
FAR static lv_obj_t *kb;
+static const char *mbox_btns[] =
+{
+ "Got it",
+ ""
+};
+
static lv_style_t style_kb;
static lv_style_t style_kb_rel;
static lv_style_t style_kb_pr;
#if LV_DEMO_WALLPAPER
-LV_IMG_DECLARE(img_bubble_pattern);
+LV_IMG_DECLARE(img_bubble_pattern)
#endif
/****************************************************************************
@@ -89,14 +96,13 @@ LV_IMG_DECLARE(img_bubble_pattern);
****************************************************************************/
/****************************************************************************
- * Name: write_create
+ * Name: kb_hide_anim_end
*
* Description:
- * Create a text-area and keyboard, each composing half of the
- * parent container.
+ * Process the evnet of anim
*
* Input Parameters:
- * parent - the lv_page_t* container to create the "write" page within
+ * a - the handler of anim
*
* Returned Value:
* none
@@ -106,109 +112,190 @@ LV_IMG_DECLARE(img_bubble_pattern);
*
****************************************************************************/
-static void write_create(lv_obj_t *parent)
+#if LV_USE_ANIMATION
+static void kb_hide_anim_end(lv_anim_t *a)
{
- static lv_style_t style_ta;
-
- lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit);
- lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit);
-
- lv_page_set_sb_mode(parent, LV_SB_MODE_OFF);
-
- lv_style_copy(&style_ta, &lv_style_pretty);
- style_ta.body.opa = LV_OPA_30;
- style_ta.body.radius = 0;
- style_ta.text.color = LV_COLOR_HEX3(0x222);
+ lv_obj_del(a->var);
+ kb = NULL;
+}
+#endif
- ta = lv_ta_create(parent, NULL);
- lv_obj_set_size(ta, lv_page_get_scrl_width(parent),
- lv_obj_get_height(parent) / 2);
- lv_ta_set_style(ta, LV_TA_STYLE_BG, &style_ta);
- lv_ta_set_text(ta, "");
- lv_page_set_rel_action(ta, keyboard_open_close);
+/****************************************************************************
+ * Name: text_area_event_handler
+ *
+ * Description:
+ * Process the evnet of text area
+ *
+ * Input Parameters:
+ * text_area - the handler of text area controller
+ * event - event type
+ *
+ * Returned Value:
+ * none
+ *
+ * Assumptions/Limitations:
+ *
+ *
+ ****************************************************************************/
- lv_style_copy(&style_kb, &lv_style_plain);
- style_kb.body.opa = LV_OPA_70;
- style_kb.body.main_color = LV_COLOR_HEX3(0x333);
- style_kb.body.grad_color = LV_COLOR_HEX3(0x333);
- style_kb.body.padding.hor = 0;
- style_kb.body.padding.ver = 0;
- style_kb.body.padding.inner = 0;
+static void text_area_event_handler(lv_obj_t *text_area, lv_event_t event)
+{
+ (void)text_area;
- lv_style_copy(&style_kb_rel, &lv_style_plain);
- style_kb_rel.body.empty = 1;
- style_kb_rel.body.radius = 0;
- style_kb_rel.body.border.width = 1;
- style_kb_rel.body.border.color = LV_COLOR_SILVER;
- style_kb_rel.body.border.opa = LV_OPA_50;
- style_kb_rel.body.main_color = LV_COLOR_HEX3(0x333);
- style_kb_rel.body.grad_color = LV_COLOR_HEX3(0x333);
- style_kb_rel.text.color = LV_COLOR_WHITE;
+ /* Text area is on the scrollable part of the page but we need the page itself */
- lv_style_copy(&style_kb_pr, &lv_style_plain);
- style_kb_pr.body.radius = 0;
- style_kb_pr.body.opa = LV_OPA_50;
- style_kb_pr.body.main_color = LV_COLOR_WHITE;
- style_kb_pr.body.grad_color = LV_COLOR_WHITE;
- style_kb_pr.body.border.width = 1;
- style_kb_pr.body.border.color = LV_COLOR_SILVER;
+ lv_obj_t *parent = lv_obj_get_parent(lv_obj_get_parent(ta));
- keyboard_open_close(ta);
+ if (event == LV_EVENT_CLICKED)
+ {
+ if (kb == NULL)
+ {
+ kb = lv_kb_create(parent, NULL);
+ lv_obj_set_size(kb,
+ lv_obj_get_width_fit(parent),
+ lv_obj_get_height_fit(parent) / 2);
+ lv_obj_align(kb, ta, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
+ lv_kb_set_ta(kb, ta);
+ lv_kb_set_style(kb, LV_KB_STYLE_BG, &style_kb);
+ lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &style_kb_rel);
+ lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &style_kb_pr);
+ lv_obj_set_event_cb(kb, keyboard_event_cb);
+
+#if LV_USE_ANIMATION
+ lv_anim_t a;
+ a.var = kb;
+ a.start = LV_VER_RES;
+ a.end = lv_obj_get_y(kb);
+ a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_y;
+ a.path_cb = lv_anim_path_linear;
+ a.ready_cb = NULL;
+ a.act_time = 0;
+ a.time = 300;
+ a.playback = 0;
+ a.playback_pause = 0;
+ a.repeat = 0;
+ a.repeat_pause = 0;
+ lv_anim_create(&a);
+#endif
+ }
+ }
}
/****************************************************************************
- * Name: keyboard_open_close
+ * Name: keyboard_event_cb
*
* Description:
- * Toggle the display of the keyboard on the "Write" tab
+ * Process the evnet of keyboard
*
* Input Parameters:
- * text_area - a pointer to the lv_obj_t text area for the keyboard
+ * keyboard - the handler of keyboard controller
+ * event - event type
*
* Returned Value:
- * LV_RES_OK on success, some other LV_RES_ value otherwise.
+ * none
*
* Assumptions/Limitations:
*
*
****************************************************************************/
-static lv_res_t keyboard_open_close(lv_obj_t *text_area)
+static void keyboard_event_cb(lv_obj_t *keyboard, lv_event_t event)
{
- lv_obj_t *parent;
+ (void)keyboard;
- /* Text area is on the scrollable part of the page but we need
- * the page itself
- */
+ lv_kb_def_event_cb(kb, event);
- parent = lv_obj_get_parent(lv_obj_get_parent(ta));
-
- if (kb)
+ if (event == LV_EVENT_APPLY || event == LV_EVENT_CANCEL)
{
- return keyboard_hide_action(kb);
+#if LV_USE_ANIMATION
+ lv_anim_t a;
+ a.var = kb;
+ a.start = lv_obj_get_y(kb);
+ a.end = LV_VER_RES;
+ a.exec_cb = (lv_anim_exec_xcb_t)lv_obj_set_y;
+ a.path_cb = lv_anim_path_linear;
+ a.ready_cb = kb_hide_anim_end;
+ a.act_time = 0;
+ a.time = 300;
+ a.playback = 0;
+ a.playback_pause = 0;
+ a.repeat = 0;
+ a.repeat_pause = 0;
+ lv_anim_create(&a);
+#else
+ lv_obj_del(kb);
+ kb = NULL;
+#endif
}
- else
- {
- kb = lv_kb_create(parent, NULL);
+}
- lv_obj_set_size(kb, lv_page_get_scrl_width(parent),
- lv_obj_get_height(parent) / 2);
- lv_obj_align(kb, ta, LV_ALIGN_OUT_BOTTOM_MID, 0, 0);
+/****************************************************************************
+ * Name: write_create
+ *
+ * Description:
+ * Create a text-area and keyboard, each composing half of the
+ * parent container.
+ *
+ * Input Parameters:
+ * parent - the lv_page_t* container to create the "write" page within
+ *
+ * Returned Value:
+ * none
+ *
+ * Assumptions/Limitations:
+ *
+ *
+ ****************************************************************************/
- lv_kb_set_ta(kb, ta);
+static void write_create(lv_obj_t *parent)
+{
+ lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit);
+ lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit);
- lv_kb_set_style(kb, LV_KB_STYLE_BG, &style_kb);
- lv_kb_set_style(kb, LV_KB_STYLE_BTN_REL, &style_kb_rel);
- lv_kb_set_style(kb, LV_KB_STYLE_BTN_PR, &style_kb_pr);
+ lv_page_set_sb_mode(parent, LV_SB_MODE_OFF);
- lv_kb_set_hide_action(kb, keyboard_hide_action);
- lv_kb_set_ok_action(kb, keyboard_hide_action);
+ static lv_style_t style_ta;
+ lv_style_copy(&style_ta, &lv_style_pretty);
+ style_ta.body.opa = LV_OPA_30;
+ style_ta.body.radius = 0;
+ style_ta.text.color = lv_color_hex3(0x222);
-#if USE_LV_ANIMATION
- lv_obj_animate(kb, LV_ANIM_FLOAT_BOTTOM | LV_ANIM_IN, 300, 0, NULL);
-#endif
- return LV_RES_OK;
- }
+ ta = lv_ta_create(parent, NULL);
+ lv_obj_set_size(ta,
+ lv_page_get_scrl_width(parent),
+ lv_obj_get_height(parent) / 2);
+ lv_ta_set_style(ta, LV_TA_STYLE_BG, &style_ta);
+ lv_ta_set_text(ta, "");
+ lv_obj_set_event_cb(ta, text_area_event_handler);
+ lv_style_copy(&style_kb, &lv_style_plain);
+ lv_ta_set_text_sel(ta, true);
+
+ style_kb.body.opa = LV_OPA_70;
+ style_kb.body.main_color = lv_color_hex3(0x333);
+ style_kb.body.grad_color = lv_color_hex3(0x333);
+ style_kb.body.padding.left = 0;
+ style_kb.body.padding.right = 0;
+ style_kb.body.padding.top = 0;
+ style_kb.body.padding.bottom = 0;
+ style_kb.body.padding.inner = 0;
+
+ lv_style_copy(&style_kb_rel, &lv_style_plain);
+ style_kb_rel.body.opa = LV_OPA_TRANSP;
+ style_kb_rel.body.radius = 0;
+ style_kb_rel.body.border.width = 1;
+ style_kb_rel.body.border.color = LV_COLOR_SILVER;
+ style_kb_rel.body.border.opa = LV_OPA_50;
+ style_kb_rel.body.main_color = lv_color_hex3(0x333);
+ style_kb_rel.body.grad_color = lv_color_hex3(0x333);
+ style_kb_rel.text.color = LV_COLOR_WHITE;
+
+ lv_style_copy(&style_kb_pr, &lv_style_plain);
+ style_kb_pr.body.radius = 0;
+ style_kb_pr.body.opa = LV_OPA_50;
+ style_kb_pr.body.main_color = LV_COLOR_WHITE;
+ style_kb_pr.body.grad_color = LV_COLOR_WHITE;
+ style_kb_pr.body.border.width = 1;
+ style_kb_pr.body.border.color = LV_COLOR_SILVER;
}
/****************************************************************************
@@ -246,28 +333,6 @@ static lv_res_t keyboard_hide_action(lv_obj_t *keyboard)
}
/****************************************************************************
- * Name: kb_hide_anim_end
- *
- * Description:
- * A callback to delete (free) the object passed as a parameter.
- *
- * Input Parameters:
- * keyboard - An lv_obj_t * to be deleted.
- *
- * Returned Value:
- * None
- *
- * Assumptions/Limitations:
- *
- *
- ****************************************************************************/
-
-static void kb_hide_anim_end(lv_obj_t *keyboard)
-{
- lv_obj_del(keyboard);
-}
-
-/****************************************************************************
* Name: list_create
*
* Description:
@@ -287,65 +352,66 @@ static void kb_hide_anim_end(lv_obj_t *keyboard)
static void list_create(lv_obj_t *parent)
{
- static lv_style_t style_btn_rel;
- static lv_style_t style_btn_pr;
-
- FAR lv_obj_t *list;
- FAR lv_obj_t *mbox;
-
- FAR static const char *mbox_btns[] = {
- "Got it", ""
- };
+ lv_coord_t hres = lv_disp_get_hor_res(NULL);
lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit);
lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit);
- lv_page_set_scrl_fit(parent, false, false);
- lv_page_set_scrl_height(parent, lv_obj_get_height(parent));
lv_page_set_sb_mode(parent, LV_SB_MODE_OFF);
/* Create styles for the buttons */
+ static lv_style_t style_btn_rel;
+ static lv_style_t style_btn_pr;
lv_style_copy(&style_btn_rel, &lv_style_btn_rel);
- style_btn_rel.body.main_color = LV_COLOR_HEX3(0x333);
- style_btn_rel.body.grad_color = LV_COLOR_BLACK;
- style_btn_rel.body.border.color = LV_COLOR_SILVER;
- style_btn_rel.body.border.width = 1;
- style_btn_rel.body.border.opa = LV_OPA_50;
- style_btn_rel.body.radius = 0;
+ style_btn_rel.body.main_color = lv_color_hex3(0x333);
+ style_btn_rel.body.grad_color = LV_COLOR_BLACK;
+ style_btn_rel.body.border.color = LV_COLOR_SILVER;
+ style_btn_rel.body.border.width = 1;
+ style_btn_rel.body.border.opa = LV_OPA_50;
+ style_btn_rel.body.radius = 0;
lv_style_copy(&style_btn_pr, &style_btn_rel);
- style_btn_pr.body.main_color = LV_COLOR_MAKE(0x55, 0x96, 0xd8);
- style_btn_pr.body.grad_color = LV_COLOR_MAKE(0x37, 0x62, 0x90);
- style_btn_pr.text.color = LV_COLOR_MAKE(0xbb, 0xd5, 0xf1);
-
- list = lv_list_create(parent, NULL);
+ style_btn_pr.body.main_color = lv_color_make(0x55, 0x96, 0xd8);
+ style_btn_pr.body.grad_color = lv_color_make(0x37, 0x62, 0x90);
+ style_btn_pr.text.color = lv_color_make(0xbb, 0xd5, 0xf1);
+ lv_obj_t *list = lv_list_create(parent, NULL);
lv_obj_set_height(list, 2 * lv_obj_get_height(parent) / 3);
-
- lv_list_set_style(list, LV_LIST_STYLE_BG, &lv_style_transp_tight);
- lv_list_set_style(list, LV_LIST_STYLE_SCRL, &lv_style_transp_tight);
+ lv_list_set_style(list, LV_LIST_STYLE_BG, &lv_style_transp_tight);
+ lv_list_set_style(list, LV_LIST_STYLE_SCRL, &lv_style_transp_tight);
lv_list_set_style(list, LV_LIST_STYLE_BTN_REL, &style_btn_rel);
- lv_list_set_style(list, LV_LIST_STYLE_BTN_PR, &style_btn_pr);
-
+ lv_list_set_style(list, LV_LIST_STYLE_BTN_PR, &style_btn_pr);
lv_obj_align(list, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 4);
- lv_list_add(list, SYMBOL_FILE, "New", list_btn_action);
- lv_list_add(list, SYMBOL_DIRECTORY, "Open", list_btn_action);
- lv_list_add(list, SYMBOL_TRASH, "Delete", list_btn_action);
- lv_list_add(list, SYMBOL_EDIT, "Edit", list_btn_action);
- lv_list_add(list, SYMBOL_SAVE, "Save", list_btn_action);
- lv_list_add(list, SYMBOL_WIFI, "WiFi", list_btn_action);
- lv_list_add(list, SYMBOL_GPS, "GPS", list_btn_action);
+ lv_obj_t *list_btn;
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_FILE, "New");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
+
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_DIRECTORY, "Open");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
+
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_TRASH, "Delete");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
+
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_EDIT, "Edit");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
+
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_SAVE, "Save");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
- mbox = lv_mbox_create(parent, NULL);
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_WIFI, "WiFi");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
- lv_mbox_set_text(mbox, "Click a button to copy its text to the Text area ");
- lv_obj_set_width(mbox, LV_HOR_RES - LV_DPI);
+ list_btn = lv_list_add_btn(list, LV_SYMBOL_GPS, "GPS");
+ lv_obj_set_event_cb(list_btn, list_btn_event_handler);
- /* The default action is close */
+ lv_obj_t *mbox = lv_mbox_create(parent, NULL);
+ lv_mbox_set_text(mbox, "Click a button to copy"
+ "its text to the Text area ");
+ lv_obj_set_width(mbox, hres - LV_DPI);
- lv_mbox_add_btns(mbox, mbox_btns, NULL);
+ lv_mbox_add_btns(mbox, mbox_btns);
lv_obj_align(mbox, parent, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 2);
}
@@ -395,37 +461,29 @@ static lv_res_t list_btn_action(lv_obj_t *btn)
static void chart_create(lv_obj_t *parent)
{
- static lv_style_t style_chart;
- static lv_style_t style_bar;
- static lv_style_t style_indic;
- static lv_style_t style_knob;
-
- FAR lv_chart_series_t *ser1;
-
- FAR lv_obj_t *slider;
+ lv_coord_t vres = lv_disp_get_ver_res(NULL);
- lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit);
+ lv_page_set_style(parent, LV_PAGE_STYLE_BG, &lv_style_transp_fit);
lv_page_set_style(parent, LV_PAGE_STYLE_SCRL, &lv_style_transp_fit);
- /* Make the parent a fixed size */
-
- lv_page_set_scrl_fit(parent, false, false);
lv_page_set_scrl_height(parent, lv_obj_get_height(parent));
lv_page_set_sb_mode(parent, LV_SB_MODE_OFF);
+ static lv_style_t style_chart;
lv_style_copy(&style_chart, &lv_style_pretty);
- style_chart.body.opa = LV_OPA_60;
- style_chart.body.radius = 0;
- style_chart.line.color = LV_COLOR_GRAY;
+ style_chart.body.opa = LV_OPA_60;
+ style_chart.body.radius = 0;
+ style_chart.line.color = LV_COLOR_GRAY;
chart = lv_chart_create(parent, NULL);
- lv_obj_set_size(chart, 2 * lv_obj_get_width(parent) / 3,
+ lv_obj_set_size(chart,
+ 2 * lv_obj_get_width(parent) / 3,
lv_obj_get_height(parent) / 2);
- lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 4);
+ lv_obj_align(chart, NULL, LV_ALIGN_IN_TOP_MID, 0, LV_DPI / 4);
lv_chart_set_type(chart, LV_CHART_TYPE_COLUMN);
- lv_chart_set_style(chart, &style_chart);
+ lv_chart_set_style(chart, LV_CHART_STYLE_MAIN, &style_chart);
lv_chart_set_series_opa(chart, LV_OPA_70);
-
+ lv_chart_series_t *ser1;
ser1 = lv_chart_add_series(chart, LV_COLOR_RED);
lv_chart_set_next(chart, ser1, 40);
lv_chart_set_next(chart, ser1, 30);
@@ -440,75 +498,79 @@ static void chart_create(lv_obj_t *parent)
/* Create a bar, an indicator and a knob style */
+ static lv_style_t style_bar;
+ static lv_style_t style_indic;
+ static lv_style_t style_knob;
+
lv_style_copy(&style_bar, &lv_style_pretty);
- style_bar.body.main_color = LV_COLOR_BLACK;
- style_bar.body.grad_color = LV_COLOR_GRAY;
- style_bar.body.radius = LV_RADIUS_CIRCLE;
- style_bar.body.border.color = LV_COLOR_WHITE;
- style_bar.body.opa = LV_OPA_60;
- style_bar.body.padding.hor = 0;
- style_bar.body.padding.ver = LV_DPI / 10;
+ style_bar.body.main_color = LV_COLOR_BLACK;
+ style_bar.body.grad_color = LV_COLOR_GRAY;
+ style_bar.body.radius = LV_RADIUS_CIRCLE;
+ style_bar.body.border.color = LV_COLOR_WHITE;
+ style_bar.body.opa = LV_OPA_60;
+ style_bar.body.padding.left = 0;
+ style_bar.body.padding.right = 0;
+ style_bar.body.padding.top = LV_DPI / 10;
+ style_bar.body.padding.bottom = LV_DPI / 10;
lv_style_copy(&style_indic, &lv_style_pretty);
- style_indic.body.grad_color = LV_COLOR_MAROON;
- style_indic.body.main_color = LV_COLOR_RED;
- style_indic.body.radius = LV_RADIUS_CIRCLE;
+ style_indic.body.grad_color = LV_COLOR_MAROON;
+ style_indic.body.main_color = LV_COLOR_RED;
+ style_indic.body.radius = LV_RADIUS_CIRCLE;
style_indic.body.shadow.width = LV_DPI / 10;
style_indic.body.shadow.color = LV_COLOR_RED;
- style_indic.body.padding.hor = LV_DPI / 30;
- style_indic.body.padding.ver = LV_DPI / 30;
+ style_indic.body.padding.left = LV_DPI / 30;
+ style_indic.body.padding.right = LV_DPI / 30;
+ style_indic.body.padding.top = LV_DPI / 30;
+ style_indic.body.padding.bottom = LV_DPI / 30;
lv_style_copy(&style_knob, &lv_style_pretty);
- style_knob.body.radius = LV_RADIUS_CIRCLE;
- style_knob.body.opa = LV_OPA_70;
+ style_knob.body.radius = LV_RADIUS_CIRCLE;
+ style_knob.body.opa = LV_OPA_70;
- /* Create a second slider, align to bottom of the chart */
-
- slider = lv_slider_create(parent, NULL);
+ /* Create a second slider */
+ lv_obj_t *slider = lv_slider_create(parent, NULL);
lv_slider_set_style(slider, LV_SLIDER_STYLE_BG, &style_bar);
lv_slider_set_style(slider, LV_SLIDER_STYLE_INDIC, &style_indic);
lv_slider_set_style(slider, LV_SLIDER_STYLE_KNOB, &style_knob);
-
lv_obj_set_size(slider, lv_obj_get_width(chart), LV_DPI / 3);
-
- lv_obj_align(slider, chart, LV_ALIGN_OUT_BOTTOM_MID, 0,
- (LV_VER_RES - chart->coords.y2 - lv_obj_get_height(slider)) / 2);
-
- /* Simulate a user value set the refresh the chart */
-
- lv_slider_set_action(slider, slider_action);
+ lv_obj_align(slider,
+ chart,
+ LV_ALIGN_OUT_BOTTOM_MID,
+ 0,
+ (vres - chart->coords.y2 - lv_obj_get_height(slider)) / 2);
+ lv_obj_set_event_cb(slider, slider_event_handler);
lv_slider_set_range(slider, 10, 1000);
- lv_slider_set_value(slider, 700);
-
- slider_action(slider);
+ lv_slider_set_value(slider, 700, false);
+ slider_event_handler(slider, LV_EVENT_VALUE_CHANGED);
}
/****************************************************************************
- * Name: slider_action
+ * Name: slider_event_handler
*
* Description:
* Callback of the slider on the chart page. Adjusts the Y-axis range
*
* Input Parameters:
* slider - the slider object that triggered this action
- *
+ * event - the event type
* Returned Value:
- * LV_RES_OK - the object is still valid
+ * None
*
* Assumptions/Limitations:
* Anything else that one might need to know to use this function.
*
****************************************************************************/
-static lv_res_t slider_action(lv_obj_t *slider)
+static void slider_event_handler(lv_obj_t *slider, lv_event_t event)
{
- int16_t v = lv_slider_get_value(slider);
-
- v = 1000 * 100 / v; /* Convert to range modify values linearly */
- lv_chart_set_range(chart, 0, v);
-
- return LV_RES_OK;
+ if (event == LV_EVENT_VALUE_CHANGED)
+ {
+ int16_t v = lv_slider_get_value(slider);
+ v = 1000 * 100 / v;
+ lv_chart_set_range(chart, 0, v);
+ }
}
#if LV_DEMO_SLIDE_SHOW
@@ -533,18 +595,16 @@ static lv_res_t slider_action(lv_obj_t *slider)
* Called periodically (lv_task) to switch to the next tab
*/
-static void tab_switcher(void *tv)
+static void tab_switcher(lv_task_t *task)
{
static uint8_t tab = 0;
-
+ lv_obj_t *tv = task->user_data;
tab++;
if (tab >= 3)
- {
- tab = 0;
- }
-
+ tab = 0;
lv_tabview_set_tab_act(tv, tab, true);
}
+
#endif
/****************************************************************************
@@ -570,51 +630,48 @@ static void tab_switcher(void *tv)
void demo_create(void)
{
- static lv_style_t style_tv_btn_bg;
- static lv_style_t style_tv_btn_rel;
- static lv_style_t style_tv_btn_pr;
-
- FAR lv_obj_t *tv;
- FAR lv_obj_t *tab1;
- FAR lv_obj_t *tab2;
- FAR lv_obj_t *tab3;
+ lv_coord_t hres = lv_disp_get_hor_res(NULL);
+ lv_coord_t vres = lv_disp_get_ver_res(NULL);
#if LV_DEMO_WALLPAPER
- FAR lv_obj_t *wp;
-
- wp = lv_img_create(lv_scr_act(), NULL);
+ lv_obj_t *wp = lv_img_create(lv_disp_get_scr_act(NULL), NULL);
lv_img_set_src(wp, &img_bubble_pattern);
- lv_obj_set_width(wp, LV_HOR_RES * 4);
+ lv_obj_set_width(wp, hres * 4);
lv_obj_set_protect(wp, LV_PROTECT_POS);
#endif
+ static lv_style_t style_tv_btn_bg;
lv_style_copy(&style_tv_btn_bg, &lv_style_plain);
- style_tv_btn_bg.body.main_color = LV_COLOR_HEX(0x487fb7);
- style_tv_btn_bg.body.grad_color = LV_COLOR_HEX(0x487fb7);
- style_tv_btn_bg.body.padding.ver = 0;
+ style_tv_btn_bg.body.main_color = lv_color_hex(0x487fb7);
+ style_tv_btn_bg.body.grad_color = lv_color_hex(0x487fb7);
+ style_tv_btn_bg.body.padding.top = 0;
+ style_tv_btn_bg.body.padding.bottom = 0;
+ static lv_style_t style_tv_btn_rel;
lv_style_copy(&style_tv_btn_rel, &lv_style_btn_rel);
- style_tv_btn_rel.body.empty = 1;
- style_tv_btn_rel.body.border.width = 0;
+ style_tv_btn_rel.body.opa = LV_OPA_TRANSP;
+ style_tv_btn_rel.body.border.width = 0;
+ static lv_style_t style_tv_btn_pr;
lv_style_copy(&style_tv_btn_pr, &lv_style_btn_pr);
- style_tv_btn_pr.body.radius = 0;
- style_tv_btn_pr.body.opa = LV_OPA_50;
- style_tv_btn_pr.body.main_color = LV_COLOR_WHITE;
- style_tv_btn_pr.body.grad_color = LV_COLOR_WHITE;
+ style_tv_btn_pr.body.radius = 0;
+ style_tv_btn_pr.body.opa = LV_OPA_50;
+ style_tv_btn_pr.body.main_color = LV_COLOR_WHITE;
+ style_tv_btn_pr.body.grad_color = LV_COLOR_WHITE;
style_tv_btn_pr.body.border.width = 0;
- style_tv_btn_pr.text.color = LV_COLOR_GRAY;
+ style_tv_btn_pr.text.color = LV_COLOR_GRAY;
- tv = lv_tabview_create(lv_scr_act(), NULL);
+ lv_obj_t *tv = lv_tabview_create(lv_disp_get_scr_act(NULL), NULL);
+ lv_obj_set_size(tv, hres, vres);
#if LV_DEMO_WALLPAPER
- lv_obj_set_parent(wp, ((lv_tabview_ext_t*)tv->ext_attr)->content);
+ lv_obj_set_parent(wp, ((lv_tabview_ext_t *)tv->ext_attr)->content);
lv_obj_set_pos(wp, 0, -5);
#endif
- tab1 = lv_tabview_add_tab(tv, "Write");
- tab2 = lv_tabview_add_tab(tv, "List");
- tab3 = lv_tabview_add_tab(tv, "Chart");
+ lv_obj_t *tab1 = lv_tabview_add_tab(tv, "Write");
+ lv_obj_t *tab2 = lv_tabview_add_tab(tv, "List");
+ lv_obj_t *tab3 = lv_tabview_add_tab(tv, "Chart");
#if LV_DEMO_WALLPAPER == 0
/* Blue bg instead of wallpaper */
@@ -637,4 +694,4 @@ void demo_create(void)
#endif
}
-#endif /* CONFIG_EXAMPLES_LVGLDEMO_SIMPLE */
+#endif /* CONFIG_EXAMPLES_LVGLDEMO_SIMPLE */
\ No newline at end of file