/**************************************************************************** * apps/examples/lvgldemo/lv_test_theme_1.c * * Copyright (C) 2019 Gábor Kiss-Vámosi. All rights reserved. * Author: Gábor Kiss-Vámosi * * Released under the following BSD-compatible MIT license: * * Permission is hereby granted, free of charge, to any person * obtaining a copy of this software and associated documentation * files (the “Software”), to deal in the Software without * restriction, including without limitation the rights to use, * copy, modify, merge, publish, distribute, sublicense, and/or * sell copies of the Software, and to permit persons to whom * the Software is furnished to do so, subject to the following * conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE * WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************/ /**************************************************************************** * Included Files ****************************************************************************/ #include #include "lv_test_theme_1.h" #ifdef CONFIG_EXAMPLES_LVGLDEMO_THEME_1 /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ /**************************************************************************** * Private Types ****************************************************************************/ /**************************************************************************** * Private Function Prototypes ****************************************************************************/ static void create_tab1(FAR lv_obj_t *parent); static void create_tab2(FAR lv_obj_t *parent); static void create_tab3(FAR lv_obj_t *parent); /**************************************************************************** * Private Data ****************************************************************************/ /**************************************************************************** * Public Data ****************************************************************************/ /**************************************************************************** * Private Functions ****************************************************************************/ /**************************************************************************** * Name: create_tab1 * * Description: * Create a tab with a pile of different widgets/controls/objects * * Input Parameters: * parent - a page container object to contain the view * * Returned Value: * None * * Assumptions/Limitations: * ****************************************************************************/ static void create_tab1(lv_obj_t * parent) { lv_page_set_scrl_layout(parent, LV_LAYOUT_PRETTY); lv_theme_t * th = lv_theme_get_current(); static lv_style_t h_style; lv_style_copy(&h_style, &lv_style_transp); h_style.body.padding.inner = LV_DPI / 10; h_style.body.padding.left = LV_DPI / 4; h_style.body.padding.right = LV_DPI / 4; h_style.body.padding.top = LV_DPI / 10; h_style.body.padding.bottom = LV_DPI / 10; lv_obj_t * h = lv_cont_create(parent, NULL); lv_obj_set_style(h, &h_style); lv_obj_set_click(h, false); lv_cont_set_fit(h, LV_FIT_TIGHT); lv_cont_set_layout(h, LV_LAYOUT_COL_M); lv_obj_t * btn = lv_btn_create(h, NULL); lv_btn_set_fit(btn, LV_FIT_TIGHT); lv_btn_set_toggle(btn, true); lv_obj_t * btn_label = lv_label_create(btn, NULL); lv_label_set_text(btn_label, "Button"); btn = lv_btn_create(h, btn); lv_btn_toggle(btn); btn_label = lv_label_create(btn, NULL); lv_label_set_text(btn_label, "Toggled"); btn = lv_btn_create(h, btn); lv_btn_set_state(btn, LV_BTN_STATE_INA); btn_label = lv_label_create(btn, NULL); lv_label_set_text(btn_label, "Inactive"); lv_obj_t * label = lv_label_create(h, NULL); lv_label_set_text(label, "Primary"); lv_obj_set_style(label, th->style.label.prim); label = lv_label_create(h, NULL); lv_label_set_text(label, "Secondary"); lv_obj_set_style(label, th->style.label.sec); label = lv_label_create(h, NULL); lv_label_set_text(label, "Hint"); lv_obj_set_style(label, th->style.label.hint); static const char * btnm_str[] = { "1", "2", "3", LV_SYMBOL_OK, LV_SYMBOL_CLOSE, "" }; lv_obj_t * btnm = lv_btnm_create(h, NULL); lv_obj_set_size(btnm, lv_disp_get_hor_res(NULL) / 4, 2 * LV_DPI / 3); lv_btnm_set_map(btnm, btnm_str); lv_btnm_set_btn_ctrl_all(btnm, LV_BTNM_CTRL_TGL_ENABLE); lv_btnm_set_one_toggle(btnm, true); lv_obj_t * table = lv_table_create(h, NULL); lv_table_set_col_cnt(table, 3); lv_table_set_row_cnt(table, 4); lv_table_set_col_width(table, 0, LV_DPI / 3); lv_table_set_col_width(table, 1, LV_DPI / 2); lv_table_set_col_width(table, 2, LV_DPI / 2); lv_table_set_cell_merge_right(table, 0, 0, true); lv_table_set_cell_merge_right(table, 0, 1, true); lv_table_set_cell_value(table, 0, 0, "Table"); lv_table_set_cell_align(table, 0, 0, LV_LABEL_ALIGN_CENTER); lv_table_set_cell_value(table, 1, 0, "1"); lv_table_set_cell_value(table, 1, 1, "13"); lv_table_set_cell_align(table, 1, 1, LV_LABEL_ALIGN_RIGHT); lv_table_set_cell_value(table, 1, 2, "ms"); lv_table_set_cell_value(table, 2, 0, "2"); lv_table_set_cell_value(table, 2, 1, "46"); lv_table_set_cell_align(table, 2, 1, LV_LABEL_ALIGN_RIGHT); lv_table_set_cell_value(table, 2, 2, "ms"); lv_table_set_cell_value(table, 3, 0, "3"); lv_table_set_cell_value(table, 3, 1, "61"); lv_table_set_cell_align(table, 3, 1, LV_LABEL_ALIGN_RIGHT); lv_table_set_cell_value(table, 3, 2, "ms"); h = lv_cont_create(parent, h); lv_obj_t * sw_h = lv_cont_create(h, NULL); lv_cont_set_style(sw_h, LV_CONT_STYLE_MAIN, &lv_style_transp); lv_cont_set_fit2(sw_h, LV_FIT_NONE, LV_FIT_TIGHT); lv_obj_set_width(sw_h, LV_HOR_RES / 4); lv_cont_set_layout(sw_h, LV_LAYOUT_PRETTY); lv_obj_t * sw = lv_sw_create(sw_h, NULL); lv_sw_set_anim_time(sw, 250); sw = lv_sw_create(sw_h, sw); lv_sw_on(sw, LV_ANIM_OFF); lv_obj_t * bar = lv_bar_create(h, NULL); lv_bar_set_value(bar, 70, false); lv_obj_t * slider = lv_slider_create(h, NULL); lv_bar_set_value(slider, 70, false); lv_obj_t * line = lv_line_create(h, NULL); static lv_point_t line_p[2]; line_p[0].x = 0; line_p[0].y = 0; line_p[1].x = lv_disp_get_hor_res(NULL) / 5; line_p[1].y = 0; lv_line_set_points(line, line_p, 2); lv_line_set_style(line, LV_LINE_STYLE_MAIN, th->style.line.decor); lv_obj_t * cb = lv_cb_create(h, NULL); cb = lv_cb_create(h, cb); lv_btn_set_state(cb, LV_BTN_STATE_TGL_REL); lv_obj_t * ddlist = lv_ddlist_create(h, NULL); lv_ddlist_set_fix_width(ddlist, lv_obj_get_width(ddlist) + LV_DPI / 2); lv_ddlist_set_draw_arrow(ddlist, true); h = lv_cont_create(parent, h); lv_obj_t * list = lv_list_create(h, NULL); lv_obj_set_size(list, lv_disp_get_hor_res(NULL) / 4, lv_disp_get_ver_res(NULL) / 2); lv_obj_t * list_btn; list_btn = lv_list_add_btn(list, LV_SYMBOL_GPS, "GPS"); lv_btn_set_toggle(list_btn, true); lv_list_add_btn(list, LV_SYMBOL_WIFI, "WiFi"); lv_list_add_btn(list, LV_SYMBOL_GPS, "GPS"); lv_list_add_btn(list, LV_SYMBOL_AUDIO, "Audio"); lv_list_add_btn(list, LV_SYMBOL_VIDEO, "Video"); lv_list_add_btn(list, LV_SYMBOL_CALL, "Call"); lv_list_add_btn(list, LV_SYMBOL_BELL, "Bell"); lv_list_add_btn(list, LV_SYMBOL_FILE, "File"); lv_list_add_btn(list, LV_SYMBOL_EDIT, "Edit"); lv_list_add_btn(list, LV_SYMBOL_CUT, "Cut"); lv_list_add_btn(list, LV_SYMBOL_COPY, "Copy"); lv_obj_t * roller = lv_roller_create(h, NULL); lv_roller_set_options(roller, "Monday\n" "Tuesday\n" "Wednesday\n" "Thursday\n" "Friday\n" "Saturday\n" "Sunday", true); lv_roller_set_selected(roller, 1, false); lv_roller_set_visible_row_count(roller, 3); } /**************************************************************************** * Name: create_tab2 * * Description: * Create a tab with a pile of different widgets/controls/objects * * Input Parameters: * parent - a page container object to contain the view * * Returned Value: * None * * Assumptions/Limitations: * ****************************************************************************/ static void create_tab2(lv_obj_t * parent) { lv_coord_t w = lv_page_get_scrl_width(parent); lv_obj_t * chart = lv_chart_create(parent, NULL); lv_chart_set_type(chart, LV_CHART_TYPE_AREA); lv_obj_set_size(chart, w / 3, lv_disp_get_ver_res(NULL) / 3); lv_obj_set_pos(chart, LV_DPI / 10, LV_DPI / 10); lv_chart_series_t * s1 = lv_chart_add_series(chart, LV_COLOR_RED); lv_chart_set_next(chart, s1, 30); lv_chart_set_next(chart, s1, 20); lv_chart_set_next(chart, s1, 10); lv_chart_set_next(chart, s1, 12); lv_chart_set_next(chart, s1, 20); lv_chart_set_next(chart, s1, 27); lv_chart_set_next(chart, s1, 35); lv_chart_set_next(chart, s1, 55); lv_chart_set_next(chart, s1, 70); lv_chart_set_next(chart, s1, 75); lv_obj_t * gauge = lv_gauge_create(parent, NULL); lv_gauge_set_value(gauge, 0, 40); lv_obj_set_size(gauge, w / 4, w / 4); lv_obj_align(gauge, chart, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 4); lv_obj_t * arc = lv_arc_create(parent, NULL); lv_obj_align(arc, gauge, LV_ALIGN_OUT_BOTTOM_MID, 0, LV_DPI / 8); lv_obj_t * ta = lv_ta_create(parent, NULL); lv_obj_set_size(ta, w / 3, lv_disp_get_ver_res(NULL) / 4); lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_RIGHT, -LV_DPI / 10, LV_DPI / 10); lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK); lv_obj_t * kb = lv_kb_create(parent, NULL); lv_obj_set_size(kb, 2 * w / 3, lv_disp_get_ver_res(NULL) / 3); lv_obj_align(kb, ta, LV_ALIGN_OUT_BOTTOM_RIGHT, 0, LV_DPI); lv_kb_set_ta(kb, ta); #if LV_USE_ANIMATION lv_obj_t * loader = lv_preload_create(parent, NULL); lv_obj_align(loader, NULL, LV_ALIGN_CENTER, 0, - LV_DPI); #endif } /**************************************************************************** * Name: create_tab3 * * Description: * Create a tab with a pile of different widgets/controls/objects * * Input Parameters: * parent - a page container object to contain the view * * Returned Value: * None * * Assumptions/Limitations: * ****************************************************************************/ static void create_tab3(lv_obj_t *parent) { /* Create a Window */ lv_obj_t *win = lv_win_create(parent, NULL); lv_obj_t *win_btn = lv_win_add_btn(win, LV_SYMBOL_CLOSE); lv_obj_set_event_cb(win_btn, lv_win_close_event_cb); lv_win_add_btn(win, LV_SYMBOL_DOWN); lv_obj_set_size(win, lv_disp_get_hor_res(NULL) / 2, lv_disp_get_ver_res(NULL) / 2); lv_obj_set_pos(win, LV_DPI / 20, LV_DPI / 20); lv_obj_set_top(win, true); /* Create a Label in the Window */ lv_obj_t *label = lv_label_create(win, NULL); lv_label_set_text(label, "Label in the window"); /* Create a Line meter in the Window */ lv_obj_t *lmeter = lv_lmeter_create(win, NULL); lv_obj_align(lmeter, label, LV_ALIGN_OUT_BOTTOM_LEFT, 0, LV_DPI / 2); lv_lmeter_set_value(lmeter, 70); /* Create a 2 LEDs in the Window */ lv_obj_t *led1 = lv_led_create(win, NULL); lv_obj_align(led1, lmeter, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0); lv_led_on(led1); lv_obj_t *led2 = lv_led_create(win, NULL); lv_obj_align(led2, led1, LV_ALIGN_OUT_RIGHT_MID, LV_DPI / 2, 0); lv_led_off(led2); /* Create a Page */ lv_obj_t *page = lv_page_create(parent, NULL); lv_obj_set_size(page, lv_disp_get_hor_res(NULL) / 3, lv_disp_get_ver_res(NULL) / 2); lv_obj_set_top(page, true); lv_obj_align(page, win, LV_ALIGN_IN_TOP_RIGHT, LV_DPI, LV_DPI); label = lv_label_create(page, NULL); lv_label_set_text(label, "Lorem ipsum dolor sit amet, " "repudiare voluptatibus pri cu.\n" "Ei mundi pertinax posidonium eum," " cum tempor maiorum at,\n" "mea fuisset assentior ad. " "Usu cu suas civibus iudicabit.\n" "Eum eu congue tempor facilisi. " "Tale hinc unum te vim.\n" "Te cum populo animal eruditi," "labitur inciderint at nec.\n\n" "Eius corpora et quo. Everti" "voluptaria instructior est id,\n" "vel in falli primis." "Mea ei porro essent admodum,\n" "his ei malis quodsi, te quis aeterno his.\n" "Qui tritani recusabo reprehendunt ne,\n" "per duis explicari at." " Simul mediocritatem mei et."); /* Create a Calendar */ lv_obj_t *cal = lv_calendar_create(parent, NULL); lv_obj_set_size(cal, 5 * LV_DPI / 2, 5 * LV_DPI / 2); lv_obj_align(cal, page, LV_ALIGN_OUT_RIGHT_TOP, -LV_DPI / 2, LV_DPI / 3); lv_obj_set_top(cal, true); static lv_calendar_date_t highlighted_days[2]; highlighted_days[0].day = 5; highlighted_days[0].month = 5; highlighted_days[0].year = 2018; highlighted_days[1].day = 8; highlighted_days[1].month = 5; highlighted_days[1].year = 2018; lv_calendar_set_highlighted_dates(cal, highlighted_days, 2); lv_calendar_set_today_date(cal, &highlighted_days[0]); lv_calendar_set_showed_date(cal, &highlighted_days[0]); /* Create a Message box */ static const char *mbox_btn_map[] = { " ", "Got it!", " ", "" }; lv_obj_t *mbox = lv_mbox_create(parent, NULL); lv_mbox_set_text(mbox, "Click on the window or the page" " to bring it to the foreground"); lv_mbox_add_btns(mbox, mbox_btn_map); lv_btnm_set_btn_ctrl(lv_mbox_get_btnm(mbox), 0, LV_BTNM_CTRL_HIDDEN); lv_btnm_set_btn_width(lv_mbox_get_btnm(mbox), 1, 7); lv_btnm_set_btn_ctrl(lv_mbox_get_btnm(mbox), 2, LV_BTNM_CTRL_HIDDEN); lv_obj_set_top(mbox, true); } /**************************************************************************** * Public Functions ****************************************************************************/ /**************************************************************************** * Name: lv_test_theme_1 * * Description: * Create a test screen with a lot objects and apply * the given theme on them * * Input Parameters: * th - pointer to a theme * * Returned Value: * None * * Assumptions/Limitations: * * ****************************************************************************/ void lv_test_theme_1(lv_theme_t * th) { lv_theme_set_current(th); /* If `LV_THEME_LIVE_UPDATE 1` `th` is not used directly * so get the real theme after set */ th = lv_theme_get_current(); FAR lv_obj_t * scr = lv_cont_create(NULL, NULL); lv_disp_load_scr(scr); FAR lv_obj_t * tv = lv_tabview_create(scr, NULL); lv_obj_set_size(tv, lv_disp_get_hor_res(NULL), lv_disp_get_ver_res(NULL)); FAR lv_obj_t * tab1 = lv_tabview_add_tab(tv, "Tab 1"); FAR lv_obj_t * tab2 = lv_tabview_add_tab(tv, "Tab 2"); FAR lv_obj_t * tab3 = lv_tabview_add_tab(tv, "Tab 3"); create_tab1(tab1); create_tab2(tab2); create_tab3(tab3); } #endif /* CONFIG_EXAMPLES_LVGLDEMO_THEME_1 */