From 7bec13c2b9b2b624a7c34f71273d6383e6c8202b Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Mon, 8 Feb 2021 09:53:03 +0100 Subject: [PATCH] update asserts --- .../get_started/llv_example_get_started_.h | 40 ++ .../get_started/lv_example_get_started_1.c | 28 + .../get_started/lv_example_get_started_2.c | 83 +++ .../get_started/lv_example_get_started_3.c | 31 ++ examples/layouts/flex/lv_example_flex.h | 37 ++ examples/layouts/flex/lv_example_flex_1.c | 43 ++ examples/layouts/flex/lv_example_flex_2.c | 24 + examples/layouts/flex/lv_example_flex_3.c | 30 + examples/layouts/flex/lv_example_flex_4.c | 24 + examples/layouts/flex/lv_example_flex_5.c | 28 + examples/layouts/flex/lv_example_flex_6.c | 25 + examples/layouts/grid/lv_example_grid.h | 37 ++ examples/layouts/grid/lv_example_grid_1.c | 39 ++ examples/layouts/grid/lv_example_grid_2.c | 59 ++ examples/layouts/grid/lv_example_grid_3.c | 45 ++ examples/layouts/grid/lv_example_grid_4.c | 41 ++ examples/layouts/grid/lv_example_grid_5.c | 41 ++ examples/layouts/grid/lv_example_grid_6.c | 43 ++ examples/styles/lv_example_style.h | 48 ++ examples/styles/lv_example_style_1.c | 28 + examples/styles/lv_example_style_10.c | 35 ++ examples/styles/lv_example_style_11.c | 36 ++ examples/styles/lv_example_style_2.c | 27 + examples/styles/lv_example_style_3.c | 26 + examples/styles/lv_example_style_4.c | 27 + examples/styles/lv_example_style_5.c | 27 + examples/styles/lv_example_style_6.c | 30 + examples/styles/lv_example_style_7.c | 34 ++ examples/styles/lv_example_style_8.c | 24 + examples/styles/lv_example_style_9.c | 35 ++ examples/widgets/arc/lv_example_arc_1.c | 14 + examples/widgets/arc/lv_example_arc_1.py | 12 + examples/widgets/arc/lv_example_arc_2.c | 38 ++ examples/widgets/arc/lv_example_arc_2.py | 43 ++ examples/widgets/bar/lv_example_bar_1.c | 12 + examples/widgets/bar/lv_example_bar_1.py | 5 + examples/widgets/bar/lv_example_bar_3.c | 37 ++ examples/widgets/bar/lv_example_bar_4.c | 27 + examples/widgets/bar/lv_example_bar_5.c | 30 + examples/widgets/bar/lv_example_bar_6.c | 68 +++ examples/widgets/btn/lv_example_btn_1.c | 35 ++ examples/widgets/btn/lv_example_btn_1.py | 21 + examples/widgets/btn/lv_example_btn_2.c | 52 ++ .../btnmatrix/lv_example_btnmatrix_1.c | 31 ++ .../btnmatrix/lv_example_btnmatrix_1.py | 14 + .../btnmatrix/lv_example_btnmatrix_2.c | 71 +++ .../btnmatrix/lv_example_btnmatrix_3.c | 71 +++ .../widgets/calendar/lv_example_calendar_1.c | 55 ++ examples/widgets/canvas/lv_example_canvas_1.c | 53 ++ .../widgets/canvas/lv_example_canvas_1.py | 38 ++ examples/widgets/canvas/lv_example_canvas_2.c | 44 ++ .../widgets/canvas/lv_example_canvas_2.py | 41 ++ examples/widgets/chart/lv_example_chart_1.c | 44 ++ examples/widgets/chart/lv_example_chart_1.py | 19 + examples/widgets/chart/lv_example_chart_2.c | 82 +++ examples/widgets/chart/lv_example_chart_3.c | 75 +++ examples/widgets/chart/lv_example_chart_4.c | 80 +++ .../widgets/checkbox/lv_example_checkbox_1.c | 44 ++ .../widgets/checkbox/lv_example_checkbox_1.py | 8 + .../colorwheel/lv_example_colorwheel_1.c | 13 + .../widgets/dropdown/lv_example_dropdown_1.c | 35 ++ .../widgets/dropdown/lv_example_dropdown_1.py | 21 + .../widgets/dropdown/lv_example_dropdown_2.c | 42 ++ .../widgets/dropdown/lv_example_dropdown_2.py | 23 + .../widgets/dropdown/lv_example_dropdown_3.c | 34 ++ examples/widgets/img/index.rst | 21 + examples/widgets/img/lv_example_img_1.c | 18 + examples/widgets/img/lv_example_img_1.py | 29 + examples/widgets/img/lv_example_img_2.c | 64 +++ examples/widgets/img/lv_example_img_3.c | 33 ++ examples/widgets/img/lv_example_img_4.c | 36 ++ .../widgets/keyboard/lv_example_keyboard_1.c | 37 ++ .../widgets/keyboard/lv_example_keyboard_1.py | 26 + examples/widgets/label/lv_example_label_1.c | 26 + examples/widgets/label/lv_example_label_1.py | 14 + examples/widgets/label/lv_example_label_2.c | 36 ++ examples/widgets/label/lv_example_label_2.py | 24 + examples/widgets/led/lv_example_led_1.c | 22 + examples/widgets/led/lv_example_led_1.py | 27 + examples/widgets/line/lv_example_line_1.c | 24 + examples/widgets/line/lv_example_line_1.py | 19 + examples/widgets/list/lv_example_list_1.c | 34 ++ examples/widgets/list/lv_example_list_1.py | 25 + examples/widgets/lv_example_widgets.h | 77 +++ examples/widgets/meter/lv_example_meter_1.c | 54 ++ examples/widgets/meter/lv_example_meter_2.c | 60 ++ examples/widgets/meter/lv_example_meter_3.c | 55 ++ examples/widgets/meter/lv_example_meter_4.c | 37 ++ examples/widgets/msgbox/lv_example_msgbox_1.c | 26 + .../widgets/msgbox/lv_example_msgbox_1.py | 12 + examples/widgets/msgbox/lv_example_msgbox_2.c | 94 ++++ .../widgets/msgbox/lv_example_msgbox_2.py | 86 +++ examples/widgets/obj/lv_example_obj_1.c | 21 + examples/widgets/obj/lv_example_obj_1.py | 20 + examples/widgets/roller/lv_example_roller_1.c | 40 ++ .../widgets/roller/lv_example_roller_1.py | 24 + examples/widgets/slider/lv_example_slider_1.c | 35 ++ .../widgets/slider/lv_example_slider_1.py | 37 ++ examples/widgets/slider/lv_example_slider_2.c | 43 ++ .../widgets/slider/lv_example_slider_2.py | 23 + examples/widgets/slider/lv_example_slider_3.c | 39 ++ .../widgets/spinbox/lv_example_spinbox_1.c | 47 ++ .../widgets/spinbox/lv_example_spinbox_1.py | 13 + .../widgets/spinner/lv_example_spinner_1.c | 12 + .../widgets/spinner/lv_example_spinner_1.py | 15 + examples/widgets/switch/lv_example_switch_1.c | 40 ++ .../widgets/switch/lv_example_switch_1.py | 48 ++ examples/widgets/table/lv_example_table_1.c | 66 +++ examples/widgets/table/lv_example_table_1.py | 41 ++ .../widgets/tabview/lv_example_tabview_1.c | 41 ++ .../widgets/tabview/lv_example_tabview_1.py | 25 + .../widgets/textarea/lv_example_textarea_1.c | 32 ++ .../widgets/textarea/lv_example_textarea_1.py | 13 + .../widgets/textarea/lv_example_textarea_2.c | 62 +++ .../widgets/textarea/lv_example_textarea_2.py | 51 ++ .../widgets/textarea/lv_example_textarea_3.c | 44 ++ .../widgets/tileview/lv_example_tileview_1.c | 49 ++ .../widgets/tileview/lv_example_tileview_1.py | 62 +++ examples/widgets/win/lv_example_win_1.c | 40 ++ lvgl.h | 6 +- src/extra/layouts/flex/lv_flex.c | 2 +- src/extra/layouts/grid/lv_grid.c | 6 +- src/extra/layouts/lv_layouts.h | 4 +- src/extra/themes/default/lv_theme_default.c | 7 + src/extra/widgets/colorwheel/lv_colorwheel.c | 518 +++++++----------- src/extra/widgets/colorwheel/lv_colorwheel.h | 14 +- src/extra/widgets/imgbtn/lv_imgbtn.c | 6 +- src/extra/widgets/led/lv_led.c | 4 +- src/extra/widgets/lv_widgets.h | 1 + src/extra/widgets/msgbox/lv_msgbox.c | 2 +- src/extra/widgets/spinbox/lv_spinbox.c | 6 +- src/extra/widgets/spinner/lv_spinner.c | 2 +- src/lv_core/lv_group.c | 4 +- src/lv_core/lv_obj.c | 27 +- src/lv_core/lv_obj.h | 36 +- src/lv_core/lv_obj_pos.c | 15 +- src/lv_core/lv_obj_style.c | 2 +- src/lv_core/lv_refr.c | 4 +- src/lv_draw/lv_draw_label.c | 4 +- src/lv_draw/lv_draw_mask.c | 14 +- src/lv_draw/lv_draw_rect.c | 4 +- src/lv_draw/lv_img_cache.c | 4 +- src/lv_draw/lv_img_decoder.c | 14 +- src/lv_font/lv_font_fmt_txt.c | 4 +- src/lv_hal/lv_hal_disp.c | 6 +- src/lv_hal/lv_hal_indev.c | 4 +- src/lv_misc/lv_anim.c | 4 +- src/lv_misc/{lv_debug.c => lv_assert.c} | 8 +- src/lv_misc/lv_assert.h | 100 ++++ src/lv_misc/lv_debug.h | 131 ----- src/lv_misc/lv_fs.c | 6 +- src/lv_misc/lv_mem.c | 9 +- src/lv_misc/lv_style.c | 22 +- src/lv_misc/lv_style.h | 48 +- src/lv_misc/lv_timer.c | 8 +- src/lv_misc/lv_txt.c | 8 +- src/lv_widgets/lv_arc.c | 2 +- src/lv_widgets/lv_bar.c | 2 +- src/lv_widgets/lv_btnmatrix.c | 6 +- src/lv_widgets/lv_canvas.c | 2 +- src/lv_widgets/lv_chart.c | 10 +- src/lv_widgets/lv_checkbox.c | 2 +- src/lv_widgets/lv_dropdown.c | 16 +- src/lv_widgets/lv_img.c | 4 +- src/lv_widgets/lv_label.c | 20 +- src/lv_widgets/lv_line.c | 2 +- src/lv_widgets/lv_meter.c | 12 +- src/lv_widgets/lv_objx_templ.c | 4 +- src/lv_widgets/lv_roller.c | 4 +- src/lv_widgets/lv_slider.c | 2 +- src/lv_widgets/lv_switch.c | 2 +- src/lv_widgets/lv_table.c | 26 +- src/lv_widgets/lv_textarea.c | 16 +- 173 files changed, 4906 insertions(+), 696 deletions(-) create mode 100644 examples/get_started/llv_example_get_started_.h create mode 100644 examples/get_started/lv_example_get_started_1.c create mode 100644 examples/get_started/lv_example_get_started_2.c create mode 100644 examples/get_started/lv_example_get_started_3.c create mode 100644 examples/layouts/flex/lv_example_flex.h create mode 100644 examples/layouts/flex/lv_example_flex_1.c create mode 100644 examples/layouts/flex/lv_example_flex_2.c create mode 100644 examples/layouts/flex/lv_example_flex_3.c create mode 100644 examples/layouts/flex/lv_example_flex_4.c create mode 100644 examples/layouts/flex/lv_example_flex_5.c create mode 100644 examples/layouts/flex/lv_example_flex_6.c create mode 100644 examples/layouts/grid/lv_example_grid.h create mode 100644 examples/layouts/grid/lv_example_grid_1.c create mode 100644 examples/layouts/grid/lv_example_grid_2.c create mode 100644 examples/layouts/grid/lv_example_grid_3.c create mode 100644 examples/layouts/grid/lv_example_grid_4.c create mode 100644 examples/layouts/grid/lv_example_grid_5.c create mode 100644 examples/layouts/grid/lv_example_grid_6.c create mode 100644 examples/styles/lv_example_style.h create mode 100644 examples/styles/lv_example_style_1.c create mode 100644 examples/styles/lv_example_style_10.c create mode 100644 examples/styles/lv_example_style_11.c create mode 100644 examples/styles/lv_example_style_2.c create mode 100644 examples/styles/lv_example_style_3.c create mode 100644 examples/styles/lv_example_style_4.c create mode 100644 examples/styles/lv_example_style_5.c create mode 100644 examples/styles/lv_example_style_6.c create mode 100644 examples/styles/lv_example_style_7.c create mode 100644 examples/styles/lv_example_style_8.c create mode 100644 examples/styles/lv_example_style_9.c create mode 100644 examples/widgets/arc/lv_example_arc_1.c create mode 100644 examples/widgets/arc/lv_example_arc_1.py create mode 100644 examples/widgets/arc/lv_example_arc_2.c create mode 100644 examples/widgets/arc/lv_example_arc_2.py create mode 100644 examples/widgets/bar/lv_example_bar_1.c create mode 100644 examples/widgets/bar/lv_example_bar_1.py create mode 100644 examples/widgets/bar/lv_example_bar_3.c create mode 100644 examples/widgets/bar/lv_example_bar_4.c create mode 100644 examples/widgets/bar/lv_example_bar_5.c create mode 100644 examples/widgets/bar/lv_example_bar_6.c create mode 100644 examples/widgets/btn/lv_example_btn_1.c create mode 100644 examples/widgets/btn/lv_example_btn_1.py create mode 100644 examples/widgets/btn/lv_example_btn_2.c create mode 100644 examples/widgets/btnmatrix/lv_example_btnmatrix_1.c create mode 100644 examples/widgets/btnmatrix/lv_example_btnmatrix_1.py create mode 100644 examples/widgets/btnmatrix/lv_example_btnmatrix_2.c create mode 100644 examples/widgets/btnmatrix/lv_example_btnmatrix_3.c create mode 100644 examples/widgets/calendar/lv_example_calendar_1.c create mode 100644 examples/widgets/canvas/lv_example_canvas_1.c create mode 100644 examples/widgets/canvas/lv_example_canvas_1.py create mode 100644 examples/widgets/canvas/lv_example_canvas_2.c create mode 100644 examples/widgets/canvas/lv_example_canvas_2.py create mode 100644 examples/widgets/chart/lv_example_chart_1.c create mode 100644 examples/widgets/chart/lv_example_chart_1.py create mode 100644 examples/widgets/chart/lv_example_chart_2.c create mode 100644 examples/widgets/chart/lv_example_chart_3.c create mode 100644 examples/widgets/chart/lv_example_chart_4.c create mode 100644 examples/widgets/checkbox/lv_example_checkbox_1.c create mode 100644 examples/widgets/checkbox/lv_example_checkbox_1.py create mode 100644 examples/widgets/colorwheel/lv_example_colorwheel_1.c create mode 100644 examples/widgets/dropdown/lv_example_dropdown_1.c create mode 100644 examples/widgets/dropdown/lv_example_dropdown_1.py create mode 100644 examples/widgets/dropdown/lv_example_dropdown_2.c create mode 100644 examples/widgets/dropdown/lv_example_dropdown_2.py create mode 100644 examples/widgets/dropdown/lv_example_dropdown_3.c create mode 100644 examples/widgets/img/index.rst create mode 100644 examples/widgets/img/lv_example_img_1.c create mode 100644 examples/widgets/img/lv_example_img_1.py create mode 100644 examples/widgets/img/lv_example_img_2.c create mode 100644 examples/widgets/img/lv_example_img_3.c create mode 100644 examples/widgets/img/lv_example_img_4.c create mode 100644 examples/widgets/keyboard/lv_example_keyboard_1.c create mode 100644 examples/widgets/keyboard/lv_example_keyboard_1.py create mode 100644 examples/widgets/label/lv_example_label_1.c create mode 100644 examples/widgets/label/lv_example_label_1.py create mode 100644 examples/widgets/label/lv_example_label_2.c create mode 100644 examples/widgets/label/lv_example_label_2.py create mode 100644 examples/widgets/led/lv_example_led_1.c create mode 100644 examples/widgets/led/lv_example_led_1.py create mode 100644 examples/widgets/line/lv_example_line_1.c create mode 100644 examples/widgets/line/lv_example_line_1.py create mode 100644 examples/widgets/list/lv_example_list_1.c create mode 100644 examples/widgets/list/lv_example_list_1.py create mode 100644 examples/widgets/lv_example_widgets.h create mode 100644 examples/widgets/meter/lv_example_meter_1.c create mode 100644 examples/widgets/meter/lv_example_meter_2.c create mode 100644 examples/widgets/meter/lv_example_meter_3.c create mode 100644 examples/widgets/meter/lv_example_meter_4.c create mode 100644 examples/widgets/msgbox/lv_example_msgbox_1.c create mode 100644 examples/widgets/msgbox/lv_example_msgbox_1.py create mode 100644 examples/widgets/msgbox/lv_example_msgbox_2.c create mode 100644 examples/widgets/msgbox/lv_example_msgbox_2.py create mode 100644 examples/widgets/obj/lv_example_obj_1.c create mode 100644 examples/widgets/obj/lv_example_obj_1.py create mode 100644 examples/widgets/roller/lv_example_roller_1.c create mode 100644 examples/widgets/roller/lv_example_roller_1.py create mode 100644 examples/widgets/slider/lv_example_slider_1.c create mode 100644 examples/widgets/slider/lv_example_slider_1.py create mode 100644 examples/widgets/slider/lv_example_slider_2.c create mode 100644 examples/widgets/slider/lv_example_slider_2.py create mode 100644 examples/widgets/slider/lv_example_slider_3.c create mode 100644 examples/widgets/spinbox/lv_example_spinbox_1.c create mode 100644 examples/widgets/spinbox/lv_example_spinbox_1.py create mode 100644 examples/widgets/spinner/lv_example_spinner_1.c create mode 100644 examples/widgets/spinner/lv_example_spinner_1.py create mode 100644 examples/widgets/switch/lv_example_switch_1.c create mode 100644 examples/widgets/switch/lv_example_switch_1.py create mode 100644 examples/widgets/table/lv_example_table_1.c create mode 100644 examples/widgets/table/lv_example_table_1.py create mode 100644 examples/widgets/tabview/lv_example_tabview_1.c create mode 100644 examples/widgets/tabview/lv_example_tabview_1.py create mode 100644 examples/widgets/textarea/lv_example_textarea_1.c create mode 100644 examples/widgets/textarea/lv_example_textarea_1.py create mode 100644 examples/widgets/textarea/lv_example_textarea_2.c create mode 100644 examples/widgets/textarea/lv_example_textarea_2.py create mode 100644 examples/widgets/textarea/lv_example_textarea_3.c create mode 100644 examples/widgets/tileview/lv_example_tileview_1.c create mode 100644 examples/widgets/tileview/lv_example_tileview_1.py create mode 100644 examples/widgets/win/lv_example_win_1.c rename src/lv_misc/{lv_debug.c => lv_assert.c} (96%) create mode 100644 src/lv_misc/lv_assert.h delete mode 100644 src/lv_misc/lv_debug.h diff --git a/examples/get_started/llv_example_get_started_.h b/examples/get_started/llv_example_get_started_.h new file mode 100644 index 000000000..7c825069a --- /dev/null +++ b/examples/get_started/llv_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/examples/get_started/lv_example_get_started_1.c b/examples/get_started/lv_example_get_started_1.c new file mode 100644 index 000000000..092fec254 --- /dev/null +++ b/examples/get_started/lv_example_get_started_1.c @@ -0,0 +1,28 @@ +#include "../../lvgl.h" + +static void btn_event_cb(lv_obj_t * btn, lv_event_t event) +{ + if(event == 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(), NULL); /*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, NULL); /*Assign a callback to the button*/ + + lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/ + lv_label_set_text(label, "Button"); /*Set the labels text*/ +} + diff --git a/examples/get_started/lv_example_get_started_2.c b/examples/get_started/lv_example_get_started_2.c new file mode 100644 index 000000000..bd70f6280 --- /dev/null +++ b/examples/get_started/lv_example_get_started_2.c @@ -0,0 +1,83 @@ +//#include "../../lv_examples.h" +// +// +///** +// * Create styles from scratch for buttons. +// */ +//void lv_example_get_started_2(void) +//{ +// static lv_style_t style_btn; +// static lv_style_t style_btn_red; +// +// /*Create a simple button style*/ +// lv_style_init(&style_btn); +// lv_style_set_radius(&style_btn, LV_STATE_DEFAULT, 10); +// lv_style_set_bg_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// lv_style_set_bg_grad_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_GRAY); +// lv_style_set_bg_grad_dir(&style_btn, LV_STATE_DEFAULT, LV_GRAD_DIR_VER); +// +// /*Swap the colors in pressed state*/ +// lv_style_set_bg_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_GRAY); +// lv_style_set_bg_grad_color(&style_btn, LV_STATE_PRESSED, LV_COLOR_SILVER); +// +// /*Add a border*/ +// lv_style_set_border_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE); +// lv_style_set_border_opa(&style_btn, LV_STATE_DEFAULT, LV_OPA_70); +// lv_style_set_border_width(&style_btn, LV_STATE_DEFAULT, 2); +// +// /*Different border color in focused state*/ +// lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED, LV_COLOR_BLUE); +// lv_style_set_border_color(&style_btn, LV_STATE_FOCUSED | LV_STATE_PRESSED, LV_COLOR_NAVY); +// +// /*Set the text style*/ +// lv_style_set_text_color(&style_btn, LV_STATE_DEFAULT, LV_COLOR_WHITE); +// +// /*Make the button smaller when pressed*/ +// lv_style_set_transform_height(&style_btn, LV_STATE_PRESSED, -5); +// lv_style_set_transform_width(&style_btn, LV_STATE_PRESSED, -10); +//#if LV_USE_ANIMATION +// /*Add a transition to the size change*/ +// static lv_anim_path_t path; +// lv_anim_path_init(&path); +// lv_anim_path_set_cb(&path, lv_anim_path_overshoot); +// +// lv_style_set_transition_prop_1(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_HEIGHT); +// lv_style_set_transition_prop_2(&style_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH); +// lv_style_set_transition_time(&style_btn, LV_STATE_DEFAULT, 300); +// lv_style_set_transition_path(&style_btn, LV_STATE_DEFAULT, &path); +//#endif +// +// /*Create a red style. Change only some colors.*/ +// lv_style_init(&style_btn_red); +// lv_style_set_bg_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_RED); +// lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_MAROON); +// lv_style_set_bg_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_MAROON); +// lv_style_set_bg_grad_color(&style_btn_red, LV_STATE_PRESSED, LV_COLOR_RED); +// lv_style_set_text_color(&style_btn_red, LV_STATE_DEFAULT, LV_COLOR_WHITE); +//#if LV_USE_BTN +// /*Create buttons and use the new styles*/ +// lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); /*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_reset_style_list(btn, LV_BTN_PART_MAIN); /*Remove the styles coming from the theme*/ +// lv_obj_add_style(btn, LV_BTN_PART_MAIN, &style_btn); +// +// lv_obj_t * label = lv_label_create(btn, NULL); /*Add a label to the button*/ +// lv_label_set_text(label, "Button"); /*Set the labels text*/ +// +// /*Create a new button*/ +// lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), btn); +// lv_obj_set_pos(btn2, 10, 80); +// lv_obj_set_size(btn2, 120, 50); /*Set its size*/ +// lv_obj_reset_style_list(btn2, LV_BTN_PART_MAIN); /*Remove the styles coming from the theme*/ +// lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn); +// lv_obj_add_style(btn2, LV_BTN_PART_MAIN, &style_btn_red); /*Add the red style on top of the current */ +// lv_obj_set_style_local_radius(btn2, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); /*Add a local style*/ +// +// label = lv_label_create(btn2, NULL); /*Add a label to the button*/ +// lv_label_set_text(label, "Button 2"); /*Set the labels text*/ +//#endif +//} +// +// diff --git a/examples/get_started/lv_example_get_started_3.c b/examples/get_started/lv_example_get_started_3.c new file mode 100644 index 000000000..8c73b677e --- /dev/null +++ b/examples/get_started/lv_example_get_started_3.c @@ -0,0 +1,31 @@ +//#include "../../lv_examples.h" +// +//static lv_obj_t * label; +// +//static void slider_event_cb(lv_obj_t * slider, lv_event_t event) +//{ +// if(event == LV_EVENT_VALUE_CHANGED) { +// /*Refresh the text*/ +// lv_label_set_text_fmt(label, "%d", lv_slider_get_value(slider)); +// lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); /*Align below 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(), NULL); +// lv_obj_set_width(slider, 200); /*Set the width*/ +// lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the center of the parent (screen)*/ +// lv_obj_set_event_cb(slider, slider_event_cb); /*Assign an event function*/ +// +// /* Create a label below the slider */ +// label = lv_label_create(lv_scr_act(), NULL); +// lv_label_set_text(label, "0"); +// lv_obj_align(label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); /*Align below the slider*/ +//} +// +// diff --git a/examples/layouts/flex/lv_example_flex.h b/examples/layouts/flex/lv_example_flex.h new file mode 100644 index 000000000..c9daf66d9 --- /dev/null +++ b/examples/layouts/flex/lv_example_flex.h @@ -0,0 +1,37 @@ +/** + * @file lv_example_flex.h + * + */ + +#ifndef LV_EX_FLEX_H +#define LV_EX_FLEX_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_EX_FLEX_H*/ diff --git a/examples/layouts/flex/lv_example_flex_1.c b/examples/layouts/flex/lv_example_flex_1.c new file mode 100644 index 000000000..3113f86a0 --- /dev/null +++ b/examples/layouts/flex/lv_example_flex_1.c @@ -0,0 +1,43 @@ +//#include "../../lv_examples.h" +// +///** +// * 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(), NULL); +// lv_obj_set_size(cont_row, 300, 75); +// lv_obj_align(cont_row, NULL, LV_ALIGN_IN_TOP_MID, 0, 5); +// lv_obj_set_flex_dir(cont_row, LV_FLEX_DIR_ROW); +// lv_obj_set_flex_gap(cont_row, 10); +// +// /*Create a container with COLUMN flex direction*/ +// lv_obj_t * cont_col = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont_col, 200, 150); +// lv_obj_align(cont_col, cont_row, LV_ALIGN_OUT_BOTTOM_MID, 0, 5); +// lv_obj_set_flex_dir(cont_col, LV_FLEX_DIR_COLUMN); +// lv_obj_set_flex_gap(cont_col, 10); +// +// uint32_t i; +// for(i = 0; i < 10; i++) { +// /*Add items to the row*/ +// lv_obj_t * obj1 = lv_obj_create(cont_row, NULL); +// lv_obj_set_size(obj1, 100, LV_COORD_PCT(100)); +// lv_obj_set_flex_item(obj1, true); +// +// lv_obj_t * label1 = lv_label_create(obj1, NULL); +// lv_label_set_text_fmt(label1, "Item: %d", i); +// lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, 0); +// +// /*Add items to the column*/ +// lv_obj_t * obj2 = lv_obj_create(cont_col, NULL); +// lv_obj_set_size(obj2, LV_COORD_PCT(100), LV_SIZE_AUTO); +// lv_obj_set_flex_item(obj2, true); +// +// lv_obj_t * label3 = lv_label_create(obj2, NULL); +// lv_label_set_text_fmt(label3, "Item: %d", i); +// lv_obj_align(label3, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/layouts/flex/lv_example_flex_2.c b/examples/layouts/flex/lv_example_flex_2.c new file mode 100644 index 000000000..974475e05 --- /dev/null +++ b/examples/layouts/flex/lv_example_flex_2.c @@ -0,0 +1,24 @@ +//#include "../../lv_examples.h" +// +///** +// * Arrange items in column with wrap and place the row to get even space around them. +// */ +//void lv_example_flex_2(void) +//{ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP); +// lv_obj_set_flex_place(cont, LV_FLEX_PLACE_START, LV_FLEX_PLACE_START); +// +// uint32_t i; +// for(i = 0; i < 3; i++) { +// lv_obj_t * obj = lv_obj_create(cont, NULL); +// lv_obj_set_flex_item_place(obj, LV_FLEX_PLACE_STRETCH); +// lv_obj_set_size(obj, 70, LV_SIZE_AUTO); +// +// lv_obj_t * label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "%d", i); +// } +//} +// diff --git a/examples/layouts/flex/lv_example_flex_3.c b/examples/layouts/flex/lv_example_flex_3.c new file mode 100644 index 000000000..e31d079d9 --- /dev/null +++ b/examples/layouts/flex/lv_example_flex_3.c @@ -0,0 +1,30 @@ +//#include "../../lv_examples.h" +// +///** +// * Arrange items in a row and demonstrate flex grow. +// */ +//void lv_example_flex_3(void) +//{ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW); +// +// lv_obj_t * obj; +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, 20, 20); /*Fix size*/ +// lv_obj_set_flex_item(obj, true); +// +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_FLEX_GROW(1), 30); /*1 portion from the free space*/ +// lv_obj_set_flex_item(obj, true); +// +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_FLEX_GROW(2), 40); /*2 portion from the free space*/ +// lv_obj_set_flex_item(obj, true); +// +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, 20, 20); /*Fix size. It is flushed to the right by the "grow" items*/ +// lv_obj_set_flex_item(obj, true); +//} +// diff --git a/examples/layouts/flex/lv_example_flex_4.c b/examples/layouts/flex/lv_example_flex_4.c new file mode 100644 index 000000000..94726af58 --- /dev/null +++ b/examples/layouts/flex/lv_example_flex_4.c @@ -0,0 +1,24 @@ +//#include "../../lv_examples.h" +// +///** +// * Reverse the order of flex items +// */ +//void lv_example_flex_4(void) +//{ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP_REVERSE); +// lv_obj_set_flex_gap(cont, 10); +// +// uint32_t i; +// for(i = 0; i < 20; i++) { +// lv_obj_t * obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, 100, LV_SIZE_AUTO); +// lv_obj_set_flex_item(obj, true); +// +// lv_obj_t * label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "Item: %d", i); +// } +//} +// diff --git a/examples/layouts/flex/lv_example_flex_5.c b/examples/layouts/flex/lv_example_flex_5.c new file mode 100644 index 000000000..17e16218c --- /dev/null +++ b/examples/layouts/flex/lv_example_flex_5.c @@ -0,0 +1,28 @@ +//#include "../../lv_examples.h" +// +///** +// * Demonstrate the effect of margin on flex item +// */ +//void lv_example_flex_5(void) +//{ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW_WRAP); +// +// uint32_t i; +// for(i = 0; i < 20; i++) { +// lv_obj_t * obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, 100, LV_SIZE_AUTO); +// lv_obj_set_flex_item(obj, true); +// +// /*Set margin on every side*/ +// if(i == 4) { +// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 20); +// } +// +// lv_obj_t * label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "Item:%d", i); +// } +//} +// diff --git a/examples/layouts/flex/lv_example_flex_6.c b/examples/layouts/flex/lv_example_flex_6.c new file mode 100644 index 000000000..9bb07e6fb --- /dev/null +++ b/examples/layouts/flex/lv_example_flex_6.c @@ -0,0 +1,25 @@ +//#include "../../lv_examples.h" +// +///** +// * RTL base direction changes order of the items. +// */ +//void lv_example_flex_6(void) +//{ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_flex_dir(cont, LV_FLEX_DIR_COLUMN_WRAP); +// +// uint32_t i; +// for(i = 0; i < 20; i++) { +// lv_obj_t * obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, 80, LV_SIZE_AUTO); +// lv_obj_set_flex_item(obj, true); +// +// lv_obj_t * label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "%d", i); +// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/layouts/grid/lv_example_grid.h b/examples/layouts/grid/lv_example_grid.h new file mode 100644 index 000000000..69d284d30 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid.h @@ -0,0 +1,37 @@ +/** + * @file lv_example_grid.h + * + */ + +#ifndef LV_EX_GRID_H +#define LV_EX_GRID_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_EX_GRID_H*/ diff --git a/examples/layouts/grid/lv_example_grid_1.c b/examples/layouts/grid/lv_example_grid_1.c new file mode 100644 index 000000000..81e3a0bf2 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid_1.c @@ -0,0 +1,39 @@ +//#include "../../lv_examples.h" +// +///** +// * A simple grid +// */ +//void lv_example_grid_1(void) +//{ +// static lv_coord_t col_dsc[3] = {80, 80, 80}; +// static lv_coord_t row_dsc[3] = {60, 60, 60}; +// +// static lv_grid_t grid; +// lv_grid_init(&grid); +// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); +// +// /*Create a container with grid*/ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_grid(cont, &grid); +// +// lv_obj_t * label; +// lv_obj_t * obj; +// +// uint32_t i; +// for(i = 0; i < 9; i++) { +// uint8_t col = i % 3; +// uint8_t row = i / 3; +// +// obj = lv_obj_create(cont, NULL); +// /* Stretch the cell horizontally and vertically too +// * Set span to 1 to make the cell 1 column/row sized */ +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1)); +// +// label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "c%d, r%d", col, row); +// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/layouts/grid/lv_example_grid_2.c b/examples/layouts/grid/lv_example_grid_2.c new file mode 100644 index 000000000..687a6d663 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid_2.c @@ -0,0 +1,59 @@ +//#include "../../lv_examples.h" +// +///** +// * Demonstrate cell placement and span +// */ +//void lv_example_grid_2(void) +//{ +// static lv_coord_t col_dsc[3] = {80, 80, 80}; +// static lv_coord_t row_dsc[3] = {60, 60, 60}; +// +// static lv_grid_t grid; +// lv_grid_init(&grid); +// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); +// +// /*Create a container with grid*/ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_grid(cont, &grid); +// +// lv_obj_t * label; +// lv_obj_t * obj; +// +// /*Cell to 0;0 and align to to the start (left/top) horizontally and vertically too */ +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(0, 1), LV_GRID_CELL_START(0, 1)); +// label = lv_label_create(obj, NULL); +// lv_label_set_text(label, "c0, r0"); +// +// /*Cell to 1;0 and align to to the start (left) horizontally and center vertically too */ +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(1, 1), LV_GRID_CELL_CENTER(0, 1)); +// label = lv_label_create(obj, NULL); +// lv_label_set_text(label, "c1, r0"); +// +// /*Cell to 2;0 and align to to the start (left) horizontally and end (bottom) vertically too */ +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(2, 1), LV_GRID_CELL_END(0, 1)); +// label = lv_label_create(obj, NULL); +// lv_label_set_text(label, "c2, r0"); +// +// /*Cell to 1;1 but 2 column wide (span = 2).Set width and height to stretched. */ +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(1, 2), LV_GRID_CELL_STRETCH(1, 1)); +// label = lv_label_create(obj, NULL); +// lv_label_set_text(label, "c1-2, r1"); +// +// /*Cell to 0;1 but 2 rows tall (span = 2).Set width and height to stretched. */ +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_size(obj, LV_SIZE_AUTO, LV_SIZE_AUTO); +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(0, 1), LV_GRID_CELL_STRETCH(1, 2)); +// label = lv_label_create(obj, NULL); +// lv_label_set_text(label, "c0\nr1-2"); +//} +// diff --git a/examples/layouts/grid/lv_example_grid_3.c b/examples/layouts/grid/lv_example_grid_3.c new file mode 100644 index 000000000..7c06df2f1 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid_3.c @@ -0,0 +1,45 @@ +//#include "../../lv_examples.h" +// +///** +// * Demonstrate grid's "free unit" +// */ +//void lv_example_grid_3(void) +//{ +// /* Column 1: fix width 60 px +// * Column 2: 1 unit from the remaining free space +// * Column 3: 2 unit from the remaining free space */ +// static lv_coord_t col_dsc[3] = {60, LV_GRID_FR(1), LV_GRID_FR(2)}; +// +// /* Row 1: fix width 60 px +// * Row 2: 1 unit from the remaining free space +// * Row 3: fix width 60 px */ +// static lv_coord_t row_dsc[3] = {60, LV_GRID_FR(1), 60}; +// +// static lv_grid_t grid; +// lv_grid_init(&grid); +// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); +// +// /*Create a container with grid*/ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_grid(cont, &grid); +// +// lv_obj_t * label; +// lv_obj_t * obj; +// uint32_t i; +// for(i = 0; i < 9; i++) { +// uint8_t col = i % 3; +// uint8_t row = i / 3; +// +// obj = lv_obj_create(cont, NULL); +// /* Stretch the cell horizontally and vertically too +// * Set span to 1 to make the cell 1 column/row sized */ +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1)); +// +// label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "%d,%d", col, row); +// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/layouts/grid/lv_example_grid_4.c b/examples/layouts/grid/lv_example_grid_4.c new file mode 100644 index 000000000..6fffb66d5 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid_4.c @@ -0,0 +1,41 @@ +//#include "../../lv_examples.h" +// +///** +// * Demonstrate track placement +// */ +//void lv_example_grid_4(void) +//{ +// static lv_coord_t col_dsc[3] = {60, 60, 60}; +// static lv_coord_t row_dsc[3] = {50, 50, 50}; +// +// static lv_grid_t grid; +// lv_grid_init(&grid); +// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); +// +// /*Add space between the columns and move the rows to the bottom (end)*/ +// lv_grid_set_place(&grid, LV_GRID_SPACE_BETWEEN, LV_GRID_END); +// +// /*Create a container with grid*/ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_grid(cont, &grid); +// +// lv_obj_t * label; +// lv_obj_t * obj; +// uint32_t i; +// for(i = 0; i < 9; i++) { +// uint8_t col = i % 3; +// uint8_t row = i / 3; +// +// obj = lv_obj_create(cont, NULL); +// /* Stretch the cell horizontally and vertically too +// * Set span to 1 to make the cell 1 column/row sized */ +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_STRETCH(row, 1)); +// +// label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "%d,%d", col, row); +// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/layouts/grid/lv_example_grid_5.c b/examples/layouts/grid/lv_example_grid_5.c new file mode 100644 index 000000000..0f93bbb03 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid_5.c @@ -0,0 +1,41 @@ +//#include "../../lv_examples.h" +// +///** +// * Demonstrate margin in grid +// */ +//void lv_example_grid_5(void) +//{ +// +// /*60x60 cells*/ +// static lv_coord_t col_dsc[3] = {100, 60, 60}; +// static lv_coord_t row_dsc[3] = {60, 60, 60}; +// +// static lv_grid_t grid; +// lv_grid_init(&grid); +// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); +// +// /*Create a container with grid*/ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_grid(cont, &grid); +// +// lv_obj_t * label; +// lv_obj_t * obj; +// uint32_t i; +// for(i = 0; i < 9; i++) { +// uint8_t col = i % 3; +// uint8_t row = i / 3; +// +// obj = lv_obj_create(cont, NULL); +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_START(col, 1), LV_GRID_CELL_START(row, 1)); +// lv_obj_set_size(obj, 55, 55); +// if(i == 1) { +// lv_obj_set_style_local_margin_all(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, 5); +// } +// label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "%d,%d", col, row); +// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/layouts/grid/lv_example_grid_6.c b/examples/layouts/grid/lv_example_grid_6.c new file mode 100644 index 000000000..b9edde377 --- /dev/null +++ b/examples/layouts/grid/lv_example_grid_6.c @@ -0,0 +1,43 @@ +//#include "../../lv_examples.h" +// +///** +// * Demonstrate RTL direction on grid +// */ +//void lv_example_grid_6(void) +//{ +// +// static lv_coord_t col_dsc[3] = {100, 60, 60}; +// static lv_coord_t row_dsc[3] = {60, 60, 60}; +// +// static lv_grid_t grid; +// lv_grid_init(&grid); +// lv_grid_set_template(&grid, col_dsc, 3, row_dsc, 3); +// +// /*Add space between the columns and move the rows to the bottom (end)*/ +// +// /*Create a container with grid*/ +// lv_obj_t * cont = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(cont, 300, 220); +// lv_obj_align(cont, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_base_dir(cont, LV_BIDI_DIR_RTL); +// lv_obj_set_grid(cont, &grid); +// +// lv_obj_t * label; +// lv_obj_t * obj; +// uint32_t i; +// for(i = 0; i < 3; i++) { +// uint8_t col = i % 3; +// uint8_t row = i / 3; +// +// obj = lv_obj_create(cont, NULL); +// /* Stretch the cell horizontally and vertically too +// * Set span to 1 to make the cell 1 column/row sized */ +// lv_obj_set_grid_cell(obj, LV_GRID_CELL_STRETCH(col, 1), LV_GRID_CELL_START(row, 1)); +// lv_obj_set_size(obj, 55, 55); +// +// label = lv_label_create(obj, NULL); +// lv_label_set_text_fmt(label, "%d,%d", col, row); +// lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); +// } +//} +// diff --git a/examples/styles/lv_example_style.h b/examples/styles/lv_example_style.h new file mode 100644 index 000000000..5d79d117d --- /dev/null +++ b/examples/styles/lv_example_style.h @@ -0,0 +1,48 @@ +/** + * @file lv_example_widgets.h + * + */ + +#ifndef LV_EX_STYLE_H +#define LV_EX_STYLE_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_example_style_1(void); +void lv_example_style_2(void); +void lv_example_style_3(void); +void lv_example_style_4(void); +void lv_example_style_5(void); +void lv_example_style_6(void); +void lv_example_style_7(void); +void lv_example_style_8(void); +void lv_example_style_9(void); +void lv_example_style_10(void); +void lv_example_style_11(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_EX_STYLE_H*/ diff --git a/examples/styles/lv_example_style_1.c b/examples/styles/lv_example_style_1.c new file mode 100644 index 000000000..13b825f22 --- /dev/null +++ b/examples/styles/lv_example_style_1.c @@ -0,0 +1,28 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the background style properties +// */ +//void lv_example_style_1(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// +// /*Make a gradient*/ +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// lv_style_set_bg_grad_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_bg_grad_dir(&style, LV_STATE_DEFAULT, LV_GRAD_DIR_VER); +// +// /*Shift the gradient to the bottom*/ +// lv_style_set_bg_main_stop(&style, LV_STATE_DEFAULT, 128); +// lv_style_set_bg_grad_stop(&style, LV_STATE_DEFAULT, 192); +// +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_10.c b/examples/styles/lv_example_style_10.c new file mode 100644 index 000000000..89401cfa1 --- /dev/null +++ b/examples/styles/lv_example_style_10.c @@ -0,0 +1,35 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the transitions style properties +// */ +//void lv_example_style_10(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Set different background color in pressed state*/ +// lv_style_set_bg_color(&style, LV_STATE_PRESSED, LV_COLOR_GRAY); +// +// /*Set different transition time in default and pressed state +// *fast press, slower revert to default*/ +// lv_style_set_transition_time(&style, LV_STATE_DEFAULT, 500); +// lv_style_set_transition_time(&style, LV_STATE_PRESSED, 200); +// +// /*Small delay to make transition more visible*/ +// lv_style_set_transition_delay(&style, LV_STATE_DEFAULT, 100); +// +// /*Add `bg_color` to transitioned properties*/ +// lv_style_set_transition_prop_1(&style, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_11.c b/examples/styles/lv_example_style_11.c new file mode 100644 index 000000000..a415584b7 --- /dev/null +++ b/examples/styles/lv_example_style_11.c @@ -0,0 +1,36 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the scale style properties +// */ +//void lv_example_style_11(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Set some paddings*/ +// lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 20); +// lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 5); +// +// lv_style_set_scale_end_color(&style, LV_STATE_DEFAULT, LV_COLOR_RED); +// lv_style_set_line_color(&style, LV_STATE_DEFAULT, LV_COLOR_WHITE); +// lv_style_set_scale_grad_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_line_width(&style, LV_STATE_DEFAULT, 2); +// lv_style_set_scale_end_line_width(&style, LV_STATE_DEFAULT, 4); +// lv_style_set_scale_end_border_width(&style, LV_STATE_DEFAULT, 4); +// +// /*Gauge has a needle but for simplicity its style is not initialized here*/ +//#if LV_USE_GAUGE +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_gauge_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_GAUGE_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//#endif +//} +// diff --git a/examples/styles/lv_example_style_2.c b/examples/styles/lv_example_style_2.c new file mode 100644 index 000000000..10419a141 --- /dev/null +++ b/examples/styles/lv_example_style_2.c @@ -0,0 +1,27 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the border style properties +// */ +//void lv_example_style_2(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 20); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Add border to the bottom+right*/ +// lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_border_width(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_border_opa(&style, LV_STATE_DEFAULT, LV_OPA_50); +// lv_style_set_border_side(&style, LV_STATE_DEFAULT, LV_BORDER_SIDE_BOTTOM | LV_BORDER_SIDE_RIGHT); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_3.c b/examples/styles/lv_example_style_3.c new file mode 100644 index 000000000..9e16cd071 --- /dev/null +++ b/examples/styles/lv_example_style_3.c @@ -0,0 +1,26 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the outline style properties +// */ +//void lv_example_style_3(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Add outline*/ +// lv_style_set_outline_width(&style, LV_STATE_DEFAULT, 2); +// lv_style_set_outline_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_outline_pad(&style, LV_STATE_DEFAULT, 8); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_4.c b/examples/styles/lv_example_style_4.c new file mode 100644 index 000000000..70e945d10 --- /dev/null +++ b/examples/styles/lv_example_style_4.c @@ -0,0 +1,27 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the Shadow style properties +// */ +//void lv_example_style_4(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Add a shadow*/ +// lv_style_set_shadow_width(&style, LV_STATE_DEFAULT, 8); +// lv_style_set_shadow_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_shadow_ofs_x(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_shadow_ofs_y(&style, LV_STATE_DEFAULT, 20); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_5.c b/examples/styles/lv_example_style_5.c new file mode 100644 index 000000000..98b3d8937 --- /dev/null +++ b/examples/styles/lv_example_style_5.c @@ -0,0 +1,27 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the pattern style properties +// */ +//void lv_example_style_5(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Add a repeating pattern*/ +// lv_style_set_pattern_image(&style, LV_STATE_DEFAULT, LV_SYMBOL_OK); +// lv_style_set_pattern_recolor(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_pattern_opa(&style, LV_STATE_DEFAULT, LV_OPA_50); +// lv_style_set_pattern_repeat(&style, LV_STATE_DEFAULT, true); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_6.c b/examples/styles/lv_example_style_6.c new file mode 100644 index 000000000..87c765965 --- /dev/null +++ b/examples/styles/lv_example_style_6.c @@ -0,0 +1,30 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the value style properties +// */ +//void lv_example_style_6(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// +// /*Add a value text properties*/ +// lv_style_set_value_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_value_align(&style, LV_STATE_DEFAULT, LV_ALIGN_IN_BOTTOM_RIGHT); +// lv_style_set_value_ofs_x(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_value_ofs_y(&style, LV_STATE_DEFAULT, 10); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +// +// /*Add a value text to the local style. This way every object can have different text*/ +// lv_obj_set_style_local_value_str(obj, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, "Text"); +//} +// diff --git a/examples/styles/lv_example_style_7.c b/examples/styles/lv_example_style_7.c new file mode 100644 index 000000000..995e664fa --- /dev/null +++ b/examples/styles/lv_example_style_7.c @@ -0,0 +1,34 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the text style properties +// */ +//void lv_example_style_7(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// lv_style_set_border_width(&style, LV_STATE_DEFAULT, 2); +// lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// +// lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 10); +// +// lv_style_set_text_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_text_letter_space(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_text_line_space(&style, LV_STATE_DEFAULT, 20); +// lv_style_set_text_decor(&style, LV_STATE_DEFAULT, LV_TEXT_DECOR_UNDERLINE); +// +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_label_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_LABEL_PART_MAIN, &style); +// lv_label_set_text(obj, "Text of\n" +// "a label"); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//} +// diff --git a/examples/styles/lv_example_style_8.c b/examples/styles/lv_example_style_8.c new file mode 100644 index 000000000..b3582f27e --- /dev/null +++ b/examples/styles/lv_example_style_8.c @@ -0,0 +1,24 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the line style properties +// */ +//void lv_example_style_8(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// lv_style_set_line_color(&style, LV_STATE_DEFAULT, LV_COLOR_GRAY); +// lv_style_set_line_width(&style, LV_STATE_DEFAULT, 6); +// lv_style_set_line_rounded(&style, LV_STATE_DEFAULT, true); +//#if LV_USE_LINE +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_line_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_LINE_PART_MAIN, &style); +// +// static lv_point_t p[] = {{10, 30}, {30, 50}, {100, 0}}; +// lv_line_set_points(obj, p, 3); +// +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//#endif +//} diff --git a/examples/styles/lv_example_style_9.c b/examples/styles/lv_example_style_9.c new file mode 100644 index 000000000..a2c3a5ee1 --- /dev/null +++ b/examples/styles/lv_example_style_9.c @@ -0,0 +1,35 @@ +//#include "../../lv_examples.h" +// +///** +// * Using the image style properties +// */ +//void lv_example_style_9(void) +//{ +// static lv_style_t style; +// lv_style_init(&style); +// +// /*Set a background color and a radius*/ +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 5); +// lv_style_set_bg_opa(&style, LV_STATE_DEFAULT, LV_OPA_COVER); +// lv_style_set_bg_color(&style, LV_STATE_DEFAULT, LV_COLOR_SILVER); +// lv_style_set_border_width(&style, LV_STATE_DEFAULT, 2); +// lv_style_set_border_color(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// +// lv_style_set_pad_top(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_pad_bottom(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_pad_left(&style, LV_STATE_DEFAULT, 10); +// lv_style_set_pad_right(&style, LV_STATE_DEFAULT, 10); +// +// lv_style_set_image_recolor(&style, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// lv_style_set_image_recolor_opa(&style, LV_STATE_DEFAULT, LV_OPA_50); +// +//#if LV_USE_IMG +// /*Create an object with the new style*/ +// lv_obj_t * obj = lv_img_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj, LV_IMG_PART_MAIN, &style); +// LV_IMG_DECLARE(img_cogwheel_argb); +// lv_img_set_src(obj, &img_cogwheel_argb); +// lv_obj_align(obj, NULL, LV_ALIGN_CENTER, 0, 0); +//#endif +//} +// diff --git a/examples/widgets/arc/lv_example_arc_1.c b/examples/widgets/arc/lv_example_arc_1.c new file mode 100644 index 000000000..d361d872f --- /dev/null +++ b/examples/widgets/arc/lv_example_arc_1.c @@ -0,0 +1,14 @@ +#include "../../../lvgl.h" + +#if LV_USE_ARC + +void lv_example_arc_1(void) +{ + /*Create an Arc*/ + lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL); + lv_arc_set_end_angle(arc, 200); + lv_obj_set_size(arc, 150, 150); + lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0); +} + +#endif diff --git a/examples/widgets/arc/lv_example_arc_1.py b/examples/widgets/arc/lv_example_arc_1.py new file mode 100644 index 000000000..2fc6dae39 --- /dev/null +++ b/examples/widgets/arc/lv_example_arc_1.py @@ -0,0 +1,12 @@ +# Create style for the Arcs +style = lv.style_t() +lv.style_copy(style, lv.style_plain) +style.line.color = lv.color_make(0,0,255) # Arc color +style.line.width = 8 # Arc width + +# Create an Arc +arc = lv.arc(lv.scr_act()) +arc.set_style(lv.arc.STYLE.MAIN, style) # Use the new style +arc.set_angles(90, 60) +arc.set_size(150, 150) +arc.align(None, lv.ALIGN.CENTER, 0, 0) \ No newline at end of file diff --git a/examples/widgets/arc/lv_example_arc_2.c b/examples/widgets/arc/lv_example_arc_2.c new file mode 100644 index 000000000..7fd9a1a1d --- /dev/null +++ b/examples/widgets/arc/lv_example_arc_2.c @@ -0,0 +1,38 @@ +#include "../../../lvgl.h" +#if LV_USE_ARC + +/** + * An `lv_task` to call periodically to set the angles of the arc + * @param t + */ +static void arc_loader(lv_timer_t * t) +{ + static int16_t a = 270; + + a+=5; + + lv_arc_set_end_angle(t->user_data, a); + + if(a >= 270 + 360) { + lv_timer_del(t); + return; + } +} + +/** + * Create an arc which acts as a loader. + */ +void lv_example_arc_2(void) +{ + /*Create an Arc*/ + lv_obj_t * arc = lv_arc_create(lv_scr_act(), NULL); + lv_arc_set_bg_angles(arc, 0, 360); + lv_arc_set_angles(arc, 270, 270); + lv_obj_align(arc, NULL, LV_ALIGN_CENTER, 0, 0); + + /* Create an `lv_task` to update the arc. + * Store the `arc` in the user data*/ + lv_timer_create(arc_loader, 20, arc); +} + +#endif diff --git a/examples/widgets/arc/lv_example_arc_2.py b/examples/widgets/arc/lv_example_arc_2.py new file mode 100644 index 000000000..a03f4ec61 --- /dev/null +++ b/examples/widgets/arc/lv_example_arc_2.py @@ -0,0 +1,43 @@ +# Create an arc which acts as a loader. +class loader_arc(lv.arc): + + def __init__(self, parent, color=lv.color_hex(0x000080), + width=8, style=lv.style_plain, rate=20): + super().__init__(parent) + + self.a = 0 + self.rate = rate + + # Create style for the Arcs + self.style = lv.style_t() + lv.style_copy(self.style, style) + self.style.line.color = color + self.style.line.width = width + + # Create an Arc + self.set_angles(180, 180); + self.set_style(self.STYLE.MAIN, self.style); + + # Spin the Arc + self.spin() + + def spin(self): + # Create an `lv_task` to update the arc. + lv.task_create(self.task_cb, self.rate, lv.TASK_PRIO.LOWEST, {}) + + + # An `lv_task` to call periodically to set the angles of the arc + def task_cb(self, task): + self.a+=5; + if self.a >= 359: self.a = 359 + + if self.a < 180: self.set_angles(180-self.a, 180) + else: self.set_angles(540-self.a, 180) + + if self.a == 359: + self.a = 0 + lv.task_del(task) + +# Create a loader arc +loader_arc = loader_arc(lv.scr_act()) +loader_arc.align(None, lv.ALIGN.CENTER, 0, 0) \ No newline at end of file diff --git a/examples/widgets/bar/lv_example_bar_1.c b/examples/widgets/bar/lv_example_bar_1.c new file mode 100644 index 000000000..460835153 --- /dev/null +++ b/examples/widgets/bar/lv_example_bar_1.c @@ -0,0 +1,12 @@ +#include "../../../lvgl.h" +#if LV_USE_BAR + +void lv_example_bar_1(void) +{ + lv_obj_t * bar1 = lv_bar_create(lv_scr_act(), NULL); + lv_obj_set_size(bar1, 200, 20); + lv_obj_align(bar1, NULL, LV_ALIGN_CENTER, 0, 0); + lv_bar_set_value(bar1, 70, LV_ANIM_OFF); +} + +#endif diff --git a/examples/widgets/bar/lv_example_bar_1.py b/examples/widgets/bar/lv_example_bar_1.py new file mode 100644 index 000000000..2f663c7e2 --- /dev/null +++ b/examples/widgets/bar/lv_example_bar_1.py @@ -0,0 +1,5 @@ +bar1 = lv.bar(lv.scr_act()) +bar1.set_size(200, 30) +bar1.align(None, lv.ALIGN.CENTER, 0, 0) +bar1.set_anim_time(1000) +bar1.set_value(100, lv.ANIM.ON) diff --git a/examples/widgets/bar/lv_example_bar_3.c b/examples/widgets/bar/lv_example_bar_3.c new file mode 100644 index 000000000..6cad55570 --- /dev/null +++ b/examples/widgets/bar/lv_example_bar_3.c @@ -0,0 +1,37 @@ +#include "../../../lvgl.h" +#if LV_USE_BAR + +static void set_temp(lv_obj_t * bar, int32_t temp) +{ + lv_bar_set_value(bar, temp, LV_ANIM_ON); + + static char buf[10]; /*Only the pointer t saved so must be static*/ + lv_snprintf(buf, sizeof(buf), "%d°C", temp); + lv_obj_set_style_content_text(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf); +} + +/** + * A temperature meter example + */ +void lv_example_bar_3(void) +{ + static lv_style_t style_indic; + + lv_style_init(&style_indic); + lv_style_set_bg_opa(&style_indic, LV_OPA_COVER); + lv_style_set_bg_color(&style_indic, LV_COLOR_RED); + lv_style_set_bg_grad_color(&style_indic, LV_COLOR_BLUE); + lv_style_set_bg_grad_dir(&style_indic, LV_GRAD_DIR_VER); + lv_style_set_content_align(&style_indic, LV_ALIGN_OUT_LEFT_TOP); + lv_style_set_content_ofs_x(&style_indic, -3); + + lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL); + lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic); + lv_obj_set_size(bar, 20, 200); + lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0); + lv_bar_set_range(bar, -20, 40); + set_temp(bar, 30); +} + + +#endif diff --git a/examples/widgets/bar/lv_example_bar_4.c b/examples/widgets/bar/lv_example_bar_4.c new file mode 100644 index 000000000..4ddf71987 --- /dev/null +++ b/examples/widgets/bar/lv_example_bar_4.c @@ -0,0 +1,27 @@ +#include "../../../lvgl.h" +#if LV_USE_BAR + +/** + * Bar with stripe pattern and ranged value + */ +void lv_example_bar_4(void) +{ + LV_IMG_DECLARE(img_skew_strip); + static lv_style_t style_indic; + + lv_style_init(&style_indic); + lv_style_set_bg_img_src(&style_indic, &img_skew_strip); + lv_style_set_bg_img_tiled(&style_indic, true); + lv_style_set_bg_img_opa(&style_indic, LV_OPA_30); + + lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL); + lv_obj_add_style(bar, LV_PART_INDICATOR, LV_STATE_DEFAULT, &style_indic); + + lv_obj_set_size(bar, 260, 20); + lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0); + lv_bar_set_type(bar, LV_BAR_TYPE_RANGE); + lv_bar_set_value(bar, 90, LV_ANIM_OFF); + lv_bar_set_start_value(bar, 20, LV_ANIM_OFF); +} + +#endif diff --git a/examples/widgets/bar/lv_example_bar_5.c b/examples/widgets/bar/lv_example_bar_5.c new file mode 100644 index 000000000..6f37c8d4a --- /dev/null +++ b/examples/widgets/bar/lv_example_bar_5.c @@ -0,0 +1,30 @@ +#include "../../../lvgl.h" +#if LV_USE_BAR + +/** + * Bar with LTR and RTL base direction + */ +void lv_example_bar_5(void) +{ + static lv_style_t style_bg; + lv_style_init(&style_bg); + lv_style_set_content_ofs_y(&style_bg, -3); + lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID); + + lv_obj_t * bar_ltr = lv_bar_create(lv_scr_act(), NULL); + lv_obj_set_size(bar_ltr, 200, 20); + lv_bar_set_value(bar_ltr, 70, LV_ANIM_OFF); + lv_obj_align(bar_ltr, NULL, LV_ALIGN_CENTER, 0, -30); + lv_obj_add_style(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg); + lv_obj_set_style_content_text(bar_ltr, LV_PART_MAIN, LV_STATE_DEFAULT, "Left to Right base direction"); + + lv_obj_t * bar_rtl = lv_bar_create(lv_scr_act(), NULL); + lv_obj_set_base_dir(bar_rtl, LV_BIDI_DIR_RTL); + lv_obj_set_size(bar_rtl, 200, 20); + lv_bar_set_value(bar_rtl, 70, LV_ANIM_OFF); + lv_obj_align(bar_rtl, NULL, LV_ALIGN_CENTER, 0, 30); + lv_obj_add_style(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg); + lv_obj_set_style_content_text(bar_rtl, LV_PART_MAIN, LV_STATE_DEFAULT, "Right to Left base direction"); +} + +#endif diff --git a/examples/widgets/bar/lv_example_bar_6.c b/examples/widgets/bar/lv_example_bar_6.c new file mode 100644 index 000000000..031c50469 --- /dev/null +++ b/examples/widgets/bar/lv_example_bar_6.c @@ -0,0 +1,68 @@ +#include "../../../lvgl.h" +#if LV_USE_BAR + +static void event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(e == LV_EVENT_DRAW_POST_END) { + lv_bar_t * bar = (lv_bar_t *)obj; + + lv_draw_label_dsc_t dsc; + lv_draw_label_dsc_init(&dsc); + dsc.font = LV_THEME_FONT_NORMAL; + + char buf[8]; + lv_snprintf(buf, sizeof(buf), "%d", lv_bar_get_value(obj)); + + lv_point_t txt_size; + lv_txt_get_size(&txt_size, buf, dsc.font, dsc.letter_space, dsc.line_space, LV_COORD_MAX, dsc.flag); + + lv_area_t txt_area; + /*If the indicator is long enough put the text inside on the right*/ + if(lv_area_get_width(&bar->indic_area) > txt_size.x + 20) { + txt_area.x2 = bar->indic_area.x2 - 5; + txt_area.x1 = txt_area.x2 - txt_size.x + 1; + dsc.color = LV_COLOR_WHITE; + } + /*If the indicator is still short put the text out of it on the right */ + else { + txt_area.x1 = bar->indic_area.x2 + 5; + txt_area.x2 = txt_area.x1 + txt_size.x - 1; + dsc.color = LV_COLOR_BLACK; + } + + txt_area.y1 = bar->indic_area.y1 + (lv_area_get_height(&bar->indic_area) - txt_size.y) / 2; + txt_area.y2 = txt_area.y1 + txt_size.y - 1; + + const lv_area_t * clip_area = lv_event_get_param(); + lv_draw_label(&txt_area, clip_area, &dsc, buf, NULL); + } +} + +/** + * Custom drawer on bar to display the current value + */ +void lv_example_bar_6(void) +{ + static lv_style_t style_bg; + lv_style_init(&style_bg); + lv_style_set_content_ofs_y(&style_bg, -3); + lv_style_set_content_align(&style_bg, LV_ALIGN_OUT_TOP_MID); + + lv_obj_t * bar = lv_bar_create(lv_scr_act(), NULL); + lv_obj_add_event_cb(bar, event_cb, NULL); + lv_obj_set_size(bar, 200, 20); + lv_obj_align(bar, NULL, LV_ALIGN_CENTER, 0, 0); + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, bar); + lv_anim_set_values(&a, 0, 100); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) lv_bar_set_value); + lv_anim_set_time(&a, 2000); + lv_anim_set_playback_time(&a, 2000); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_start(&a); + +} + +#endif diff --git a/examples/widgets/btn/lv_example_btn_1.c b/examples/widgets/btn/lv_example_btn_1.c new file mode 100644 index 000000000..bd12ff4b3 --- /dev/null +++ b/examples/widgets/btn/lv_example_btn_1.c @@ -0,0 +1,35 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_BTN + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_CLICKED) { + printf("Clicked\n"); + } + else if(event == LV_EVENT_VALUE_CHANGED) { + printf("Toggled\n"); + } +} + +void lv_example_btn_1(void) +{ + lv_obj_t * label; + + lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); + lv_obj_add_event_cb(btn1, event_handler, NULL); + lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, -40); + + label = lv_label_create(btn1, NULL); + lv_label_set_text(label, "Button"); + + lv_obj_t * btn2 = lv_btn_create(lv_scr_act(), NULL); + lv_obj_add_event_cb(btn2, event_handler, NULL); + lv_obj_align(btn2, NULL, LV_ALIGN_CENTER, 0, 40); + lv_obj_add_flag(btn2, LV_OBJ_FLAG_CHECKABLE); + lv_obj_set_height(btn2, LV_SIZE_CONTENT); + + label = lv_label_create(btn2, NULL); + lv_label_set_text(label, "Toggle"); +} +#endif diff --git a/examples/widgets/btn/lv_example_btn_1.py b/examples/widgets/btn/lv_example_btn_1.py new file mode 100644 index 000000000..007821e65 --- /dev/null +++ b/examples/widgets/btn/lv_example_btn_1.py @@ -0,0 +1,21 @@ +def event_handler(obj, event): + if event == lv.EVENT.CLICKED: + print("Clicked") + +btn1 = lv.btn(lv.scr_act()) +btn1.set_event_cb(event_handler) +btn1.align(None, lv.ALIGN.CENTER, 0, -40) + +label = lv.label(btn1) +label.set_text("Button") + +btn2 = lv.btn(lv.scr_act()) +# callback can be lambda: +btn2.set_event_cb(lambda obj, event: print("Toggled") if event == lv.EVENT.VALUE_CHANGED else None) +btn2.align(None, lv.ALIGN.CENTER, 0, 40) +btn2.set_toggle(True) +btn2.toggle() +btn2.set_fit2(lv.FIT.NONE, lv.FIT.TIGHT) + +label = lv.label(btn2) +label.set_text("Toggled") diff --git a/examples/widgets/btn/lv_example_btn_2.c b/examples/widgets/btn/lv_example_btn_2.c new file mode 100644 index 000000000..c66f603e2 --- /dev/null +++ b/examples/widgets/btn/lv_example_btn_2.c @@ -0,0 +1,52 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_BTN + +/** + * Style a button from scratch + */ +void lv_example_btn_2(void) +{ + + static lv_style_t style; + static lv_style_t style_pr; + lv_style_init(&style); + lv_style_init(&style_pr); + + /*Init the default style*/ + lv_style_set_radius(&style, 3); + + lv_style_set_bg_opa(&style, LV_OPA_70); + lv_style_set_bg_color(&style, LV_COLOR_BLUE); + lv_style_set_bg_grad_color(&style, LV_COLOR_AQUA); + lv_style_set_bg_grad_dir(&style, LV_GRAD_DIR_VER); + + lv_style_set_border_opa(&style, LV_OPA_40); + lv_style_set_border_width(&style, 2); + lv_style_set_border_color(&style, LV_COLOR_GRAY); + + lv_style_set_shadow_width(&style, 8); + lv_style_set_shadow_color(&style, LV_COLOR_GRAY); + lv_style_set_shadow_ofs_x(&style, 8); + lv_style_set_shadow_ofs_y(&style, 8); + + lv_style_set_text_color(&style, LV_COLOR_WHITE); + + /*Init the pressed style*/ + lv_style_set_shadow_ofs_x(&style_pr, 4); + lv_style_set_shadow_ofs_y(&style_pr, 4); + lv_style_set_color_filter_cb(&style_pr, lv_color_darken); /*Darken every color*/ + lv_style_set_color_filter_opa(&style_pr, LV_OPA_30); + + lv_obj_t * btn1 = lv_btn_create(lv_scr_act(), NULL); + lv_obj_remove_style(btn1, LV_PART_ANY, LV_STATE_ANY, NULL); + lv_obj_add_style(btn1, LV_PART_MAIN, LV_STATE_DEFAULT, &style); + lv_obj_add_style(btn1, LV_PART_MAIN, LV_STATE_PRESSED, &style_pr); + lv_obj_align(btn1, NULL, LV_ALIGN_CENTER, 0, 0); + + lv_obj_t * label = lv_label_create(btn1, NULL); + lv_label_set_text(label, "Button"); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + +} +#endif diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c new file mode 100644 index 000000000..d8cebf0a8 --- /dev/null +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_1.c @@ -0,0 +1,31 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_BTNMATRIX + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + uint32_t id = lv_btnmatrix_get_active_btn(obj); + const char * txt = lv_btnmatrix_get_btn_text(obj, id); + + printf("%s was pressed\n", txt); + } +} + + +static const char * btnm_map[] = {"1", "2", "3", "4", "5", "\n", + "6", "7", "8", "9", "0", "\n", + "Action1", "Action2", ""}; + +void lv_example_btnmatrix_1(void) +{ + lv_obj_t * btnm1 = lv_btnmatrix_create(lv_scr_act(), NULL); + lv_btnmatrix_set_map(btnm1, btnm_map); + lv_btnmatrix_set_btn_width(btnm1, 10, 2); /*Make "Action1" twice as wide as "Action2"*/ + lv_btnmatrix_set_btn_ctrl(btnm1, 10, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_set_btn_ctrl(btnm1, 11, LV_BTNMATRIX_CTRL_CHECKED); + lv_obj_align(btnm1, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(btnm1, event_handler, NULL); +} + +#endif diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_1.py b/examples/widgets/btnmatrix/lv_example_btnmatrix_1.py new file mode 100644 index 000000000..2cf684966 --- /dev/null +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_1.py @@ -0,0 +1,14 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + txt = obj.get_active_btn_text() + print("%s was pressed" % txt) + +btnm_map = ["1", "2", "3", "4", "5", "\n", + "6", "7", "8", "9", "0", "\n", + "Action1", "Action2", ""] + +btnm1 = lv.btnm(lv.scr_act()) +btnm1.set_map(btnm_map) +btnm1.set_btn_width(10, 2) # Make "Action1" twice as wide as "Action2" +btnm1.align(None, lv.ALIGN.CENTER, 0, 0) +btnm1.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c new file mode 100644 index 000000000..387d68eff --- /dev/null +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_2.c @@ -0,0 +1,71 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_BTNMATRIX + + +void event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(e == LV_EVENT_DRAW_PART_BEGIN) { + lv_obj_draw_hook_dsc_t * dsc = lv_event_get_param(); + + /*Change the draw descriptor the 2nd button */ + if(dsc->id == 1) { + dsc->rect_dsc->radius = 0; + if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = LV_COLOR_NAVY; + else dsc->rect_dsc->bg_color = LV_COLOR_BLUE; + + dsc->rect_dsc->shadow_width = 6; + dsc->rect_dsc->shadow_ofs_x = 3; + dsc->rect_dsc->shadow_ofs_y = 3; + dsc->label_dsc->color = LV_COLOR_WHITE; + } + /*Change the draw descriptor the 3rd button */ + else if(dsc->id == 2) { + dsc->rect_dsc->radius = LV_RADIUS_CIRCLE; + if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) dsc->rect_dsc->bg_color = LV_COLOR_MAROON; + else dsc->rect_dsc->bg_color = LV_COLOR_RED; + + dsc->label_dsc->color = LV_COLOR_WHITE; + } + else if(dsc->id == 3) { + dsc->label_dsc->opa = LV_OPA_TRANSP; /*Hide the text if any*/ + + } + } + if(e == LV_EVENT_DRAW_PART_END) { + lv_obj_draw_hook_dsc_t * dsc = lv_event_get_param(); + + /*Add custom content to the 4th button when the button itself was drawn*/ + if(dsc->id == 3) { + LV_IMG_DECLARE(img_star); + lv_img_header_t header; + lv_res_t res = lv_img_decoder_get_info(&img_star, &header); + if(res != LV_RES_OK) return; + + lv_area_t a; + a.x1 = dsc->draw_area->x1 + (lv_area_get_width(dsc->draw_area) - header.w) / 2; + a.x2 = a.x1 + header.w - 1; + a.y1 = dsc->draw_area->y1 + (lv_area_get_height(dsc->draw_area) - header.h) / 2; + a.y2 = a.y1 + header.h - 1; + + lv_draw_img_dsc_t img_draw_dsc; + lv_draw_img_dsc_init(&img_draw_dsc); + img_draw_dsc.recolor = LV_COLOR_BLACK; + if(lv_btnmatrix_get_pressed_btn(obj) == dsc->id) img_draw_dsc.recolor_opa = LV_OPA_30; + + lv_draw_img(&a, dsc->clip_area, &img_star, &img_draw_dsc); + } + } +} + +/** + * Add custom drawer to the button matrix to c + */ +void lv_example_btnmatrix_2(void) +{ + lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL); + lv_obj_add_event_cb(btnm, event_cb, NULL); + lv_obj_align(btnm, NULL, LV_ALIGN_CENTER, 0, 0); +} + +#endif diff --git a/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c b/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c new file mode 100644 index 000000000..38a258e13 --- /dev/null +++ b/examples/widgets/btnmatrix/lv_example_btnmatrix_3.c @@ -0,0 +1,71 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_BTNMATRIX + + +static void event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(e == LV_EVENT_VALUE_CHANGED) { + uint32_t id = lv_btnmatrix_get_active_btn(obj); + bool prev = id == 0 ? true : false; + bool next = id == 6 ? true : false; + if(prev || next) { + /*Find the checked button*/ + uint32_t i; + for(i = 1; i < 7; i++) { + if(lv_btnmatrix_has_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED)) break; + } + + if(prev && i > 1) i--; + else if(next && i < 5) i++; + + lv_btnmatrix_set_btn_ctrl(obj, i, LV_BTNMATRIX_CTRL_CHECKED); + } + } +} + +/** + * Make a button group + */ +void lv_example_btnmatrix_3(void) +{ + static lv_style_t style_bg; + lv_style_init(&style_bg); + lv_style_set_pad_all(&style_bg, 0); + lv_style_set_pad_gap(&style_bg, 0); + lv_style_set_clip_corner(&style_bg, true); + lv_style_set_radius(&style_bg, LV_RADIUS_CIRCLE); + lv_style_set_border_width(&style_bg, 0); + + + static lv_style_t style_btn; + lv_style_init(&style_btn); + lv_style_set_radius(&style_btn, 0); + lv_style_set_border_width(&style_btn, 1); + lv_style_set_border_opa(&style_btn, LV_OPA_50); + lv_style_set_border_color(&style_btn, LV_COLOR_GRAY); + lv_style_set_border_side(&style_btn, LV_BORDER_SIDE_INTERNAL); + lv_style_set_radius(&style_btn, 0); + + static const char * map[] = {LV_SYMBOL_LEFT, "1", "2", "3", "4", "5", LV_SYMBOL_RIGHT, ""}; + + lv_obj_t * btnm = lv_btnmatrix_create(lv_scr_act(), NULL); + lv_btnmatrix_set_map(btnm, map); + lv_obj_add_style(btnm, LV_PART_MAIN, LV_STATE_DEFAULT, &style_bg); + lv_obj_add_style(btnm, LV_PART_ITEMS, LV_STATE_DEFAULT, &style_btn); + lv_obj_add_event_cb(btnm, event_cb, NULL); + lv_obj_set_size(btnm, 225, 35); + + /*Allow selecting on one number at time*/ + lv_btnmatrix_set_btn_ctrl_all(btnm, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_clear_btn_ctrl(btnm, 0, LV_BTNMATRIX_CTRL_CHECKABLE); + lv_btnmatrix_clear_btn_ctrl(btnm, 6, LV_BTNMATRIX_CTRL_CHECKABLE); + + lv_btnmatrix_set_one_checked(btnm, true); + lv_btnmatrix_set_btn_ctrl(btnm, 1, LV_BTNMATRIX_CTRL_CHECKED); + + lv_obj_align(btnm, NULL, LV_ALIGN_CENTER, 0, 0); + +} + +#endif diff --git a/examples/widgets/calendar/lv_example_calendar_1.c b/examples/widgets/calendar/lv_example_calendar_1.c new file mode 100644 index 000000000..8f39ea0f1 --- /dev/null +++ b/examples/widgets/calendar/lv_example_calendar_1.c @@ -0,0 +1,55 @@ +#include "../../../lvgl.h" +#include + +#if LV_USE_CALENDAR + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + lv_calendar_date_t date; + if(lv_calendar_get_pressed_date(obj, &date)) { + printf("Clicked date: %02d.%02d.%d\n", date.day, date.month, date.year); + } + } +} + +void lv_example_calendar_1(void) +{ + lv_obj_t * calendar = lv_calendar_create(lv_scr_act()); + lv_obj_set_size(calendar, 180, 180); + lv_obj_align(calendar, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(calendar, event_handler, NULL); + + /*Set today's date*/ + lv_calendar_date_t today; + today.year = 2021; + today.month = 02; + today.day = 23; + + lv_calendar_set_today_date(calendar, &today); + lv_calendar_set_showed_date(calendar, &today); + + /*Highlight a few days*/ + static lv_calendar_date_t highlighted_days[3]; /*Only its pointer will be saved so should be static*/ + highlighted_days[0].year = 2020; + highlighted_days[0].month = 10; + highlighted_days[0].day = 6; + + highlighted_days[1].year = 2020; + highlighted_days[1].month = 10; + highlighted_days[1].day = 11; + + highlighted_days[2].year = 2020; + highlighted_days[2].month = 11; + highlighted_days[2].day = 22; + + lv_calendar_set_highlighted_dates(calendar, highlighted_days, 3); + +#if LV_USE_CALENDAR_HEADER_ARROW + lv_obj_t * h = lv_calendar_header_arrow_create(lv_scr_act(), calendar, 25); + lv_obj_align(h, NULL, LV_ALIGN_IN_TOP_MID, 0, 5); + lv_obj_align(calendar, h, LV_ALIGN_OUT_BOTTOM_MID, 0, 0); +#endif +} + +#endif diff --git a/examples/widgets/canvas/lv_example_canvas_1.c b/examples/widgets/canvas/lv_example_canvas_1.c new file mode 100644 index 000000000..c54c72829 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_1.c @@ -0,0 +1,53 @@ +#include "../../../lvgl.h" +#if LV_USE_CANVAS + + +#define CANVAS_WIDTH 200 +#define CANVAS_HEIGHT 150 + +void lv_example_canvas_1(void) +{ + lv_draw_rect_dsc_t rect_dsc; + lv_draw_rect_dsc_init(&rect_dsc); + rect_dsc.radius = 10; + rect_dsc.bg_opa = LV_OPA_COVER; + rect_dsc.bg_grad_dir = LV_GRAD_DIR_HOR; + rect_dsc.bg_color = LV_COLOR_RED; + rect_dsc.bg_grad_color = LV_COLOR_BLUE; + rect_dsc.border_width = 2; + rect_dsc.border_opa = LV_OPA_90; + rect_dsc.border_color = LV_COLOR_WHITE; + rect_dsc.shadow_width = 5; + rect_dsc.shadow_ofs_x = 5; + rect_dsc.shadow_ofs_y = 5; + + lv_draw_label_dsc_t label_dsc; + lv_draw_label_dsc_init(&label_dsc); + label_dsc.color = LV_COLOR_YELLOW; + + static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_TRUE_COLOR(CANVAS_WIDTH, CANVAS_HEIGHT)]; + + lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL); + lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_TRUE_COLOR); + lv_obj_align(canvas, NULL, LV_ALIGN_CENTER, 0, 0); + lv_canvas_fill_bg(canvas, LV_COLOR_SILVER, LV_OPA_COVER); + + lv_canvas_draw_rect(canvas, 70, 60, 100, 70, &rect_dsc); + + lv_canvas_draw_text(canvas, 40, 20, 100, &label_dsc, "Some text on text canvas"); + + /* Test the rotation. It requires an other buffer where the orignal image is stored. + * So copy the current image to buffer and rotate it to the canvas */ + static lv_color_t cbuf_tmp[CANVAS_WIDTH * CANVAS_HEIGHT]; + memcpy(cbuf_tmp, cbuf, sizeof(cbuf_tmp)); + lv_img_dsc_t img; + img.data = (void *)cbuf_tmp; + img.header.cf = LV_IMG_CF_TRUE_COLOR; + img.header.w = CANVAS_WIDTH; + img.header.h = CANVAS_HEIGHT; + + lv_canvas_fill_bg(canvas, LV_COLOR_SILVER, LV_OPA_COVER); + lv_canvas_transform(canvas, &img, 30, LV_IMG_ZOOM_NONE, 0, 0, CANVAS_WIDTH / 2, CANVAS_HEIGHT / 2, true); +} + +#endif diff --git a/examples/widgets/canvas/lv_example_canvas_1.py b/examples/widgets/canvas/lv_example_canvas_1.py new file mode 100644 index 000000000..116784164 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_1.py @@ -0,0 +1,38 @@ +CANVAS_WIDTH = 200 +CANVAS_HEIGHT = 150 + +style = lv.style_t() +lv.style_copy(style, lv.style_plain) +style.body.main_color = lv.color_make(0xFF,0,0) +style.body.grad_color = lv.color_make(0x80,0,0) +style.body.radius = 4 +style.body.border.width = 2 +style.body.border.color = lv.color_make(0xFF,0xFF,0xFF) +style.body.shadow.color = lv.color_make(0xFF,0xFF,0xFF) +style.body.shadow.width = 4 +style.line.width = 2 +style.line.color = lv.color_make(0,0,0) +style.text.color = lv.color_make(0,0,0xFF) + +# CF.TRUE_COLOR requires 4 bytes per pixel +cbuf = bytearray(CANVAS_WIDTH * CANVAS_HEIGHT * 4) + +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.TRUE_COLOR) +canvas.align(None, lv.ALIGN.CENTER, 0, 0) +canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0)) + +canvas.draw_rect(70, 60, 100, 70, style) + +canvas.draw_text(40, 20, 100, style, "Some text on text canvas", lv.label.ALIGN.LEFT) + +# Test the rotation. It requires an other buffer where the orignal image is stored. +# So copy the current image to buffer and rotate it to the canvas +img = lv.img_dsc_t() +img.data = cbuf[:] +img.header.cf = lv.img.CF.TRUE_COLOR +img.header.w = CANVAS_WIDTH +img.header.h = CANVAS_HEIGHT + +canvas.fill_bg(lv.color_make(0xC0, 0xC0, 0xC0)) +canvas.rotate(img, 30, 0, 0, CANVAS_WIDTH // 2, CANVAS_HEIGHT // 2) \ No newline at end of file diff --git a/examples/widgets/canvas/lv_example_canvas_2.c b/examples/widgets/canvas/lv_example_canvas_2.c new file mode 100644 index 000000000..9ea0a6d8d --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_2.c @@ -0,0 +1,44 @@ +#include "../../../lvgl.h" +#if LV_USE_CANVAS + +#define CANVAS_WIDTH 50 +#define CANVAS_HEIGHT 50 + +/** + * Create a transparent canvas with Chroma keying and indexed color format (palette). + */ +void lv_example_canvas_2(void) +{ + /*Create a button to better see the transparency*/ + lv_btn_create(lv_scr_act(), NULL); + + /*Create a buffer for the canvas*/ + static lv_color_t cbuf[LV_CANVAS_BUF_SIZE_INDEXED_1BIT(CANVAS_WIDTH, CANVAS_HEIGHT)]; + + /*Create a canvas and initialize its the palette*/ + lv_obj_t * canvas = lv_canvas_create(lv_scr_act(), NULL); + lv_canvas_set_buffer(canvas, cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, LV_IMG_CF_INDEXED_1BIT); + lv_canvas_set_palette(canvas, 0, LV_COLOR_CHROMA_KEY); + lv_canvas_set_palette(canvas, 1, LV_COLOR_RED); + + /*Create colors with the indices of the palette*/ + lv_color_t c0; + lv_color_t c1; + + c0.full = 0; + c1.full = 1; + + /*Red background (There is no dedicated alpha channel in indexed images so LV_OPA_COVER is ignored)*/ + lv_canvas_fill_bg(canvas, c1, LV_OPA_COVER); + + /*Create hole on the canvas*/ + uint32_t x; + uint32_t y; + for( y = 10; y < 30; y++) { + for( x = 5; x < 20; x++) { + lv_canvas_set_px(canvas, x, y, c0); + } + } + +} +#endif diff --git a/examples/widgets/canvas/lv_example_canvas_2.py b/examples/widgets/canvas/lv_example_canvas_2.py new file mode 100644 index 000000000..2ebe8f4f4 --- /dev/null +++ b/examples/widgets/canvas/lv_example_canvas_2.py @@ -0,0 +1,41 @@ +# Create a transparent canvas with Chroma keying and indexed color format (palette). + +CANVAS_WIDTH = 50 +CANVAS_HEIGHT = 50 + +def bufsize(w, h, bits, indexed=False): + """this function determines required buffer size + depending on the color depth""" + size = (w * bits // 8 + 1) * h + if indexed: + # + 4 bytes per palette color + size += 4 * (2**bits) + return size + +# Create a button to better see the transparency +lv.btn(lv.scr_act()) + +# Create a buffer for the canvas +cbuf = bytearray(bufsize(CANVAS_WIDTH, CANVAS_HEIGHT, 1, indexed=True)) + +# Create a canvas and initialize its the palette +canvas = lv.canvas(lv.scr_act()) +canvas.set_buffer(cbuf, CANVAS_WIDTH, CANVAS_HEIGHT, lv.img.CF.INDEXED_1BIT) +# transparent color can be defined in lv_conf.h and set to pure green by default +canvas.set_palette(0, lv.color_make(0x00, 0xFF, 0x00)) +canvas.set_palette(1, lv.color_make(0xFF, 0x00, 0x00)) + +# Create colors with the indices of the palette +c0 = lv.color_t() +c1 = lv.color_t() + +c0.full = 0 +c1.full = 1 + +# Transparent background +canvas.fill_bg(c1) + +# Create hole on the canvas +for y in range(10,30): + for x in range(5, 20): + canvas.set_px(x, y, c0) diff --git a/examples/widgets/chart/lv_example_chart_1.c b/examples/widgets/chart/lv_example_chart_1.c new file mode 100644 index 000000000..9947cc1a0 --- /dev/null +++ b/examples/widgets/chart/lv_example_chart_1.c @@ -0,0 +1,44 @@ +#include "../../../lvgl.h" +#if LV_USE_CHART + +void lv_example_chart_1(void) +{ + /*Create a chart*/ + lv_obj_t * chart; + chart = lv_chart_create(lv_scr_act(), NULL); + lv_obj_set_size(chart, 200, 150); + lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0); + lv_chart_set_type(chart, LV_CHART_TYPE_LINE); /*Show lines and points too*/ + + /*Add two data series*/ + lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y); + lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN, LV_CHART_AXIS_SECONDARY_Y); + + /*Set the next points on 'ser1'*/ + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 30); + lv_chart_set_next_value(chart, ser1, 70); + lv_chart_set_next_value(chart, ser1, 90); + + /*Directly set points on 'ser2'*/ + ser2->points[0] = 90; + ser2->points[1] = 70; + ser2->points[2] = 65; + ser2->points[3] = 65; + ser2->points[4] = 65; + ser2->points[5] = 65; + ser2->points[6] = 65; + ser2->points[7] = 65; + ser2->points[8] = 65; + ser2->points[9] = 65; + + lv_chart_refresh(chart); /*Required after direct set*/ +} + +#endif diff --git a/examples/widgets/chart/lv_example_chart_1.py b/examples/widgets/chart/lv_example_chart_1.py new file mode 100644 index 000000000..f2250ff78 --- /dev/null +++ b/examples/widgets/chart/lv_example_chart_1.py @@ -0,0 +1,19 @@ +# Create a chart +chart = lv.chart(lv.scr_act()) +chart.set_size(200, 150) +chart.align(None, lv.ALIGN.CENTER, 0, 0) +chart.set_type(lv.chart.TYPE.POINT | lv.chart.TYPE.LINE) # Show lines and points too +chart.set_series_opa(lv.OPA._70) # Opacity of the data series +chart.set_series_width(4) # Line width and point radious + +chart.set_range(0, 100) + +# Add two data series +ser1 = chart.add_series(lv.color_make(0xFF,0,0)) +ser2 = chart.add_series(lv.color_make(0,0x80,0)) + +# Set points on 'dl1' +chart.set_points(ser1, [10, 10, 10, 10, 10, 10, 10, 30, 70, 90]) + +# Set points on 'dl2' +chart.set_points(ser2, [90, 70, 65, 65, 65, 65, 65, 65, 65, 65]) \ No newline at end of file diff --git a/examples/widgets/chart/lv_example_chart_2.c b/examples/widgets/chart/lv_example_chart_2.c new file mode 100644 index 000000000..693b34cbd --- /dev/null +++ b/examples/widgets/chart/lv_example_chart_2.c @@ -0,0 +1,82 @@ +#include "../../../lvgl.h" +#if LV_USE_CHART + +static lv_obj_t * chart1; +static lv_chart_series_t * ser1; +static lv_chart_series_t * ser2; + +static void event_cb(lv_obj_t * obj, lv_event_t e) +{ + /*Add the faded area before the lines are drawn */ + if(e == LV_EVENT_DRAW_PART_BEGIN) { + lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param(); + if(hook_dsc->part != LV_PART_ITEMS) return; + if(!hook_dsc->p1 || !hook_dsc->p2) return; + + /*Add a line mask that keeps the area below the line*/ + lv_draw_mask_line_param_t line_mask_param; + lv_draw_mask_line_points_init(&line_mask_param, hook_dsc->p1->x, hook_dsc->p1->y, hook_dsc->p2->x, hook_dsc->p2->y, LV_DRAW_MASK_LINE_SIDE_BOTTOM); + int16_t line_mask_id = lv_draw_mask_add(&line_mask_param, NULL); + + /*Add a fade effect: transparent bottom covering top*/ + lv_coord_t h = lv_obj_get_height(obj); + lv_draw_mask_fade_param_t fade_mask_param; + lv_draw_mask_fade_init(&fade_mask_param, &obj->coords, LV_OPA_COVER, obj->coords.y1 + h / 8, LV_OPA_TRANSP,obj->coords.y2); + int16_t fade_mask_id = lv_draw_mask_add(&fade_mask_param, NULL); + + /*Draw a rectangle that will be affected by the mask*/ + lv_draw_rect_dsc_t draw_rect_dsc; + lv_draw_rect_dsc_init(&draw_rect_dsc); + draw_rect_dsc.bg_opa = LV_OPA_20; + draw_rect_dsc.bg_color = hook_dsc->line_dsc->color; + + lv_area_t a; + a.x1 = hook_dsc->p1->x; + a.x2 = hook_dsc->p2->x - 1; + a.y1 = LV_MIN(hook_dsc->p1->y, hook_dsc->p2->y); + a.y2 = obj->coords.y2; + lv_draw_rect(&a, hook_dsc->clip_area, &draw_rect_dsc); + + /*Remove the masks*/ + lv_draw_mask_remove_id(line_mask_id); + lv_draw_mask_remove_id(fade_mask_id); + } +} + +static void add_data(lv_timer_t * timer) +{ + static uint32_t cnt = 0; + lv_chart_set_next_value(chart1, ser1, lv_rand(20, 90)); + + if(cnt % 4 == 0) lv_chart_set_next_value(chart1, ser2, lv_rand(40, 60)); + + cnt++; +} + +/** + * Add a faded area effect to the line chart + */ +void lv_example_chart_2(void) +{ + /*Create a chart1*/ + chart1 = lv_chart_create(lv_scr_act(), NULL); + lv_obj_set_size(chart1, 200, 150); + lv_obj_align(chart1, NULL, LV_ALIGN_CENTER, 0, 0); + lv_chart_set_type(chart1, LV_CHART_TYPE_LINE); /*Show lines and points too*/ + + lv_obj_add_event_cb(chart1, event_cb, NULL); + + /*Add two data series*/ + ser1 = lv_chart_add_series(chart1, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y); + ser2 = lv_chart_add_series(chart1, LV_COLOR_BLUE, LV_CHART_AXIS_SECONDARY_Y); + + uint32_t i; + for(i = 0; i < 10; i++) { + lv_chart_set_next_value(chart1, ser1, lv_rand(20, 90)); + lv_chart_set_next_value(chart1, ser2, lv_rand(30, 70)); + } + + lv_timer_create(add_data, 200, NULL); +} + +#endif diff --git a/examples/widgets/chart/lv_example_chart_3.c b/examples/widgets/chart/lv_example_chart_3.c new file mode 100644 index 000000000..bf92818df --- /dev/null +++ b/examples/widgets/chart/lv_example_chart_3.c @@ -0,0 +1,75 @@ +#include "../../../lvgl.h" +#if LV_USE_CHART + +static void event_cb(lv_obj_t * chart, lv_event_t e) +{ + if(e == LV_EVENT_DRAW_PART_BEGIN) { + lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param(); + if(hook_dsc->part == LV_PART_MARKER && hook_dsc->sub_part_id == LV_CHART_AXIS_X) { + const char * month[] = {"Jan", "Febr", "March", "Apr", "May", "Jun", "July", "Aug", "Sept", "Oct", "Nov", "Dec"}; + lv_snprintf(hook_dsc->text, sizeof(hook_dsc->text), "%s", month[hook_dsc->id]); + } + } +} + +/** + * Add ticks and labels to the axis and demonstrate scrolling + */ +void lv_example_chart_3(void) +{ + /*Create a chart*/ + lv_obj_t * chart; + chart = lv_chart_create(lv_scr_act(), NULL); + lv_obj_set_size(chart, 200, 150); + lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0); + lv_chart_set_type(chart, LV_CHART_TYPE_BAR); + lv_chart_set_range(chart, LV_CHART_AXIS_PRIMARY_Y, 0, 100); + lv_chart_set_range(chart, LV_CHART_AXIS_SECONDARY_Y, 0, 400); + lv_chart_set_point_count(chart, 12); + lv_obj_add_event_cb(chart, event_cb, NULL); + + /*Add ticks and label to every axis*/ + lv_chart_set_axis_tick(chart, LV_CHART_AXIS_X, 10, 5, 12, 3, true, 40); + lv_chart_set_axis_tick(chart, LV_CHART_AXIS_PRIMARY_Y, 10, 5, 6, 2, true, 50); + lv_chart_set_axis_tick(chart, LV_CHART_AXIS_SECONDARY_Y, 10, 5, 3, 4, true, 50); + + /*Zoom in a little in X*/ + lv_chart_set_zoom_x(chart, 800); + + /*Add two data series*/ + lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y); + lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN, LV_CHART_AXIS_SECONDARY_Y); + + /*Set the next points on 'ser1'*/ + lv_chart_set_next_value(chart, ser1, 31); + lv_chart_set_next_value(chart, ser1, 66); + lv_chart_set_next_value(chart, ser1, 10); + lv_chart_set_next_value(chart, ser1, 89); + lv_chart_set_next_value(chart, ser1, 63); + lv_chart_set_next_value(chart, ser1, 56); + lv_chart_set_next_value(chart, ser1, 32); + lv_chart_set_next_value(chart, ser1, 35); + lv_chart_set_next_value(chart, ser1, 57); + lv_chart_set_next_value(chart, ser1, 85); + lv_chart_set_next_value(chart, ser1, 22); + lv_chart_set_next_value(chart, ser1, 58); + + lv_coord_t * ser2_array = lv_chart_get_array(chart, ser2); + /*Directly set points on 'ser2'*/ + ser2_array[0] = 92; + ser2_array[1] = 71; + ser2_array[2] = 61; + ser2_array[3] = 15; + ser2_array[4] = 21; + ser2_array[5] = 35; + ser2_array[6] = 35; + ser2_array[7] = 58; + ser2_array[8] = 31; + ser2_array[9] = 53; + ser2_array[10] = 33; + ser2_array[11] = 73; + + lv_chart_refresh(chart); /*Required after direct set*/ +} + +#endif diff --git a/examples/widgets/chart/lv_example_chart_4.c b/examples/widgets/chart/lv_example_chart_4.c new file mode 100644 index 000000000..ce9331455 --- /dev/null +++ b/examples/widgets/chart/lv_example_chart_4.c @@ -0,0 +1,80 @@ +#include "../../../lvgl.h" +#if LV_USE_CHART + + +static void event_cb(lv_obj_t * chart, lv_event_t e) +{ + if(e == LV_EVENT_VALUE_CHANGED) { + lv_obj_invalidate(chart); + } + if(e == LV_EVENT_REFR_EXT_DRAW_SIZE) { + lv_coord_t * s = lv_event_get_param(); + *s = LV_MAX(*s, 20); + } + else if(e == LV_EVENT_DRAW_POST_END) { + int32_t id = lv_chart_get_pressed_point(chart); + if(id < 0) return; + + printf("Selected point %d\n", id); + + lv_chart_series_t * ser = lv_chart_get_series_next(chart, NULL); + while(ser) { + lv_point_t p; + lv_chart_get_point_pos_by_id(chart, ser, id, &p); + + lv_coord_t * y_array = lv_chart_get_array(chart, ser); + lv_coord_t value = y_array[id]; + + char buf[16]; + lv_snprintf(buf, sizeof(buf), "$%d", value); + + lv_draw_rect_dsc_t draw_rect_dsc; + lv_draw_rect_dsc_init(&draw_rect_dsc); + draw_rect_dsc.bg_color = LV_COLOR_BLACK; + draw_rect_dsc.bg_opa = LV_OPA_50; + draw_rect_dsc.radius = 3; + draw_rect_dsc.content_text = buf; + draw_rect_dsc.content_color = LV_COLOR_WHITE; + + lv_area_t a; + a.x1 = chart->coords.x1 + p.x - 20; + a.x2 = chart->coords.x1 + p.x + 20; + a.y1 = chart->coords.y1 + p.y - 30; + a.y2 = chart->coords.y1 + p.y - 10; + + const lv_area_t * clip_area = lv_event_get_param(); + lv_draw_rect(&a, clip_area, &draw_rect_dsc); + + ser = lv_chart_get_series_next(chart, ser); + } + } +} + +/** + * Add ticks and labels to the axis and demonstrate scrolling + */ +void lv_example_chart_4(void) +{ + /*Create a chart*/ + lv_obj_t * chart; + chart = lv_chart_create(lv_scr_act(), NULL); + lv_obj_set_size(chart, 200, 150); + lv_obj_align(chart, NULL, LV_ALIGN_CENTER, 0, 0); + + lv_obj_add_event_cb(chart, event_cb, NULL); + lv_obj_refresh_ext_draw_size(chart); + + /*Zoom in a little in X*/ + lv_chart_set_zoom_x(chart, 800); + + /*Add two data series*/ + lv_chart_series_t * ser1 = lv_chart_add_series(chart, LV_COLOR_RED, LV_CHART_AXIS_PRIMARY_Y); + lv_chart_series_t * ser2 = lv_chart_add_series(chart, LV_COLOR_GREEN, LV_CHART_AXIS_PRIMARY_Y); + uint32_t i; + for(i = 0; i < 10; i++) { + lv_chart_set_next_value(chart, ser1, lv_rand(60,90)); + lv_chart_set_next_value(chart, ser2, lv_rand(10,40)); + } +} + +#endif diff --git a/examples/widgets/checkbox/lv_example_checkbox_1.c b/examples/widgets/checkbox/lv_example_checkbox_1.c new file mode 100644 index 000000000..65281508a --- /dev/null +++ b/examples/widgets/checkbox/lv_example_checkbox_1.c @@ -0,0 +1,44 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_CHECKBOX + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + const char * txt = lv_checkbox_get_text(obj); + const char * state = lv_obj_get_state(obj) & LV_STATE_CHECKED ? "Checked" : "Unchecked"; + printf("%s: %s\n", txt, state); + } +} + +void lv_example_checkbox_1(void) +{ + static lv_flex_t flex_center; + lv_flex_init(&flex_center); + lv_flex_set_flow(&flex_center, LV_FLEX_FLOW_COLUMN); + lv_flex_set_place(&flex_center, LV_FLEX_PLACE_CENTER, LV_FLEX_PLACE_START, LV_FLEX_PLACE_CENTER); + + lv_obj_set_layout(lv_scr_act(), &flex_center); + + lv_obj_t * cb; + cb = lv_checkbox_create(lv_scr_act(), NULL); + lv_checkbox_set_text(cb, "Apple"); + lv_obj_add_event_cb(cb, event_handler, NULL); + + cb = lv_checkbox_create(lv_scr_act(), NULL); + lv_checkbox_set_text(cb, "Banana"); + lv_obj_add_state(cb, LV_STATE_CHECKED); + lv_obj_add_event_cb(cb, event_handler, NULL); + + cb = lv_checkbox_create(lv_scr_act(), NULL); + lv_checkbox_set_text(cb, "Lemon"); + lv_obj_add_state(cb, LV_STATE_DISABLED); + lv_obj_add_event_cb(cb, event_handler, NULL); + + cb = lv_checkbox_create(lv_scr_act(), NULL); + lv_obj_add_state(cb, LV_STATE_CHECKED | LV_STATE_DISABLED); + lv_checkbox_set_text(cb, "Melon"); + lv_obj_add_event_cb(cb, event_handler, NULL); +} + +#endif diff --git a/examples/widgets/checkbox/lv_example_checkbox_1.py b/examples/widgets/checkbox/lv_example_checkbox_1.py new file mode 100644 index 000000000..d0ffb7e33 --- /dev/null +++ b/examples/widgets/checkbox/lv_example_checkbox_1.py @@ -0,0 +1,8 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + print("State: %s" % ("Checked" if obj.is_checked() else "Unchecked")) + +cb = lv.cb(lv.scr_act()) +cb.set_text("I agree to terms and conditions.") +cb.align(None, lv.ALIGN.CENTER, 0, 0) +cb.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/colorwheel/lv_example_colorwheel_1.c b/examples/widgets/colorwheel/lv_example_colorwheel_1.c new file mode 100644 index 000000000..ff6d748c3 --- /dev/null +++ b/examples/widgets/colorwheel/lv_example_colorwheel_1.c @@ -0,0 +1,13 @@ +#include "../../../lvgl.h" +#if LV_USE_COLORWHEEL + +void lv_example_colorwheel_1(void) +{ + lv_obj_t * cw; + + cw = lv_colorwheel_create(lv_scr_act(), true); + lv_obj_set_size(cw, 200, 200); + lv_obj_align(cw, NULL, LV_ALIGN_CENTER, 0, 0); +} + +#endif diff --git a/examples/widgets/dropdown/lv_example_dropdown_1.c b/examples/widgets/dropdown/lv_example_dropdown_1.c new file mode 100644 index 000000000..6d0db2801 --- /dev/null +++ b/examples/widgets/dropdown/lv_example_dropdown_1.c @@ -0,0 +1,35 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_DROPDOWN + + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + char buf[32]; + lv_dropdown_get_selected_str(obj, buf, sizeof(buf)); + printf("Option: %s\n", buf); + } +} + +void lv_example_dropdown_1(void) +{ + + /*Create a normal drop down list*/ + lv_obj_t * dd = lv_dropdown_create(lv_scr_act(), NULL); + lv_dropdown_set_options(dd, "Apple\n" + "Banana\n" + "Orange\n" + "Cherry\n" + "Grape\n" + "Raspberry\n" + "Melon\n" + "Orange\n" + "Lemon\n" + "Nuts"); + + lv_obj_align(dd, NULL, LV_ALIGN_IN_TOP_MID, 0, 20); + lv_obj_add_event_cb(dd, event_handler, NULL); +} + +#endif diff --git a/examples/widgets/dropdown/lv_example_dropdown_1.py b/examples/widgets/dropdown/lv_example_dropdown_1.py new file mode 100644 index 000000000..da76df517 --- /dev/null +++ b/examples/widgets/dropdown/lv_example_dropdown_1.py @@ -0,0 +1,21 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + option = " "*10 # should be large enough to store the option + obj.get_selected_str(option, len(option)) + # .strip() removes trailing spaces + print("Option: \"%s\"" % option.strip()) + +# Create a drop down list +ddlist = lv.ddlist(lv.scr_act()) +ddlist.set_options("\n".join([ + "Apple", + "Banana", + "Orange", + "Melon", + "Grape", + "Raspberry"])) + +ddlist.set_fix_width(150) +ddlist.set_draw_arrow(True) +ddlist.align(None, lv.ALIGN.IN_TOP_MID, 0, 20) +ddlist.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/dropdown/lv_example_dropdown_2.c b/examples/widgets/dropdown/lv_example_dropdown_2.c new file mode 100644 index 000000000..69cf9b1fe --- /dev/null +++ b/examples/widgets/dropdown/lv_example_dropdown_2.c @@ -0,0 +1,42 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_DROPDOWN + + +/** + * Create a drop down, up, left and right menus + */ +void lv_example_dropdown_2(void) +{ + static const char * opts = "Apple\n" + "Banana\n" + "Orange\n" + "Melon\n" + "Grape\n" + "Raspberry"; + + lv_obj_t * dd; + dd = lv_dropdown_create(lv_scr_act(), NULL); + lv_dropdown_set_options_static(dd, opts); + lv_obj_align(dd, NULL, LV_ALIGN_IN_TOP_MID, 0, 10); + + dd = lv_dropdown_create(lv_scr_act(), NULL); + lv_dropdown_set_options_static(dd, opts); + lv_dropdown_set_dir(dd, LV_DIR_BOTTOM); + lv_dropdown_set_symbol(dd, LV_SYMBOL_UP); + lv_obj_align(dd, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, -10); + + dd = lv_dropdown_create(lv_scr_act(), NULL); + lv_dropdown_set_options_static(dd, opts); + lv_dropdown_set_dir(dd, LV_DIR_RIGHT); + lv_dropdown_set_symbol(dd, LV_SYMBOL_RIGHT); + lv_obj_align(dd, NULL, LV_ALIGN_IN_LEFT_MID, 10, 0); + + dd = lv_dropdown_create(lv_scr_act(), NULL); + lv_dropdown_set_options_static(dd, opts); + lv_dropdown_set_dir(dd, LV_DIR_LEFT); + lv_dropdown_set_symbol(dd, LV_SYMBOL_LEFT); + lv_obj_align(dd, NULL, LV_ALIGN_IN_RIGHT_MID, -10, 0); +} + +#endif diff --git a/examples/widgets/dropdown/lv_example_dropdown_2.py b/examples/widgets/dropdown/lv_example_dropdown_2.py new file mode 100644 index 000000000..e01334c40 --- /dev/null +++ b/examples/widgets/dropdown/lv_example_dropdown_2.py @@ -0,0 +1,23 @@ +# Create a drop UP list by applying auto realign + +# Create a drop down list +ddlist = lv.ddlist(lv.scr_act()) +ddlist.set_options("\n".join([ + "Apple", + "Banana", + "Orange", + "Melon", + "Grape", + "Raspberry"])) + + +ddlist.set_fix_width(150) +ddlist.set_fix_height(150) +ddlist.set_draw_arrow(True) + +# Enable auto-realign when the size changes. +# It will keep the bottom of the ddlist fixed +ddlist.set_auto_realign(True) + +# It will be called automatically when the size changes +ddlist.align(None, lv.ALIGN.IN_BOTTOM_MID, 0, -20) diff --git a/examples/widgets/dropdown/lv_example_dropdown_3.c b/examples/widgets/dropdown/lv_example_dropdown_3.c new file mode 100644 index 000000000..dcfda19ce --- /dev/null +++ b/examples/widgets/dropdown/lv_example_dropdown_3.c @@ -0,0 +1,34 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_DROPDOWN + + +/** + * Create a menu from a drop-down list and show some drop-down list features and styling + */ +void lv_example_dropdown_3(void) +{ + /*Create a drop down list*/ + lv_obj_t * dd = lv_dropdown_create(lv_scr_act(), NULL); + lv_obj_align(dd, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 10); + lv_dropdown_set_options(dd, "New\n" + "Open\n" + "Edit\n" + "Close\n" + "Preferences\n" + "Exit"); + + /*Set a fixed text to display on the button of the drop-down list*/ + lv_dropdown_set_text(dd, "Menu"); + + /*Use a custom image as down icon*/ + LV_IMG_DECLARE(img_caret_down) + lv_dropdown_set_symbol(dd, &img_caret_down); + + /* Remove the style of the selected part on the list. + * In a menu we don't need to show the last clicked item*/ + lv_obj_t * list = lv_dropdown_get_list(dd); + lv_obj_remove_style(list, LV_PART_SELECTED, LV_STATE_DEFAULT, NULL); +} + +#endif diff --git a/examples/widgets/img/index.rst b/examples/widgets/img/index.rst new file mode 100644 index 000000000..5f47ada01 --- /dev/null +++ b/examples/widgets/img/index.rst @@ -0,0 +1,21 @@ +C +^ + +Image from variable and symbol +""""""""""""""""""""""""""""""" + +.. lv_example:: lv_ex_widgets/lv_ex_img/lv_ex_img_1 + :language: c + + +Image recoloring +"""""""""""""""" + +.. lv_example:: lv_ex_widgets/lv_ex_img/lv_ex_img_2 + :language: c + + +MicroPython +^^^^^^^^^^^ + +No examples yet. diff --git a/examples/widgets/img/lv_example_img_1.c b/examples/widgets/img/lv_example_img_1.c new file mode 100644 index 000000000..9241ee7fa --- /dev/null +++ b/examples/widgets/img/lv_example_img_1.c @@ -0,0 +1,18 @@ +#include "../../../lvgl.h" +#if LV_USE_IMG + +/* Find the image here: https://github.com/lvgl/lv_examples/tree/master/assets */ +LV_IMG_DECLARE(img_cogwheel_argb); + +void lv_example_img_1(void) +{ + lv_obj_t * img1 = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(img1, &img_cogwheel_argb); + lv_obj_align(img1, NULL, LV_ALIGN_CENTER, 0, -20); + + lv_obj_t * img2 = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(img2, LV_SYMBOL_OK "Accept"); + lv_obj_align(img2, img1, LV_ALIGN_OUT_BOTTOM_MID, 0, 20); +} + +#endif diff --git a/examples/widgets/img/lv_example_img_1.py b/examples/widgets/img/lv_example_img_1.py new file mode 100644 index 000000000..75325ccc7 --- /dev/null +++ b/examples/widgets/img/lv_example_img_1.py @@ -0,0 +1,29 @@ +from imagetools import get_png_info, open_png + +# Register PNG image decoder +decoder = lv.img.decoder_create() +decoder.info_cb = get_png_info +decoder.open_cb = open_png + +# Create a screen with a draggable image + +with open('cogwheel.png','rb') as f: + png_data = f.read() + +png_img_dsc = lv.img_dsc_t({ + 'data_size': len(png_data), + 'data': png_data +}) + +scr = lv.scr_act() + +# Create an image on the left using the decoder + +# lv.img.cache_set_size(2) +img1 = lv.img(scr) +img1.align(scr, lv.ALIGN.CENTER, 0, -20) +img1.set_src(png_img_dsc) + +img2 = lv.img(scr) +img2.set_src(lv.SYMBOL.OK + "Accept") +img2.align(img1, lv.ALIGN.OUT_BOTTOM_MID, 0, 20) \ No newline at end of file diff --git a/examples/widgets/img/lv_example_img_2.c b/examples/widgets/img/lv_example_img_2.c new file mode 100644 index 000000000..93b6ff9ed --- /dev/null +++ b/examples/widgets/img/lv_example_img_2.c @@ -0,0 +1,64 @@ +#include "../../../lvgl.h" +#if LV_USE_IMG + +static lv_obj_t * create_slider(lv_color_t color); +static void slider_event_cb(lv_obj_t * slider, lv_event_t event); + +static lv_obj_t * red_slider, * green_slider, * blue_slider, * intense_slider; +static lv_obj_t * img1; + + +/** + * Demonstrate runtime image re-coloring + */ +void lv_example_img_2(void) +{ + /*Create 4 sliders to adjust RGB color and re-color intensity*/ + red_slider = create_slider(LV_COLOR_RED); + green_slider = create_slider(LV_COLOR_LIME); + blue_slider = create_slider(LV_COLOR_BLUE); + intense_slider = create_slider(LV_COLOR_GRAY); + + lv_slider_set_value(red_slider, LV_OPA_20, LV_ANIM_OFF); + lv_slider_set_value(green_slider, LV_OPA_90, LV_ANIM_OFF); + lv_slider_set_value(blue_slider, LV_OPA_60, LV_ANIM_OFF); + lv_slider_set_value(intense_slider, LV_OPA_50, LV_ANIM_OFF); + + lv_obj_align(red_slider, NULL, LV_ALIGN_IN_LEFT_MID, 25, 0); + lv_obj_align(green_slider, red_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); + lv_obj_align(blue_slider, green_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); + lv_obj_align(intense_slider, blue_slider, LV_ALIGN_OUT_RIGHT_MID, 25, 0); + + /* Now create the actual image */ + LV_IMG_DECLARE(img_cogwheel_argb); + img1 = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(img1, &img_cogwheel_argb); + lv_obj_align(img1, NULL, LV_ALIGN_IN_RIGHT_MID, -20, 0); + + lv_event_send(intense_slider, LV_EVENT_VALUE_CHANGED, NULL); +} + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + /* Recolor the image based on the sliders' values */ + lv_color_t color = lv_color_make(lv_slider_get_value(red_slider), lv_slider_get_value(green_slider), lv_slider_get_value(blue_slider)); + lv_opa_t intense = lv_slider_get_value(intense_slider); + lv_obj_set_style_img_recolor_opa(img1, LV_PART_MAIN, LV_STATE_DEFAULT, intense); + lv_obj_set_style_img_recolor(img1, LV_PART_MAIN, LV_STATE_DEFAULT, color); + } +} + +static lv_obj_t * create_slider(lv_color_t color) +{ + lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL); + lv_slider_set_range(slider, 0, 255); + lv_obj_set_size(slider, 10, 200); + lv_obj_set_style_bg_color(slider, LV_PART_KNOB, LV_STATE_DEFAULT, color); + lv_obj_set_style_bg_color(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, lv_color_darken(color, LV_OPA_40)); + lv_obj_add_event_cb(slider, slider_event_cb, NULL); + return slider; + +} + +#endif diff --git a/examples/widgets/img/lv_example_img_3.c b/examples/widgets/img/lv_example_img_3.c new file mode 100644 index 000000000..9d83fc36d --- /dev/null +++ b/examples/widgets/img/lv_example_img_3.c @@ -0,0 +1,33 @@ +#include "../../../lvgl.h" +#if LV_USE_IMG + +LV_IMG_DECLARE(img_cogwheel_argb); + +/** + * Show transformations (zoom and rotation) using a pivot point. + */ +void lv_example_img_3(void) +{ + /* Now create the actual image */ + lv_obj_t * img = lv_img_create(lv_scr_act(), NULL); + lv_img_set_src(img, &img_cogwheel_argb); + lv_obj_align(img, NULL, LV_ALIGN_CENTER, 50, 50); + lv_img_set_pivot(img, 0, 0); /*Rotate around the top left corner*/ + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, img); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_angle); + lv_anim_set_values(&a, 0, 3600); + lv_anim_set_time(&a, 5000); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_start(&a); + + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_zoom); + lv_anim_set_values(&a, 128, 256); + lv_anim_set_playback_time(&a, 3000); + lv_anim_start(&a); + +} + +#endif diff --git a/examples/widgets/img/lv_example_img_4.c b/examples/widgets/img/lv_example_img_4.c new file mode 100644 index 000000000..73b588874 --- /dev/null +++ b/examples/widgets/img/lv_example_img_4.c @@ -0,0 +1,36 @@ +#include "../../../lvgl.h" +#if LV_USE_IMG + +LV_IMG_DECLARE(img_skew_strip); + +/** + * Image styling and offset + */ +void lv_example_img_4(void) +{ + static lv_style_t style; + lv_style_init(&style); + lv_style_set_bg_color(&style, LV_COLOR_YELLOW); + lv_style_set_bg_opa(&style, LV_OPA_COVER); + lv_style_set_img_recolor_opa(&style, LV_OPA_COVER); + lv_style_set_img_recolor(&style, LV_COLOR_BLACK); + + lv_obj_t * img = lv_img_create(lv_scr_act(), NULL); + lv_obj_add_style(img, LV_PART_MAIN, LV_STATE_DEFAULT, &style); + lv_img_set_src(img, &img_skew_strip); + lv_obj_set_size(img, 150, 100); + lv_obj_align(img, NULL, LV_ALIGN_CENTER, 0, 0); + + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, img); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_img_set_offset_y); + lv_anim_set_values(&a, 0, 100); + lv_anim_set_time(&a, 3000); + lv_anim_set_playback_time(&a, 500); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_start(&a); + +} + +#endif diff --git a/examples/widgets/keyboard/lv_example_keyboard_1.c b/examples/widgets/keyboard/lv_example_keyboard_1.c new file mode 100644 index 000000000..dacecf19d --- /dev/null +++ b/examples/widgets/keyboard/lv_example_keyboard_1.c @@ -0,0 +1,37 @@ +#include "../../../lvgl.h" +#if LV_USE_KEYBOARD + + +static void ta_event_cb(lv_obj_t * ta, lv_event_t e) +{ + lv_obj_t * kb = lv_event_get_user_data(); + if(e == LV_EVENT_FOCUSED) { + lv_keyboard_set_textarea(kb, ta); + lv_obj_clear_flag(kb, LV_OBJ_FLAG_HIDDEN); + } + + if(e == LV_EVENT_DEFOCUSED) { + lv_keyboard_set_textarea(kb, NULL); + lv_obj_add_flag(kb, LV_OBJ_FLAG_HIDDEN); + } +} + +void lv_keyboard_example_1(void) +{ + /*Create a keyboard to use it with an of the text areas*/ + lv_obj_t *kb = lv_keyboard_create(lv_scr_act()); + + /*Create a text area. The keyboard will write here*/ + lv_obj_t * ta; + ta = lv_textarea_create(lv_scr_act(), NULL); + lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_LEFT, 10, 10); + lv_obj_add_event_cb(ta, ta_event_cb, kb); + lv_textarea_set_placeholder_text(ta, "Hello"); + + ta = lv_textarea_create(lv_scr_act(), NULL); + lv_obj_align(ta, NULL, LV_ALIGN_IN_TOP_RIGHT, -10, 10); + lv_obj_add_event_cb(ta, ta_event_cb, kb); + + lv_keyboard_set_textarea(kb, ta); +} +#endif diff --git a/examples/widgets/keyboard/lv_example_keyboard_1.py b/examples/widgets/keyboard/lv_example_keyboard_1.py new file mode 100644 index 000000000..61d83ad76 --- /dev/null +++ b/examples/widgets/keyboard/lv_example_keyboard_1.py @@ -0,0 +1,26 @@ +# Create styles for the keyboard +rel_style = lv.style_t() +pr_style = lv.style_t() + +lv.style_copy(rel_style, lv.style_btn_rel) +rel_style.body.radius = 0 +rel_style.body.border.width = 1 + +lv.style_copy(pr_style, lv.style_btn_pr) +pr_style.body.radius = 0 +pr_style.body.border.width = 1 + +# Create a keyboard and apply the styles +kb = lv.kb(lv.scr_act()) +kb.set_cursor_manage(True) +kb.set_style(lv.kb.STYLE.BG, lv.style_transp_tight) +kb.set_style(lv.kb.STYLE.BTN_REL, rel_style) +kb.set_style(lv.kb.STYLE.BTN_PR, pr_style) + +# Create a text area. The keyboard will write here +ta = lv.ta(lv.scr_act()) +ta.align(None, lv.ALIGN.IN_TOP_MID, 0, 10) +ta.set_text("") + +# Assign the text area to the keyboard +kb.set_ta(ta) \ No newline at end of file diff --git a/examples/widgets/label/lv_example_label_1.c b/examples/widgets/label/lv_example_label_1.c new file mode 100644 index 000000000..6e5a541b5 --- /dev/null +++ b/examples/widgets/label/lv_example_label_1.c @@ -0,0 +1,26 @@ +#include "../../../lvgl.h" +#if LV_USE_LABEL + +/** + * Show line wrap, re-color, line align and text scrolling. + */ +void lv_example_label_1(void) +{ + lv_obj_t * label1 = lv_label_create(lv_scr_act(), NULL); + lv_label_set_long_mode(label1, LV_LABEL_LONG_WRAP); /*Break the long lines*/ + lv_label_set_recolor(label1, true); /*Enable re-coloring by commands in the text*/ + lv_label_set_text(label1, "#0000ff Re-color# #ff00ff words# #ff0000 of a# label, align the lines to the center" + "and wrap long text automatically."); + lv_obj_set_width(label1, 150); /*Set smaller width to make the lines wrap*/ + lv_obj_set_style_text_align(label1, LV_PART_MAIN, LV_STATE_DEFAULT, LV_TEXT_ALIGN_CENTER); + lv_obj_align(label1, NULL, LV_ALIGN_CENTER, 0, -40); + + + lv_obj_t * label2 = lv_label_create(lv_scr_act(), NULL); + lv_label_set_long_mode(label2, LV_LABEL_LONG_SROLL_CIRC); /*Circular scroll*/ + lv_obj_set_width(label2, 150); + lv_label_set_text(label2, "It is a circularly scrolling text. "); + lv_obj_align(label2, NULL, LV_ALIGN_CENTER, 0, 40); +} + +#endif diff --git a/examples/widgets/label/lv_example_label_1.py b/examples/widgets/label/lv_example_label_1.py new file mode 100644 index 000000000..659d3d9e8 --- /dev/null +++ b/examples/widgets/label/lv_example_label_1.py @@ -0,0 +1,14 @@ +label1 = lv.label(lv.scr_act()) +label1.set_long_mode(lv.label.LONG.BREAK) # Break the long lines +label1.set_recolor(True) # Enable re-coloring by commands in the text +label1.set_align(lv.label.ALIGN.CENTER) # Center aligned lines +label1.set_text("#000080 Re-color# #0000ff words# #6666ff of a# label " + + "and wrap long text automatically.") +label1.set_width(150) +label1.align(None, lv.ALIGN.CENTER, 0, -30) + +label2 = lv.label(lv.scr_act()) +label2.set_long_mode(lv.label.LONG.SROLL_CIRC) # Circular scroll +label2.set_width(150) +label2.set_text("It is a circularly scrolling text. ") +label2.align(None, lv.ALIGN.CENTER, 0, 30) \ No newline at end of file diff --git a/examples/widgets/label/lv_example_label_2.c b/examples/widgets/label/lv_example_label_2.c new file mode 100644 index 000000000..28c42d5d3 --- /dev/null +++ b/examples/widgets/label/lv_example_label_2.c @@ -0,0 +1,36 @@ +#include "../../../lvgl.h" +#if LV_USE_LABEL + +/** + * Create a fake text shadow + */ +void lv_example_label_2(void) +{ + /* Create a style for the shadow*/ + static lv_style_t style_shadow; + lv_style_init(&style_shadow); + lv_style_set_text_opa(&style_shadow, LV_OPA_30); + lv_style_set_text_color(&style_shadow, LV_COLOR_BLACK); + + /*Create a label for the shadow first (it's in the background) */ + lv_obj_t * shadow_label = lv_label_create(lv_scr_act(), NULL); + lv_obj_add_style(shadow_label, LV_PART_MAIN, LV_STATE_DEFAULT, &style_shadow); + + /* Create the main label */ + lv_obj_t * main_label = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(main_label, "A simple method to create\n" + "shadows on a text.\n" + "It even works with\n\n" + "newlines and spaces."); + + /*Set the same text for the shadow label*/ + lv_label_set_text(shadow_label, lv_label_get_text(main_label)); + + /* Position the main label */ + lv_obj_align(main_label, NULL, LV_ALIGN_CENTER, 0, 0); + + /* Shift the second label down and to the right by 2 pixel */ + lv_obj_align(shadow_label, main_label, LV_ALIGN_IN_TOP_LEFT, 2, 2); +} + +#endif diff --git a/examples/widgets/label/lv_example_label_2.py b/examples/widgets/label/lv_example_label_2.py new file mode 100644 index 000000000..c25e59ad2 --- /dev/null +++ b/examples/widgets/label/lv_example_label_2.py @@ -0,0 +1,24 @@ +# Create a style for the shadow +label_style = lv.style_t() +lv.style_copy(label_style, lv.style_plain) +label_style.text.opa = lv.OPA._50 + +# Create a label for the shadow first (it's in the background) +shadow_label = lv.label(lv.scr_act()) +shadow_label.set_style(lv.label.STYLE.MAIN, label_style) + +# Create the main label +main_label = lv.label(lv.scr_act()) +main_label.set_text("A simple method to create\n" + + "shadows on text\n" + + "It even works with\n\n" + + "newlines and spaces.") + +# Set the same text for the shadow label +shadow_label.set_text(main_label.get_text()) + +# Position the main label +main_label.align(None, lv.ALIGN.CENTER, 0, 0) + +# Shift the second label down and to the right by 1 pixel +shadow_label.align(main_label, lv.ALIGN.IN_TOP_LEFT, 1, 1) \ No newline at end of file diff --git a/examples/widgets/led/lv_example_led_1.c b/examples/widgets/led/lv_example_led_1.c new file mode 100644 index 000000000..7462d8047 --- /dev/null +++ b/examples/widgets/led/lv_example_led_1.c @@ -0,0 +1,22 @@ +#include "../../../lvgl.h" +#if LV_USE_LED + +void lv_example_led_1(void) +{ + /*Create a LED and switch it OFF*/ + lv_obj_t * led1 = lv_led_create(lv_scr_act()); + lv_obj_align(led1, NULL, LV_ALIGN_CENTER, -80, 0); + lv_led_off(led1); + + /*Copy the previous LED and set a brightness*/ + lv_obj_t * led2 = lv_led_create(lv_scr_act()); + lv_obj_align(led2, NULL, LV_ALIGN_CENTER, 0, 0); + lv_led_set_bright(led2, 150); + + /*Copy the previous LED and switch it ON*/ + lv_obj_t * led3 = lv_led_create(lv_scr_act()); + lv_obj_align(led3, NULL, LV_ALIGN_CENTER, 80, 0); + lv_led_on(led3); +} + +#endif diff --git a/examples/widgets/led/lv_example_led_1.py b/examples/widgets/led/lv_example_led_1.py new file mode 100644 index 000000000..dc1782998 --- /dev/null +++ b/examples/widgets/led/lv_example_led_1.py @@ -0,0 +1,27 @@ +# Create a style for the LED +style_led = lv.style_t() +lv.style_copy(style_led, lv.style_pretty_color) +style_led.body.radius = 800 # large enough to draw a circle +style_led.body.main_color = lv.color_make(0xb5, 0x0f, 0x04) +style_led.body.grad_color = lv.color_make(0x50, 0x07, 0x02) +style_led.body.border.color = lv.color_make(0xfa, 0x0f, 0x00) +style_led.body.border.width = 3 +style_led.body.border.opa = lv.OPA._30 +style_led.body.shadow.color = lv.color_make(0xb5, 0x0f, 0x04) +style_led.body.shadow.width = 5 + +# Create a LED and switch it OFF +led1 = lv.led(lv.scr_act()) +led1.set_style(lv.led.STYLE.MAIN, style_led) +led1.align(None, lv.ALIGN.CENTER, -80, 0) +led1.off() + +# Copy the previous LED and set a brightness +led2 = lv.led(lv.scr_act(), led1) +led2.align(None, lv.ALIGN.CENTER, 0, 0) +led2.set_bright(190) + +# Copy the previous LED and switch it ON +led3 = lv.led(lv.scr_act(), led1) +led3.align(None, lv.ALIGN.CENTER, 80, 0) +led3.on() \ No newline at end of file diff --git a/examples/widgets/line/lv_example_line_1.c b/examples/widgets/line/lv_example_line_1.c new file mode 100644 index 000000000..a81f840c5 --- /dev/null +++ b/examples/widgets/line/lv_example_line_1.c @@ -0,0 +1,24 @@ +#include "../../../lvgl.h" +#if LV_USE_LINE + +void lv_example_line_1(void) +{ + /*Create an array for the points of the line*/ + static lv_point_t line_points[] = { {5, 5}, {70, 70}, {120, 10}, {180, 60}, {240, 10} }; + + /*Create style*/ + static lv_style_t style_line; + lv_style_init(&style_line); + lv_style_set_line_width(&style_line, 8); + lv_style_set_line_color(&style_line, LV_COLOR_BLUE); + lv_style_set_line_rounded(&style_line, true); + + /*Create a line and apply the new style*/ + lv_obj_t * line1; + line1 = lv_line_create(lv_scr_act(), NULL); + lv_line_set_points(line1, line_points, 5); /*Set the points*/ + lv_obj_add_style(line1, LV_PART_MAIN, LV_STATE_DEFAULT, &style_line); /*Set the points*/ + lv_obj_align(line1, NULL, LV_ALIGN_CENTER, 0, 0); +} + +#endif diff --git a/examples/widgets/line/lv_example_line_1.py b/examples/widgets/line/lv_example_line_1.py new file mode 100644 index 000000000..a590d23af --- /dev/null +++ b/examples/widgets/line/lv_example_line_1.py @@ -0,0 +1,19 @@ +# Create an array for the points of the line +line_points = [ {"x":5, "y":5}, + {"x":70, "y":70}, + {"x":120, "y":10}, + {"x":180, "y":60}, + {"x":240, "y":10}] + +# Create new style (thick dark blue) +style_line = lv.style_t() +lv.style_copy(style_line, lv.style_plain) +style_line.line.color = lv.color_make(0x00, 0x3b, 0x75) +style_line.line.width = 3 +style_line.line.rounded = 1 + +# Copy the previous line and apply the new style +line1 = lv.line(lv.scr_act()) +line1.set_points(line_points, len(line_points)) # Set the points +line1.set_style(lv.line.STYLE.MAIN, style_line) +line1.align(None, lv.ALIGN.CENTER, 0, 0) \ No newline at end of file diff --git a/examples/widgets/list/lv_example_list_1.c b/examples/widgets/list/lv_example_list_1.c new file mode 100644 index 000000000..bc2017a22 --- /dev/null +++ b/examples/widgets/list/lv_example_list_1.c @@ -0,0 +1,34 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_LIST + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_CLICKED) { + printf("Clicked: %s\n", lv_list_get_btn_text(obj)); + } +} +void lv_list_example_1(void) +{ + /*Create a list*/ + lv_obj_t * list1 = lv_list_create(lv_scr_act()); + lv_obj_align(list1, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Add buttons to the list*/ + lv_list_add_text(list1, "File"); + lv_list_add_btn(list1, LV_SYMBOL_FILE, "New", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_DIRECTORY, "Open", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_SAVE, "Save", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Delete", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_EDIT, "Edit", event_handler); + lv_list_add_text(list1, "Connectivity"); + lv_list_add_btn(list1, LV_SYMBOL_BLUETOOTH, "Bluetooth", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_GPS, "Navigation", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_USB, "USB", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_BATTERY_FULL, "Battery", event_handler); + lv_list_add_text(list1, "Exit"); + lv_list_add_btn(list1, LV_SYMBOL_OK, "Apply", event_handler); + lv_list_add_btn(list1, LV_SYMBOL_CLOSE, "Close", event_handler); +} + +#endif diff --git a/examples/widgets/list/lv_example_list_1.py b/examples/widgets/list/lv_example_list_1.py new file mode 100644 index 000000000..22a0db2f4 --- /dev/null +++ b/examples/widgets/list/lv_example_list_1.py @@ -0,0 +1,25 @@ +def event_handler(obj, event): + if event == lv.EVENT.CLICKED: + print("Clicked: %s" % lv.list.get_btn_text(obj)) + +# Create a list +list1 = lv.list(lv.scr_act()) +list1.set_size(160, 200) +list1.align(None, lv.ALIGN.CENTER, 0, 0) + +# Add buttons to the list + +list_btn = list1.add_btn(lv.SYMBOL.FILE, "New") +list_btn.set_event_cb(event_handler) + +list_btn = list1.add_btn(lv.SYMBOL.DIRECTORY, "Open") +list_btn.set_event_cb(event_handler) + +list_btn = list1.add_btn(lv.SYMBOL.CLOSE, "Delete") +list_btn.set_event_cb(event_handler) + +list_btn = list1.add_btn(lv.SYMBOL.EDIT, "Edit") +list_btn.set_event_cb(event_handler) + +list_btn = list1.add_btn(lv.SYMBOL.SAVE, "Save") +list_btn.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/lv_example_widgets.h b/examples/widgets/lv_example_widgets.h new file mode 100644 index 000000000..d02ab574e --- /dev/null +++ b/examples/widgets/lv_example_widgets.h @@ -0,0 +1,77 @@ +/** + * @file lv_example_widgets.h + * + */ + +#ifndef LV_EX_WIDGETS_H +#define LV_EX_WIDGETS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +void lv_example_arc_1(void); +void lv_example_arc_2(void); +void lv_example_bar_1(void); +void lv_example_btn_1(void); +void lv_example_btn_2(void); +void lv_example_btnmatrix_1(void); +void lv_example_calendar_1(void); +void lv_example_canvas_1(void); +void lv_example_canvas_2(void); +void lv_example_checkbox_1(void); +void lv_example_chart_1(void); +void lv_example_chart_2(void); +void lv_example_dropdown_1(void); +void lv_example_dropdown_2(void); +void lv_example_gauge_1(void); +void lv_example_gauge_2(void); +void lv_example_img_1(void); +void lv_example_img_2(void); +void lv_example_img_3(void); +void lv_example_imgbtn_1(void); +void lv_example_keyboard_1(void); +void lv_example_label_1(void); +void lv_example_label_2(void); +void lv_example_label_3(void); +void lv_example_led_1(void); +void lv_example_line_1(void); +void lv_example_list_1(void); +void lv_example_linemeter_1(void); +void lv_example_msgbox_1(void); +void lv_example_msgbox_2(void); +void lv_example_obj_1(void); +void lv_example_spinner_1(void); +void lv_example_roller_1(void); +void lv_example_slider_1(void); +void lv_example_slider_2(void); +void lv_example_switch_1(void); +void lv_example_textarea_1(void); +void lv_example_objmask_1(void); +void lv_example_objmask_2(void); +void lv_example_table_1(void); + +/********************** + * MACROS + **********************/ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_EX_WIDGETS_H*/ diff --git a/examples/widgets/meter/lv_example_meter_1.c b/examples/widgets/meter/lv_example_meter_1.c new file mode 100644 index 000000000..c0a0dee92 --- /dev/null +++ b/examples/widgets/meter/lv_example_meter_1.c @@ -0,0 +1,54 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_METER + +static lv_obj_t * meter; + +static void set_value(lv_meter_indicator_t * indic, int32_t v) +{ + lv_meter_set_indicator_value(meter, indic, v); +} + +/** + * A simple meter + */ +void lv_example_meter_1(void) +{ + meter = lv_meter_create(lv_scr_act(), NULL); + lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Add a scale first*/ + lv_meter_scale_t * scale = lv_meter_add_scale(meter); + lv_meter_set_scale_ticks(meter, scale, 51, 2, 10, LV_COLOR_GRAY); + lv_meter_set_scale_major_ticks(meter, scale, 10, 4, 15, LV_COLOR_BLACK, 10); + + lv_meter_indicator_t * indic; + + /*Add a red arc to the end */ + indic = lv_meter_add_arc(meter, scale, 3, LV_COLOR_RED, 1); + lv_meter_set_indicator_start_value(meter, indic, 80); + lv_meter_set_indicator_end_value(meter, indic, 100); + + /*Make the tick lines red at the end of the scale*/ + indic = lv_meter_add_scale_lines(meter, scale, LV_COLOR_RED, LV_COLOR_RED, false, 0); + lv_meter_set_indicator_start_value(meter, indic, 80); + lv_meter_set_indicator_end_value(meter, indic, 100); + + /*Add a needle line indicator*/ + indic = lv_meter_add_needle_line(meter, scale, 4, LV_COLOR_GRAY, -10); + + /*Create an animation to set the value*/ + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) set_value); + lv_anim_set_var(&a, indic); + lv_anim_set_values(&a, 0, 100); + lv_anim_set_time(&a, 2000); + lv_anim_set_repeat_delay(&a, 100); + lv_anim_set_playback_time(&a, 500); + lv_anim_set_playback_delay(&a, 100); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_start(&a); +} + +#endif diff --git a/examples/widgets/meter/lv_example_meter_2.c b/examples/widgets/meter/lv_example_meter_2.c new file mode 100644 index 000000000..1e2e89d8c --- /dev/null +++ b/examples/widgets/meter/lv_example_meter_2.c @@ -0,0 +1,60 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_METER + +static lv_obj_t * meter; + +static void set_value(lv_meter_indicator_t * indic, int32_t v) +{ + lv_meter_set_indicator_end_value(meter, indic, v); +} + + +/** + * A meter with multiple arcs + */ +void lv_example_meter_2(void) +{ + meter = lv_meter_create(lv_scr_act(), NULL); + lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Remove the circle from the middle*/ + lv_obj_remove_style(meter, LV_PART_INDICATOR, LV_STATE_ANY, NULL); + + /*Add a scale first*/ + lv_meter_scale_t * scale = lv_meter_add_scale(meter); + lv_meter_set_scale_ticks(meter, scale, 11, 2, 10, LV_COLOR_GRAY); + lv_meter_set_scale_major_ticks(meter, scale, 1, 2, 30, lv_color_hex3(0xeee), 10); + lv_meter_set_scale_range(meter, scale, 0, 100, 270, 90); + + /*Add a three arc indicator */ + lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, 10, LV_COLOR_RED, 0); + lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, 10, LV_COLOR_GREEN, -10); + lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, 10, LV_COLOR_BLUE, -20); + + /*Create an animation to set the value*/ + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) set_value); + lv_anim_set_values(&a, 0, 100); + lv_anim_set_repeat_delay(&a, 100); + lv_anim_set_playback_delay(&a, 100); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + + lv_anim_set_time(&a, 2000); + lv_anim_set_playback_time(&a, 500); + lv_anim_set_var(&a, indic1); + lv_anim_start(&a); + + lv_anim_set_time(&a, 1000); + lv_anim_set_playback_time(&a, 1000); + lv_anim_set_var(&a, indic2); + lv_anim_start(&a); + + lv_anim_set_time(&a, 1000); + lv_anim_set_playback_time(&a, 2000); + lv_anim_set_var(&a, indic3); + lv_anim_start(&a); +} + +#endif diff --git a/examples/widgets/meter/lv_example_meter_3.c b/examples/widgets/meter/lv_example_meter_3.c new file mode 100644 index 000000000..dd3ee0aa7 --- /dev/null +++ b/examples/widgets/meter/lv_example_meter_3.c @@ -0,0 +1,55 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_METER + +static lv_obj_t * meter; + +static void set_value(lv_meter_indicator_t * indic, int32_t v) +{ + lv_meter_set_indicator_end_value(meter, indic, v); +} + + +/** + * A clock from a meter + */ +void lv_example_meter_3(void) +{ + meter = lv_meter_create(lv_scr_act(), NULL); + lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Create a scale for the minutes*/ + /*61 ticks in a 360 degrees range (the last and the first line overlaps)*/ + lv_meter_scale_t * scale_min = lv_meter_add_scale(meter); + lv_meter_set_scale_ticks(meter, scale_min, 61, 1, 10, LV_COLOR_GRAY); + lv_meter_set_scale_range(meter, scale_min, 0, 60, 360, 270); + + /*Create an other scale for the hours. It's only visual and contains only major ticks*/ + lv_meter_scale_t * scale_hour = lv_meter_add_scale(meter); + lv_meter_set_scale_ticks(meter, scale_hour, 12, 0, 0, LV_COLOR_GRAY); /*12 ticks*/ + lv_meter_set_scale_major_ticks(meter, scale_hour, 1, 2, 20, LV_COLOR_BLACK, 10); /*Every tick is major*/ + lv_meter_set_scale_range(meter, scale_hour, 1, 12, 330, 300); /*[1..12] values in an almost full circle*/ + + LV_IMG_DECLARE(img_hand) + + /*Add a the hands from images */ + lv_meter_indicator_t * indic_min = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5); + lv_meter_indicator_t * indic_hour = lv_meter_add_needle_img(meter, scale_min, &img_hand, 5, 5); + + /*Create an animation to set the value*/ + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t) set_value); + lv_anim_set_values(&a, 0, 60); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_time(&a, 2000); /*2 sec for 1 turn of the minute hand (1 hour)*/ + lv_anim_set_var(&a, indic_min); + lv_anim_start(&a); + + lv_anim_set_var(&a, indic_hour); + lv_anim_set_time(&a, 24000); /*24 sec for 1 turn of the hour hand*/ + lv_anim_set_values(&a, 0, 60); + lv_anim_start(&a); +} + +#endif diff --git a/examples/widgets/meter/lv_example_meter_4.c b/examples/widgets/meter/lv_example_meter_4.c new file mode 100644 index 000000000..f1c3bf62e --- /dev/null +++ b/examples/widgets/meter/lv_example_meter_4.c @@ -0,0 +1,37 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_METER + +/** + * Create a pie chart + */ +void lv_example_meter_4(void) +{ + lv_obj_t * meter = lv_meter_create(lv_scr_act(), NULL); + lv_obj_align(meter, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Remove the background and the circle from the middle*/ + lv_obj_remove_style(meter, LV_PART_MAIN, LV_STATE_ANY, NULL); + lv_obj_remove_style(meter, LV_PART_INDICATOR, LV_STATE_ANY, NULL); + + /*Add a scale first with no ticks.*/ + lv_meter_scale_t * scale = lv_meter_add_scale(meter); + lv_meter_set_scale_ticks(meter, scale, 0, 0, 0, LV_COLOR_BLACK); + lv_meter_set_scale_range(meter, scale, 0, 100, 360, 0); + + /*Add a three arc indicator */ + lv_coord_t indic_w = lv_obj_get_width(meter) / 2; + lv_meter_indicator_t * indic1 = lv_meter_add_arc(meter, scale, indic_w, LV_COLOR_ORANGE, 0); + lv_meter_set_indicator_start_value(meter, indic1, 0); + lv_meter_set_indicator_end_value(meter, indic1, 40); + + lv_meter_indicator_t * indic2 = lv_meter_add_arc(meter, scale, indic_w, LV_COLOR_GREEN, 0); + lv_meter_set_indicator_start_value(meter, indic2, 40); /*Start from the previous*/ + lv_meter_set_indicator_end_value(meter, indic2, 80); + + lv_meter_indicator_t * indic3 = lv_meter_add_arc(meter, scale, indic_w, LV_COLOR_BLUE, 0); + lv_meter_set_indicator_start_value(meter, indic3, 80); /*Start from the previous*/ + lv_meter_set_indicator_end_value(meter, indic3, 100); +} + +#endif diff --git a/examples/widgets/msgbox/lv_example_msgbox_1.c b/examples/widgets/msgbox/lv_example_msgbox_1.c new file mode 100644 index 000000000..472d46214 --- /dev/null +++ b/examples/widgets/msgbox/lv_example_msgbox_1.c @@ -0,0 +1,26 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_MSGBOX + +static void event_cb(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + printf("Button: %s\n", lv_msgbox_get_active_btn_text(obj)); + } +} + +void lv_example_msgbox_1(void) +{ +// static lv_style_t style; +// lv_style_init(&style); +// lv_style_set_radius(&style, LV_STATE_DEFAULT, 30); + + static const char * btns[] ={"Apply", "Close", ""}; + + lv_obj_t * mbox1 = lv_msgbox_create("Hello", "This is a message box with two buttons.", btns, true); +// lv_obj_set_width(mbox1, 300); + lv_obj_add_event_cb(mbox1, event_cb, NULL); + lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/ +} + +#endif diff --git a/examples/widgets/msgbox/lv_example_msgbox_1.py b/examples/widgets/msgbox/lv_example_msgbox_1.py new file mode 100644 index 000000000..31c59f534 --- /dev/null +++ b/examples/widgets/msgbox/lv_example_msgbox_1.py @@ -0,0 +1,12 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + print("Button: %s" % lv.mbox.get_active_btn_text(obj)) + +btns = ["Apply", "Close", ""] + +mbox1 = lv.mbox(lv.scr_act()) +mbox1.set_text("A message box with two buttons."); +mbox1.add_btns(btns) +mbox1.set_width(200) +mbox1.set_event_cb(event_handler) +mbox1.align(None, lv.ALIGN.CENTER, 0, 0) # Align to the corner \ No newline at end of file diff --git a/examples/widgets/msgbox/lv_example_msgbox_2.c b/examples/widgets/msgbox/lv_example_msgbox_2.c new file mode 100644 index 000000000..4275e8cd3 --- /dev/null +++ b/examples/widgets/msgbox/lv_example_msgbox_2.c @@ -0,0 +1,94 @@ +//#include "../../../lvgl.h" +//#if LV_USE_MSGBOX +// +//static void mbox_event_cb(lv_obj_t *obj, lv_event_t evt); +//static void btn_event_cb(lv_obj_t *btn, lv_event_t evt); +//static void opa_anim(void * bg, lv_anim_value_t v); +// +//static lv_obj_t *mbox, *info; +//static lv_style_t style_modal; +// +//static const char welcome_info[] = "Welcome to the modal message box demo!\n" +// "Press the button to display a message box."; +// +//static const char in_msg_info[] = "Notice that you cannot touch " +// "the button again while the message box is open."; +// +//void lv_example_msgbox_2(void) +//{ +// lv_style_init(&style_modal); +// lv_style_set_bg_color(&style_modal, LV_STATE_DEFAULT, LV_COLOR_BLACK); +// +// /* Create a button, then set its position and event callback */ +// lv_obj_t *btn = lv_btn_create(lv_scr_act(), NULL); +// lv_obj_set_size(btn, 200, 60); +// lv_obj_set_event_cb(btn, btn_event_cb); +// lv_obj_align(btn, NULL, LV_ALIGN_IN_TOP_LEFT, 20, 20); +// +// /* Create a label on the button */ +// lv_obj_t *label = lv_label_create(btn, NULL); +// lv_label_set_text(label, "Display a message box!"); +// +// /* Create an informative label on the screen */ +// info = lv_label_create(lv_scr_act(), NULL); +// lv_label_set_text(info, welcome_info); +// lv_label_set_long_mode(info, LV_LABEL_LONG_BREAK); /* Make sure text will wrap */ +// lv_obj_set_width(info, LV_HOR_RES - 10); +// lv_obj_align(info, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 5, -5); +// +//} +// +//static void mbox_event_cb(lv_obj_t *obj, lv_event_t evt) +//{ +// if(evt == LV_EVENT_DELETE && obj == mbox) { +// /* Delete the parent modal background */ +// lv_obj_del_async(lv_obj_get_parent(mbox)); +// mbox = NULL; /* happens before object is actually deleted! */ +// lv_label_set_text(info, welcome_info); +// } else if(evt == LV_EVENT_VALUE_CHANGED) { +// /* A button was clicked */ +// lv_msgbox_start_auto_close(mbox, 0); +// } +//} +// +//static void btn_event_cb(lv_obj_t *btn, lv_event_t evt) +//{ +// if(evt == LV_EVENT_CLICKED) { +// /* Create a full-screen background */ +// +// /* Create a base object for the modal background */ +// lv_obj_t *obj = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_reset_style_list(obj, LV_OBJ_PART_MAIN); +// lv_obj_add_style(obj, LV_OBJ_PART_MAIN, &style_modal); +// lv_obj_set_pos(obj, 0, 0); +// lv_obj_set_size(obj, LV_HOR_RES, LV_VER_RES); +// +// static const char * btns2[] = {"Ok", "Cancel", ""}; +// +// /* Create the message box as a child of the modal background */ +// mbox = lv_msgbox_create(obj, NULL); +// lv_msgbox_add_btns(mbox, btns2); +// lv_msgbox_set_text(mbox, "Hello world!"); +// lv_obj_align(mbox, NULL, LV_ALIGN_CENTER, 0, 0); +// lv_obj_set_event_cb(mbox, mbox_event_cb); +// +// /* Fade the message box in with an animation */ +// lv_anim_t a; +// lv_anim_init(&a); +// lv_anim_set_var(&a, obj); +// lv_anim_set_time(&a, 500); +// lv_anim_set_values(&a, LV_OPA_TRANSP, LV_OPA_50); +// lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)opa_anim); +// lv_anim_start(&a); +// +// lv_label_set_text(info, in_msg_info); +// lv_obj_align(info, NULL, LV_ALIGN_IN_BOTTOM_LEFT, 5, -5); +// } +//} +// +//static void opa_anim(void * bg, lv_anim_value_t v) +//{ +// lv_obj_set_style_local_bg_opa(bg, LV_OBJ_PART_MAIN, LV_STATE_DEFAULT, v); +//} +// +//#endif diff --git a/examples/widgets/msgbox/lv_example_msgbox_2.py b/examples/widgets/msgbox/lv_example_msgbox_2.py new file mode 100644 index 000000000..ed6c05335 --- /dev/null +++ b/examples/widgets/msgbox/lv_example_msgbox_2.py @@ -0,0 +1,86 @@ +welcome_info = "Welcome to the modal message box demo!\nPress the button to display a message box." +in_msg_info = "Notice that you cannot touch the button again while the message box is open." + +class Modal(lv.mbox): + """mbox with semi-transparent background""" + def __init__(self, parent, *args, **kwargs): + # Create a full-screen background + modal_style = lv.style_t() + lv.style_copy(modal_style, lv.style_plain_color) + # Set the background's style + modal_style.body.main_color = modal_style.body.grad_color = lv.color_make(0,0,0) + modal_style.body.opa = lv.OPA._50 + + # Create a base object for the modal background + self.bg = lv.obj(parent) + self.bg.set_style(modal_style) + self.bg.set_pos(0, 0) + self.bg.set_size(parent.get_width(), parent.get_height()) + self.bg.set_opa_scale_enable(True) # Enable opacity scaling for the animation + + super().__init__(self.bg, *args, **kwargs) + self.align(None, lv.ALIGN.CENTER, 0, 0) + + # Fade the message box in with an animation + a = lv.anim_t() + lv.anim_init(a) + lv.anim_set_time(a, 500, 0) + lv.anim_set_values(a, lv.OPA.TRANSP, lv.OPA.COVER) + lv.anim_set_exec_cb(a, self.bg, lv.obj.set_opa_scale) + lv.anim_create(a) + super().set_event_cb(self.default_callback) + + def set_event_cb(self, callback): + self.callback = callback + + def get_event_cb(self): + return self.callback + + def default_callback(self, obj, evt): + if evt == lv.EVENT.DELETE:# and obj == self: + # Delete the parent modal background + self.get_parent().del_async() + elif evt == lv.EVENT.VALUE_CHANGED: + # A button was clicked + self.start_auto_close(0) + # Call user-defined callback + if self.callback is not None: + self.callback(obj, evt) + +def mbox_event_cb(obj, evt): + if evt == lv.EVENT.DELETE: + info.set_text(welcome_info) + +def btn_event_cb(btn, evt): + if evt == lv.EVENT.CLICKED: + + btns2 = ["Ok", "Cancel", ""] + + # Create the message box as a child of the modal background + mbox = Modal(lv.scr_act()) + mbox.add_btns(btns2) + mbox.set_text("Hello world!") + mbox.set_event_cb(mbox_event_cb) + + info.set_text(in_msg_info) + info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5) + +# Get active screen +scr = lv.scr_act() + +# Create a button, then set its position and event callback +btn = lv.btn(scr) +btn.set_size(200, 60) +btn.set_event_cb(btn_event_cb) +btn.align(None, lv.ALIGN.IN_TOP_LEFT, 20, 20) + +# Create a label on the button +label = lv.label(btn) +label.set_text("Display a message box!") + +# Create an informative label on the screen +info = lv.label(scr) +info.set_text(welcome_info) +info.set_long_mode(lv.label.LONG.BREAK) # Make sure text will wrap +info.set_width(scr.get_width() - 10) +info.align(None, lv.ALIGN.IN_BOTTOM_LEFT, 5, -5) \ No newline at end of file diff --git a/examples/widgets/obj/lv_example_obj_1.c b/examples/widgets/obj/lv_example_obj_1.c new file mode 100644 index 000000000..b7f8d29ee --- /dev/null +++ b/examples/widgets/obj/lv_example_obj_1.c @@ -0,0 +1,21 @@ +//#include "../../../lvgl.h" +// +//void lv_example_obj_1(void) +//{ +// lv_obj_t * obj1; +// obj1 = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_set_size(obj1, 100, 50); +// lv_obj_align(obj1, NULL, LV_ALIGN_CENTER, -60, -30); +// +// static lv_style_t style_shadow; +// lv_style_init(&style_shadow); +// lv_style_set_shadow_width(&style_shadow, LV_STATE_DEFAULT, 10); +// lv_style_set_shadow_spread(&style_shadow, LV_STATE_DEFAULT, 5); +// lv_style_set_shadow_color(&style_shadow, LV_STATE_DEFAULT, LV_COLOR_BLUE); +// +// /*Copy the previous object (drag is already enabled)*/ +// lv_obj_t * obj3; +// obj3 = lv_obj_create(lv_scr_act(), NULL); +// lv_obj_add_style(obj3, LV_OBJ_PART_MAIN, &style_shadow); +// lv_obj_align(obj3, NULL, LV_ALIGN_CENTER, 60, 30); +//} diff --git a/examples/widgets/obj/lv_example_obj_1.py b/examples/widgets/obj/lv_example_obj_1.py new file mode 100644 index 000000000..3a22ab74c --- /dev/null +++ b/examples/widgets/obj/lv_example_obj_1.py @@ -0,0 +1,20 @@ +obj1 = lv.obj(lv.scr_act()) +obj1.set_size(100, 50) +obj1.set_style(lv.style_plain_color) +obj1.align(None, lv.ALIGN.CENTER, -60, -30) + +# Copy the previous object and enable drag +obj2 = lv.obj(lv.scr_act(), obj1) +obj2.set_style(lv.style_pretty_color) +obj2.align(None, lv.ALIGN.CENTER, 0, 0) +obj2.set_drag(True) + +style_shadow = lv.style_t() +lv.style_copy(style_shadow, lv.style_pretty) +style_shadow.body.shadow.width = 6 +style_shadow.body.radius = 800 # large enough to make it round + +# Copy the previous object (drag is already enabled) +obj3 = lv.obj(lv.scr_act(), obj2) +obj3.set_style(style_shadow) +obj3.align(None, lv.ALIGN.CENTER, 60, 30) \ No newline at end of file diff --git a/examples/widgets/roller/lv_example_roller_1.c b/examples/widgets/roller/lv_example_roller_1.c new file mode 100644 index 000000000..d0b03be8a --- /dev/null +++ b/examples/widgets/roller/lv_example_roller_1.c @@ -0,0 +1,40 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_ROLLER + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + char buf[32]; + lv_roller_get_selected_str(obj, buf, sizeof(buf)); + printf("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(), NULL); + 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_align(roller1, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(roller1, event_handler, NULL); +} + +#endif diff --git a/examples/widgets/roller/lv_example_roller_1.py b/examples/widgets/roller/lv_example_roller_1.py new file mode 100644 index 000000000..f99015778 --- /dev/null +++ b/examples/widgets/roller/lv_example_roller_1.py @@ -0,0 +1,24 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + option = " "*10 + obj.get_selected_str(option, len(option)) + print("Selected month: %s" % option.strip()) + +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.INIFINITE) + +roller1.set_visible_row_count(4) +roller1.align(None, lv.ALIGN.CENTER, 0, 0) +roller1.set_event_cb(event_handler) diff --git a/examples/widgets/slider/lv_example_slider_1.c b/examples/widgets/slider/lv_example_slider_1.c new file mode 100644 index 000000000..2991d846a --- /dev/null +++ b/examples/widgets/slider/lv_example_slider_1.c @@ -0,0 +1,35 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_SLIDER + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event); +static lv_obj_t * slider_label; + +/** + * A default slider with a label displaying the current value + */ +void lv_example_slider_1(void) +{ + /* Create a slider in the center of the display */ + lv_obj_t * slider = lv_slider_create(lv_scr_act(), NULL); + lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(slider, slider_event_cb, NULL); + + /* Create a label below the slider */ + slider_label = lv_label_create(lv_scr_act(), NULL); + lv_label_set_text(slider_label, "0%"); + + lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); +} + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + char buf[8]; + lv_snprintf(buf, sizeof(buf), "%d%%", lv_slider_get_value(slider)); + lv_label_set_text(slider_label, buf); + lv_obj_align(slider_label, slider, LV_ALIGN_OUT_BOTTOM_MID, 0, 10); + } +} + +#endif diff --git a/examples/widgets/slider/lv_example_slider_1.py b/examples/widgets/slider/lv_example_slider_1.py new file mode 100644 index 000000000..655fbd145 --- /dev/null +++ b/examples/widgets/slider/lv_example_slider_1.py @@ -0,0 +1,37 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + print("Value: %d" % obj.get_value()) + +# Create styles +style_bg = lv.style_t() +style_indic = lv.style_t() +style_knob = lv.style_t() + +lv.style_copy(style_bg, lv.style_pretty) +style_bg.body.main_color = lv.color_make(0,0,0) +style_bg.body.grad_color = lv.color_make(0x80, 0x80, 0x80) +style_bg.body.radius = 800 # large enough to make a circle +style_bg.body.border.color = lv.color_make(0xff,0xff,0xff) + +lv.style_copy(style_indic, lv.style_pretty_color) +style_indic.body.radius = 800 +style_indic.body.shadow.width = 8 +style_indic.body.shadow.color = style_indic.body.main_color +style_indic.body.padding.left = 3 +style_indic.body.padding.right = 3 +style_indic.body.padding.top = 3 +style_indic.body.padding.bottom = 3 + +lv.style_copy(style_knob, lv.style_pretty) +style_knob.body.radius = 800 +style_knob.body.opa = lv.OPA._70 +style_knob.body.padding.top = 10 +style_knob.body.padding.bottom = 10 + +# Create a slider +slider = lv.slider(lv.scr_act()) +slider.set_style(lv.slider.STYLE.BG, style_bg) +slider.set_style(lv.slider.STYLE.INDIC, style_indic) +slider.set_style(lv.slider.STYLE.KNOB, style_knob) +slider.align(None, lv.ALIGN.CENTER, 0, 0) +slider.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/slider/lv_example_slider_2.c b/examples/widgets/slider/lv_example_slider_2.c new file mode 100644 index 000000000..093408c00 --- /dev/null +++ b/examples/widgets/slider/lv_example_slider_2.c @@ -0,0 +1,43 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_SLIDER + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event); + +static lv_style_t style_pr; +static lv_style_t style_def; + +/** + * Show the current value when the slider if pressed (using only styles). + * + */ +void lv_example_slider_2(void) +{ + lv_style_init(&style_def); + lv_style_set_content_opa(&style_def, LV_OPA_TRANSP); + lv_style_set_content_align(&style_def, LV_ALIGN_OUT_TOP_MID); + + lv_style_init(&style_pr); + lv_style_set_content_opa(&style_pr, LV_OPA_COVER); + lv_style_set_content_ofs_y(&style_pr, -15); + + /* Create a slider in the center of the display */ + lv_obj_t * slider; + slider = lv_slider_create(lv_scr_act(), NULL); + lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(slider, slider_event_cb, NULL); + + lv_obj_add_style(slider, LV_PART_KNOB, LV_STATE_DEFAULT, &style_def); + lv_obj_add_style(slider, LV_PART_KNOB, LV_STATE_PRESSED, &style_pr); +} + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + static char buf[8]; + lv_snprintf(buf, sizeof(buf), "%u", lv_slider_get_value(slider)); + lv_obj_set_style_content_text(slider, LV_PART_KNOB, LV_STATE_DEFAULT, buf); + } +} + +#endif diff --git a/examples/widgets/slider/lv_example_slider_2.py b/examples/widgets/slider/lv_example_slider_2.py new file mode 100644 index 000000000..be6c67591 --- /dev/null +++ b/examples/widgets/slider/lv_example_slider_2.py @@ -0,0 +1,23 @@ +def slider_event_cb(slider, event): + if event == lv.EVENT.VALUE_CHANGED: + slider_label.set_text("%u" % slider.get_value()) + +# Create a slider in the center of the display +slider = lv.slider(lv.scr_act()) +slider.set_width(200) +slider.align(None, lv.ALIGN.CENTER, 0, 0) +slider.set_event_cb(slider_event_cb) +slider.set_range(0, 100) + +# Create a label below the slider +slider_label = lv.label(lv.scr_act()) +slider_label.set_text("0") +slider_label.set_auto_realign(True) +slider_label.align(slider, lv.ALIGN.OUT_BOTTOM_MID, 0, 10) + +# Create an informative label +info = lv.label(lv.scr_act()) +info.set_text("""Welcome to the slider+label demo! +Move the slider and see that the label +updates to match it.""") +info.align(None, lv.ALIGN.IN_TOP_LEFT, 10, 10) diff --git a/examples/widgets/slider/lv_example_slider_3.c b/examples/widgets/slider/lv_example_slider_3.c new file mode 100644 index 000000000..57e8e628e --- /dev/null +++ b/examples/widgets/slider/lv_example_slider_3.c @@ -0,0 +1,39 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_SLIDER + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event); + +/** + * Show the current value when the slider if pressed (using only styles). + * + */ +void lv_example_slider_3(void) +{ + /* Create a slider in the center of the display */ + lv_obj_t * slider; + slider = lv_slider_create(lv_scr_act(), NULL); + lv_obj_align(slider, NULL, LV_ALIGN_CENTER, 0, 0); + lv_obj_add_event_cb(slider, slider_event_cb, NULL); + lv_slider_set_type(slider, LV_SLIDER_TYPE_RANGE); + + lv_slider_set_value(slider, 70, LV_ANIM_OFF); + lv_slider_set_left_value(slider, 20, LV_ANIM_OFF); + + /*Now use only a local style.*/ + lv_obj_set_style_content_ofs_y(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, -20); + + /*To update the avlue text*/ + lv_event_send(slider, LV_EVENT_VALUE_CHANGED, NULL); +} + +static void slider_event_cb(lv_obj_t * slider, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + static char buf[8]; + lv_snprintf(buf, sizeof(buf), "%d - %d", lv_slider_get_value(slider), lv_slider_get_left_value(slider)); + lv_obj_set_style_content_text(slider, LV_PART_INDICATOR, LV_STATE_DEFAULT, buf); + } +} + +#endif diff --git a/examples/widgets/spinbox/lv_example_spinbox_1.c b/examples/widgets/spinbox/lv_example_spinbox_1.c new file mode 100644 index 000000000..c19cf3394 --- /dev/null +++ b/examples/widgets/spinbox/lv_example_spinbox_1.c @@ -0,0 +1,47 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_SPINBOX + +static lv_obj_t * spinbox; + + +static void lv_spinbox_increment_event_cb(lv_obj_t * btn, lv_event_t e) +{ + if(e == LV_EVENT_SHORT_CLICKED || e == LV_EVENT_LONG_PRESSED_REPEAT) { + lv_spinbox_increment(spinbox); + } +} + +static void lv_spinbox_decrement_event_cb(lv_obj_t * btn, lv_event_t e) +{ + if(e == LV_EVENT_SHORT_CLICKED || e == LV_EVENT_LONG_PRESSED_REPEAT) { + lv_spinbox_decrement(spinbox); + } +} + + +void lv_example_spinbox_1(void) +{ + spinbox = lv_spinbox_create(lv_scr_act()); + lv_spinbox_set_range(spinbox, -1000, 25000); + lv_spinbox_set_digit_format(spinbox, 5, 2); + lv_spinbox_step_prev(spinbox); + lv_obj_set_width(spinbox, 100); + lv_obj_align(spinbox, NULL, LV_ALIGN_CENTER, 0, 0); + + lv_coord_t h = lv_obj_get_height(spinbox); + + lv_obj_t * btn = lv_btn_create(lv_scr_act(), NULL); + lv_obj_set_size(btn, h, h); + lv_obj_align(btn, spinbox, LV_ALIGN_OUT_RIGHT_MID, 5, 0); + lv_obj_set_style_content_text(btn, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_PLUS); + lv_obj_add_event_cb(btn, lv_spinbox_increment_event_cb, NULL); + + btn = lv_btn_create(lv_scr_act(), NULL); + lv_obj_set_size(btn, h, h); + lv_obj_align(btn, spinbox, LV_ALIGN_OUT_LEFT_MID, -5, 0); + lv_obj_set_style_content_text(btn, LV_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_MINUS); + lv_obj_add_event_cb(btn, lv_spinbox_decrement_event_cb, NULL); +} + +#endif diff --git a/examples/widgets/spinbox/lv_example_spinbox_1.py b/examples/widgets/spinbox/lv_example_spinbox_1.py new file mode 100644 index 000000000..052ab7779 --- /dev/null +++ b/examples/widgets/spinbox/lv_example_spinbox_1.py @@ -0,0 +1,13 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + print("Value: %d" % obj.get_value()) + elif event == lv.EVENT.CLICKED: + # For simple test: Click the spinbox to increment its value + obj.increment() + +spinbox = lv.spinbox(lv.scr_act()) +spinbox.set_digit_format(5, 3) +spinbox.step_prev() +spinbox.set_width(100) +spinbox.align(None, lv.ALIGN.CENTER, 0, 0) +spinbox.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/spinner/lv_example_spinner_1.c b/examples/widgets/spinner/lv_example_spinner_1.c new file mode 100644 index 000000000..7182ea25d --- /dev/null +++ b/examples/widgets/spinner/lv_example_spinner_1.c @@ -0,0 +1,12 @@ +#include "../../../lvgl.h" +#if LV_USE_SPINNER + +void lv_example_spinner_1(void) +{ + /*Create a spinner*/ + lv_obj_t * spinner = lv_spinner_create(lv_scr_act(), 1000, 60); + lv_obj_set_size(spinner, 100, 100); + lv_obj_align(spinner, NULL, LV_ALIGN_CENTER, 0, 0); +} + +#endif diff --git a/examples/widgets/spinner/lv_example_spinner_1.py b/examples/widgets/spinner/lv_example_spinner_1.py new file mode 100644 index 000000000..b2e187cc0 --- /dev/null +++ b/examples/widgets/spinner/lv_example_spinner_1.py @@ -0,0 +1,15 @@ +# Create a style for the Preloader +style = lv.style_t() +lv.style_copy(style, lv.style_plain) +style.line.width = 10 # 10 px thick arc +style.line.color = lv.color_hex3(0x258) # Blueish arc color + +style.body.border.color = lv.color_hex3(0xBBB) # Gray background color +style.body.border.width = 10 +style.body.padding.left = 0 + +# Create a Preloader object +preload = lv.preload(lv.scr_act()) +preload.set_size(100, 100) +preload.align(None, lv.ALIGN.CENTER, 0, 0) +preload.set_style(lv.preload.STYLE.MAIN, style) \ No newline at end of file diff --git a/examples/widgets/switch/lv_example_switch_1.c b/examples/widgets/switch/lv_example_switch_1.c new file mode 100644 index 000000000..1dfe34651 --- /dev/null +++ b/examples/widgets/switch/lv_example_switch_1.c @@ -0,0 +1,40 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_SWITCH + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + printf("State: %s\n", lv_obj_has_state(obj, LV_STATE_CHECKED) ? "On" : "Off"); + } +} + +void lv_example_switch_1(void) +{ + lv_obj_set_layout(lv_scr_act(), &lv_flex_center_column); + + lv_obj_t * sw; + + sw = lv_switch_create(lv_scr_act(), NULL); + lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, -50); + lv_obj_add_event_cb(sw, event_handler, NULL); + + sw = lv_switch_create(lv_scr_act(), NULL); + lv_obj_add_state(sw, LV_STATE_CHECKED); + lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50); + lv_obj_add_event_cb(sw, event_handler, NULL); + + sw = lv_switch_create(lv_scr_act(), NULL); + lv_obj_add_state(sw, LV_STATE_DISABLED); + lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50); + lv_obj_add_event_cb(sw, event_handler, NULL); + + sw = lv_switch_create(lv_scr_act(), NULL); + lv_obj_add_state(sw, LV_STATE_CHECKED | LV_STATE_DISABLED); + lv_obj_align(sw, NULL, LV_ALIGN_CENTER, 0, 50); + lv_obj_add_event_cb(sw, event_handler, NULL); + + +} + +#endif diff --git a/examples/widgets/switch/lv_example_switch_1.py b/examples/widgets/switch/lv_example_switch_1.py new file mode 100644 index 000000000..39fb3744d --- /dev/null +++ b/examples/widgets/switch/lv_example_switch_1.py @@ -0,0 +1,48 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + print("State: %s" % ("On" if obj.get_state() else "Off")) + +# Create styles for the switch +bg_style = lv.style_t() +indic_style = lv.style_t() +knob_on_style = lv.style_t() +knob_off_style = lv.style_t() + +lv.style_copy(bg_style, lv.style_pretty) +bg_style.body.radius = 800 +bg_style.body.padding.top = 6 +bg_style.body.padding.bottom = 6 + +lv.style_copy(indic_style, lv.style_pretty_color) +indic_style.body.radius = 800 +indic_style.body.main_color = lv.color_hex(0x9fc8ef) +indic_style.body.grad_color = lv.color_hex(0x9fc8ef) +indic_style.body.padding.left = 0 +indic_style.body.padding.right = 0 +indic_style.body.padding.top = 0 +indic_style.body.padding.bottom = 0 + +lv.style_copy(knob_off_style, lv.style_pretty) +knob_off_style.body.radius = 800 +knob_off_style.body.shadow.width = 4 +knob_off_style.body.shadow.type = lv.SHADOW.BOTTOM + +lv.style_copy(knob_on_style, lv.style_pretty_color) +knob_on_style.body.radius = 800 +knob_on_style.body.shadow.width = 4 +knob_on_style.body.shadow.type = lv.SHADOW.BOTTOM + +# Create a switch and apply the styles +sw1 = lv.sw(lv.scr_act()) +sw1.set_style(lv.sw.STYLE.BG, bg_style) +sw1.set_style(lv.sw.STYLE.INDIC, indic_style) +sw1.set_style(lv.sw.STYLE.KNOB_ON, knob_on_style) +sw1.set_style(lv.sw.STYLE.KNOB_OFF, knob_off_style) +sw1.align(None, lv.ALIGN.CENTER, 0, -50) +sw1.set_event_cb(event_handler) + +# Copy the first switch and turn it ON +sw2 = lv.sw(lv.scr_act(), sw1) +sw2.on(lv.ANIM.ON) +sw2.align(None, lv.ALIGN.CENTER, 0, 50) +sw2.set_event_cb(lambda o,e: None) \ No newline at end of file diff --git a/examples/widgets/table/lv_example_table_1.c b/examples/widgets/table/lv_example_table_1.c new file mode 100644 index 000000000..c2c12ddbd --- /dev/null +++ b/examples/widgets/table/lv_example_table_1.c @@ -0,0 +1,66 @@ +#include "../../../lvgl.h" +#if LV_USE_TABLE + +static void event_cb(lv_obj_t * obj, lv_event_t e) +{ + if(e == LV_EVENT_DRAW_PART_BEGIN) { + lv_obj_draw_hook_dsc_t * hook_dsc = lv_event_get_param(); + /*If the cells are drawn...*/ + if(hook_dsc->part == LV_PART_ITEMS) { + uint32_t row = hook_dsc->id / lv_table_get_col_cnt(obj); + uint32_t col = hook_dsc->id - row * lv_table_get_col_cnt(obj); + + /*Make the texts in the first cell center aligned*/ + if(row == 0) { + hook_dsc->label_dsc->align = LV_TEXT_ALIGN_CENTER; + hook_dsc->rect_dsc->bg_color = lv_color_mix(LV_COLOR_BLUE, hook_dsc->rect_dsc->bg_color, LV_OPA_20); + hook_dsc->rect_dsc->bg_opa = LV_OPA_COVER; + } + /*In the first column align the texts to the right*/ + else if(col == 0) { + hook_dsc->label_dsc->flag = LV_TEXT_ALIGN_RIGHT; + } + + /*MAke every 2nd row grayish*/ + if((row != 0 && row % 2) == 0) { + hook_dsc->rect_dsc->bg_color = lv_color_mix(LV_COLOR_GRAY, hook_dsc->rect_dsc->bg_color, LV_OPA_10); + hook_dsc->rect_dsc->bg_opa = LV_OPA_COVER; + } + } + } +} + + +void lv_example_table_1(void) +{ + lv_obj_t * table = lv_table_create(lv_scr_act(), NULL); + + /*Fill the first column*/ + lv_table_set_cell_value(table, 0, 0, "Name"); + lv_table_set_cell_value(table, 1, 0, "Apple"); + lv_table_set_cell_value(table, 2, 0, "Banana"); + lv_table_set_cell_value(table, 3, 0, "Lemon"); + lv_table_set_cell_value(table, 4, 0, "Grape"); + lv_table_set_cell_value(table, 5, 0, "Melon"); + lv_table_set_cell_value(table, 6, 0, "Peach"); + lv_table_set_cell_value(table, 7, 0, "Nuts"); + + /*Fill the second column*/ + lv_table_set_cell_value(table, 0, 1, "Price"); + lv_table_set_cell_value(table, 1, 1, "$7"); + lv_table_set_cell_value(table, 2, 1, "$4"); + lv_table_set_cell_value(table, 3, 1, "$6"); + lv_table_set_cell_value(table, 4, 1, "$2"); + lv_table_set_cell_value(table, 5, 1, "$5"); + lv_table_set_cell_value(table, 6, 1, "$1"); + lv_table_set_cell_value(table, 7, 1, "$9"); + + /*Set a smaller height to the table. It'll make it scrollable*/ + lv_obj_set_height(table, 200); + lv_obj_align(table, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Add an event callback to to apply some custom drawing*/ + lv_obj_add_event_cb(table, event_cb, NULL); +} + +#endif diff --git a/examples/widgets/table/lv_example_table_1.py b/examples/widgets/table/lv_example_table_1.py new file mode 100644 index 000000000..e0959943f --- /dev/null +++ b/examples/widgets/table/lv_example_table_1.py @@ -0,0 +1,41 @@ +# Create a normal cell style +style_cell1 = lv.style_t() +lv.style_copy(style_cell1, lv.style_plain) +style_cell1.body.border.width = 1 +style_cell1.body.border.color = lv.color_make(0,0,0) + +# Crealte a header cell style +style_cell2 = lv.style_t() +lv.style_copy(style_cell2, lv.style_plain) +style_cell2.body.border.width = 1 +style_cell2.body.border.color = lv.color_make(0,0,0) +style_cell2.body.main_color = lv.color_make(0xC0, 0xC0, 0xC0) +style_cell2.body.grad_color = lv.color_make(0xC0, 0xC0, 0xC0) + +table = lv.table(lv.scr_act()) +table.set_style(lv.table.STYLE.CELL1, style_cell1) +table.set_style(lv.table.STYLE.CELL2, style_cell2) +table.set_style(lv.table.STYLE.BG, lv.style_transp_tight) +table.set_col_cnt(2) +table.set_row_cnt(4) +table.align(None, lv.ALIGN.CENTER, 0, 0) + +# Make the cells of the first row center aligned +table.set_cell_align(0, 0, lv.label.ALIGN.CENTER) +table.set_cell_align(0, 1, lv.label.ALIGN.CENTER) + +# Make the cells of the first row TYPE = 2 (use `style_cell2`) +table.set_cell_type(0, 0, 2) +table.set_cell_type(0, 1, 2) + +# Fill the first column +table.set_cell_value(0, 0, "Name") +table.set_cell_value(1, 0, "Apple") +table.set_cell_value(2, 0, "Banana") +table.set_cell_value(3, 0, "Citron") + +# Fill the second column +table.set_cell_value(0, 1, "Price") +table.set_cell_value(1, 1, "$7") +table.set_cell_value(2, 1, "$4") +table.set_cell_value(3, 1, "$6") \ No newline at end of file diff --git a/examples/widgets/tabview/lv_example_tabview_1.c b/examples/widgets/tabview/lv_example_tabview_1.c new file mode 100644 index 000000000..dc0fae45b --- /dev/null +++ b/examples/widgets/tabview/lv_example_tabview_1.c @@ -0,0 +1,41 @@ +#include "../../../lvgl.h" +#if LV_USE_TABVIEW + +void lv_example_tabview_1(void) +{ + /*Create a Tab view object*/ + lv_obj_t *tabview; + tabview = lv_tabview_create(lv_scr_act(), LV_DIR_RIGHT, 50); + + /*Add 3 tabs (the tabs are page (lv_page) and can be scrolled*/ + lv_obj_t *tab1 = lv_tabview_add_tab(tabview, "Tab 1"); + lv_obj_t *tab2 = lv_tabview_add_tab(tabview, "Tab 2"); + lv_obj_t *tab3 = lv_tabview_add_tab(tabview, "Tab 3"); + + /*Add content to the tabs*/ + lv_obj_t * label = lv_label_create(tab1, NULL); + lv_label_set_text(label, "This the first tab\n\n" + "If the content\n" + "of a tab\n" + "becomes too\n" + "longer\n" + "than the\n" + "container\n" + "then it\n" + "automatically\n" + "becomes\n" + "scrollable.\n" + "\n" + "\n" + "\n" + "Can you see it?"); + + label = lv_label_create(tab2, NULL); + lv_label_set_text(label, "Second tab"); + + label = lv_label_create(tab3, NULL); + lv_label_set_text(label, "Third tab"); + + lv_obj_scroll_to_view_recursive(label, LV_ANIM_ON); +} +#endif diff --git a/examples/widgets/tabview/lv_example_tabview_1.py b/examples/widgets/tabview/lv_example_tabview_1.py new file mode 100644 index 000000000..5dc302517 --- /dev/null +++ b/examples/widgets/tabview/lv_example_tabview_1.py @@ -0,0 +1,25 @@ +# Create a Tab view object +tabview = lv.tabview(lv.scr_act()) + +# Add 3 tabs (the tabs are page (lv_page) and can be scrolled +tab1 = tabview.add_tab("Tab 1") +tab2 = tabview.add_tab("Tab 2") +tab3 = tabview.add_tab("Tab 3") + +# Add content to the tabs +label = lv.label(tab1) +label.set_text("""This the first tab + +If the content +of a tab +become too long +the it +automatically +become +scrollable.""") + +label = lv.label(tab2) +label.set_text("Second tab") + +label = lv.label(tab3) +label.set_text("Third tab") \ No newline at end of file diff --git a/examples/widgets/textarea/lv_example_textarea_1.c b/examples/widgets/textarea/lv_example_textarea_1.c new file mode 100644 index 000000000..99e2ad6ed --- /dev/null +++ b/examples/widgets/textarea/lv_example_textarea_1.c @@ -0,0 +1,32 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_TEXTAREA + +lv_obj_t * ta1; +lv_obj_t * ta2; + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_VALUE_CHANGED) { + printf("Value: %s\n", lv_textarea_get_text(obj)); + } + else if(event == LV_EVENT_LONG_PRESSED_REPEAT) { + /*For simple test: Long press the Text are to add the text below*/ + const char * txt = "\n\nYou can scroll it if the text is long enough.\n"; + static uint16_t i = 0; + if(txt[i] != '\0') { + lv_textarea_add_char(ta1, txt[i]); + i++; + } + } +} + +void lv_example_textarea_1(void) +{ + ta1 = lv_textarea_create(lv_scr_act(), NULL); + lv_obj_align(ta1, NULL, LV_ALIGN_IN_TOP_LEFT, 0, 0); + lv_textarea_set_text(ta1, "A text in a Text Area"); /*Set an initial text*/ + lv_obj_add_event_cb(ta1, event_handler, NULL); +} + +#endif diff --git a/examples/widgets/textarea/lv_example_textarea_1.py b/examples/widgets/textarea/lv_example_textarea_1.py new file mode 100644 index 000000000..079b7f973 --- /dev/null +++ b/examples/widgets/textarea/lv_example_textarea_1.py @@ -0,0 +1,13 @@ +def event_handler(obj, event): + if event == lv.EVENT.VALUE_CHANGED: + print("Value: %s" % obj.get_text()) + elif event == lv.EVENT.LONG_PRESSED_REPEAT: + # For simple test: Long press the Text are to add the text below + ta1.add_text("\n\nYou can scroll it if the text is long enough.\n") + +ta1 = lv.ta(lv.scr_act()) +ta1.set_size(200, 100) +ta1.align(None, lv.ALIGN.CENTER, 0, 0) +ta1.set_cursor_type(lv.CURSOR.BLOCK) +ta1.set_text("A text in a Text Area") # Set an initial text +ta1.set_event_cb(event_handler) \ No newline at end of file diff --git a/examples/widgets/textarea/lv_example_textarea_2.c b/examples/widgets/textarea/lv_example_textarea_2.c new file mode 100644 index 000000000..c78806c33 --- /dev/null +++ b/examples/widgets/textarea/lv_example_textarea_2.c @@ -0,0 +1,62 @@ +//#include "../../../lvgl.h" +//#include +//#if LV_USE_TEXTAREA && LV_USE_KEYBOARD +// +//static void ta_event_cb(lv_obj_t * ta, lv_event_t event); +// +//static lv_obj_t * kb; +// +//void lv_example_textarea_2(void) +//{ +// /* Create the password box */ +// lv_obj_t * pwd_ta = lv_textarea_create(lv_scr_act(), NULL); +// lv_textarea_set_text(pwd_ta, ""); +// lv_textarea_set_pwd_mode(pwd_ta, true); +// lv_textarea_set_one_line(pwd_ta, true); +// lv_textarea_set_cursor_hidden(pwd_ta, true); +// lv_obj_set_width(pwd_ta, LV_HOR_RES / 2 - 20); +// lv_obj_set_pos(pwd_ta, 5, 20); +// lv_obj_set_event_cb(pwd_ta, ta_event_cb); +// +// /* Create a label and position it above the text box */ +// lv_obj_t * pwd_label = lv_label_create(lv_scr_act(), NULL); +// lv_label_set_text(pwd_label, "Password:"); +// lv_obj_align(pwd_label, pwd_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0); +// +// /* Create the one-line mode text area */ +// lv_obj_t * oneline_ta = lv_textarea_create(lv_scr_act(), pwd_ta); +// lv_textarea_set_pwd_mode(oneline_ta, false); +// lv_textarea_set_cursor_hidden(oneline_ta, true); +// lv_obj_align(oneline_ta, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20); +// +// +// /* Create a label and position it above the text box */ +// lv_obj_t * oneline_label = lv_label_create(lv_scr_act(), NULL); +// lv_label_set_text(oneline_label, "Text:"); +// lv_obj_align(oneline_label, oneline_ta, LV_ALIGN_OUT_TOP_LEFT, 0, 0); +// +// /* Create a keyboard */ +// kb = lv_keyboard_create(lv_scr_act(), NULL); +// lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2); +// +// lv_keyboard_set_textarea(kb, pwd_ta); /* Focus it on one of the text areas to start */ +// lv_keyboard_set_cursor_manage(kb, true); /* Automatically show/hide cursors on text areas */ +//} +// +//static void ta_event_cb(lv_obj_t * ta, lv_event_t event) +//{ +// if(event == LV_EVENT_CLICKED) { +// /* Focus on the clicked text area */ +// if(kb != NULL) +// lv_keyboard_set_textarea(kb, ta); +// } +// +// else if(event == LV_EVENT_INSERT) { +// const char * str = lv_event_get_data(); +// if(str[0] == '\n') { +// printf("Ready\n"); +// } +// } +//} +// +//#endif diff --git a/examples/widgets/textarea/lv_example_textarea_2.py b/examples/widgets/textarea/lv_example_textarea_2.py new file mode 100644 index 000000000..554f87f15 --- /dev/null +++ b/examples/widgets/textarea/lv_example_textarea_2.py @@ -0,0 +1,51 @@ +HOR_RES = lv.disp_get_hor_res(lv.disp_get_default()) + +def kb_event_cb(event_kb, event): + # Just call the regular event handler + event_kb.def_event_cb(event) + +def ta_event_cb(ta, event): + if event == lv.EVENT.INSERT: + # get inserted value + ptr = lv.C_Pointer() + ptr.ptr_val = lv.event_get_data() + if ptr.str_val == "\n": + print("Ready") + elif event == lv.EVENT.CLICKED: + # Focus on the clicked text area + kb.set_ta(ta) + +# Create the password box +pwd_ta = lv.ta(lv.scr_act()) +pwd_ta.set_text(""); +pwd_ta.set_pwd_mode(True) +pwd_ta.set_one_line(True) +pwd_ta.set_width(HOR_RES // 2 - 20) +pwd_ta.set_pos(5, 20) +pwd_ta.set_event_cb(ta_event_cb) + +# Create a label and position it above the text box +pwd_label = lv.label(lv.scr_act()) +pwd_label.set_text("Password:") +pwd_label.align(pwd_ta, lv.ALIGN.OUT_TOP_LEFT, 0, 0) + +# Create the one-line mode text area +oneline_ta = lv.ta(lv.scr_act(), pwd_ta) +oneline_ta.set_pwd_mode(False) +oneline_ta.set_cursor_type(lv.CURSOR.LINE | lv.CURSOR.HIDDEN) +oneline_ta.align(None, lv.ALIGN.IN_TOP_RIGHT, -5, 20) +oneline_ta.set_event_cb(ta_event_cb) + +# Create a label and position it above the text box +oneline_label = lv.label(lv.scr_act()) +oneline_label.set_text("Text:") +oneline_label.align(oneline_ta, lv.ALIGN.OUT_TOP_LEFT, 0, 0) + +# Create a keyboard and make it fill the width of the above text areas +kb = lv.kb(lv.scr_act()) +kb.set_pos(5, 90) +kb.set_event_cb(kb_event_cb) # Setting a custom event handler stops the keyboard from closing automatically +kb.set_size(HOR_RES - 10, 140) + +kb.set_ta(pwd_ta) # Focus it on one of the text areas to start +kb.set_cursor_manage(True) # Automatically show/hide cursors on text areas \ No newline at end of file diff --git a/examples/widgets/textarea/lv_example_textarea_3.c b/examples/widgets/textarea/lv_example_textarea_3.c new file mode 100644 index 000000000..33bbeac40 --- /dev/null +++ b/examples/widgets/textarea/lv_example_textarea_3.c @@ -0,0 +1,44 @@ +//#include "../../../lvgl.h" +//#include +//#if LV_USE_TEXTAREA && LV_USE_KEYBOARD +// +//static void ta_event_cb(lv_obj_t * ta, lv_event_t event); +// +//static lv_obj_t * kb; +// +///** +// * Automatically format text like a clock. E.g. "12:34" +// * Add the ':' automatically. +// */ +//void lv_example_textarea_3(void) +//{ +// /* Create the text area */ +// lv_obj_t * ta = lv_textarea_create(lv_scr_act(), NULL); +// lv_obj_set_event_cb(ta, ta_event_cb); +// lv_textarea_set_accepted_chars(ta, "0123456789:"); +// lv_textarea_set_max_length(ta, 5); +// lv_textarea_set_one_line(ta, true); +// lv_textarea_set_text(ta, ""); +// +// /* Create a keyboard*/ +// kb = lv_keyboard_create(lv_scr_act(), NULL); +// lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2); +// lv_keyboard_set_mode(kb, LV_KEYBOARD_MODE_NUM); +// lv_keyboard_set_textarea(kb, ta); +//} +// +//static void ta_event_cb(lv_obj_t * ta, lv_event_t event) +//{ +// if(event == LV_EVENT_VALUE_CHANGED) { +// const char * txt = lv_textarea_get_text(ta); +// if(txt[0] >= '0' && txt[0] <= '9' && +// txt[1] >= '0' && txt[1] <= '9' && +// txt[2] != ':') +// { +// lv_textarea_set_cursor_pos(ta, 2); +// lv_textarea_add_char(ta, ':'); +// } +// } +//} +// +//#endif diff --git a/examples/widgets/tileview/lv_example_tileview_1.c b/examples/widgets/tileview/lv_example_tileview_1.c new file mode 100644 index 000000000..ff8d9ca15 --- /dev/null +++ b/examples/widgets/tileview/lv_example_tileview_1.c @@ -0,0 +1,49 @@ +#include "../../../lvgl.h" +#if LV_USE_TILEVIEW + +/** + * Create a 2x2 tile view and allow scrolling only in an "L" shape. + * Demonstrate scroll chaining with a long list that + * scrolls the tile view when it cant't be scrolled further. + */ +void lv_example_tileview_1(void) +{ + lv_obj_t *tv = lv_tileview_create(lv_scr_act()); + + /*Tile1: just a label*/ + lv_obj_t * tile1 = lv_tileview_add_tile(tv, 0, 0, LV_DIR_BOTTOM); + lv_obj_t * label = lv_label_create(tile1, NULL); + lv_label_set_text(label, "Scroll down"); + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + + + /*Tile2: a button*/ + lv_obj_t * tile2 = lv_tileview_add_tile(tv, 0, 1, LV_DIR_TOP | LV_DIR_RIGHT); + + lv_obj_t * btn = lv_btn_create(tile2, NULL); + + label = lv_label_create(btn, NULL); + lv_label_set_text(label, "Scroll up or right"); + + lv_obj_set_size(btn, LV_SIZE_CONTENT, LV_SIZE_CONTENT); + lv_obj_align(btn, NULL, LV_ALIGN_CENTER, 0, 0); + + /*Tile3: a list*/ + lv_obj_t * tile3 = lv_tileview_add_tile(tv, 1, 1, LV_DIR_LEFT); + lv_obj_t * list = lv_list_create(tile3); + lv_obj_set_size(list, LV_COORD_PCT(100), LV_COORD_PCT(100)); + + lv_list_add_btn(list, NULL, "One", NULL); + lv_list_add_btn(list, NULL, "Two", NULL); + lv_list_add_btn(list, NULL, "Three", NULL); + lv_list_add_btn(list, NULL, "Four", NULL); + lv_list_add_btn(list, NULL, "Five", NULL); + lv_list_add_btn(list, NULL, "Six", NULL); + lv_list_add_btn(list, NULL, "Seven", NULL); + lv_list_add_btn(list, NULL, "Eight", NULL); + lv_list_add_btn(list, NULL, "Nine", NULL); + lv_list_add_btn(list, NULL, "Ten", NULL); + +} + +#endif diff --git a/examples/widgets/tileview/lv_example_tileview_1.py b/examples/widgets/tileview/lv_example_tileview_1.py new file mode 100644 index 000000000..520490814 --- /dev/null +++ b/examples/widgets/tileview/lv_example_tileview_1.py @@ -0,0 +1,62 @@ +valid_pos = [{"x":0, "y": 0}, {"x": 0, "y": 1}, {"x": 1,"y": 1}] + +# resolution of the screen +HOR_RES = lv.disp_get_hor_res(lv.disp_get_default()) +VER_RES = lv.disp_get_ver_res(lv.disp_get_default()) + +tileview = lv.tileview(lv.scr_act()) +tileview.set_valid_positions(valid_pos, len(valid_pos)) +tileview.set_edge_flash(True) + +tile1 = lv.obj(tileview) +tile1.set_size(HOR_RES, VER_RES) +tile1.set_style(lv.style_pretty) +tileview.add_element(tile1) + +# Tile1: just a label +label = lv.label(tile1) +label.set_text("Tile 1") +label.align(None, lv.ALIGN.CENTER, 0, 0) + +# Tile2: a list +lst = lv.list(tileview) +lst.set_size(HOR_RES, VER_RES) +lst.set_pos(0, VER_RES) +lst.set_scroll_propagation(True) +lst.set_sb_mode(lv.SB_MODE.OFF) +tileview.add_element(lst) + +list_btn = lst.add_btn(None, "One") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Two") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Three") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Four") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Five") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Six") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Seven") +tileview.add_element(list_btn) + +list_btn = lst.add_btn(None, "Eight") +tileview.add_element(list_btn) + +# Tile3: a button +tile3 = lv.obj(tileview, tile1) +tile3.set_pos(HOR_RES, VER_RES) +tileview.add_element(tile3) + +btn = lv.btn(tile3) +btn.align(None, lv.ALIGN.CENTER, 0, 0) + +label = lv.label(btn) +label.set_text("Button") \ No newline at end of file diff --git a/examples/widgets/win/lv_example_win_1.c b/examples/widgets/win/lv_example_win_1.c new file mode 100644 index 000000000..a8bbd61dd --- /dev/null +++ b/examples/widgets/win/lv_example_win_1.c @@ -0,0 +1,40 @@ +#include "../../../lvgl.h" +#include +#if LV_USE_WIN + + +static void event_handler(lv_obj_t * obj, lv_event_t event) +{ + if(event == LV_EVENT_CLICKED) { + printf("Button: %d\n", lv_obj_get_child_id(obj)); + } +} + +void lv_example_win_1(void) +{ + lv_obj_t * win = lv_win_create(lv_scr_act(), 60); + lv_win_add_btn(win, LV_SYMBOL_LEFT, 40, event_handler); + lv_win_add_title(win, "A title"); + lv_win_add_btn(win, LV_SYMBOL_RIGHT, 40, event_handler); + lv_win_add_btn(win, LV_SYMBOL_CLOSE, 60, event_handler); + + lv_obj_t * cont = lv_win_get_content(win); /*Content can be aded here*/ + lv_obj_t * label = lv_label_create(cont, NULL); + lv_label_set_text(label, "This is\n" + "a pretty\n" + "long text\n" + "to see how\n" + "the window\n" + "becomes\n" + "scrollable.\n" + "\n" + "\n" + "Some more\n" + "text to be\n" + "sure it\n" + "overflows. :)"); + + +} + +#endif diff --git a/lvgl.h b/lvgl.h index 4e6bb3325..0667c5618 100644 --- a/lvgl.h +++ b/lvgl.h @@ -68,11 +68,7 @@ extern "C" { * EXTRAS *----------------*/ #include "src/extra/widgets/lv_widgets.h" - -/* WIDGETS */ -/* LAYOUTS */ - -/* THEMES */ +#include "src/extra/layouts/lv_layouts.h" #include "src/extra/themes/lv_themes.h" diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index 9bc648b51..0bb0676b4 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -230,7 +230,7 @@ static void flex_update(lv_obj_t * cont, lv_obj_t * item) *cross_pos += t.track_cross_size + gap + track_gap; } } - LV_ASSERT_MEM_INTEGRITY(); + LV_ASSERT_MALLOC_INTEGRITY(); } /** diff --git a/src/extra/layouts/grid/lv_grid.c b/src/extra/layouts/grid/lv_grid.c index 408dfe387..704a84108 100644 --- a/src/extra/layouts/grid/lv_grid.c +++ b/src/extra/layouts/grid/lv_grid.c @@ -54,8 +54,8 @@ static lv_coord_t grid_place(lv_coord_t cont_size, bool auto_size, uint8_t plac /********************** * GLOBAL VARIABLES **********************/ -const static lv_coord_t grid_12_template[12] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), - LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1)}; +const static lv_coord_t grid_12_template[12] = {LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), + LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1), LV_GRID_FR(1)}; const lv_grid_t grid_12 = {.base.update_cb = grid_update, .col_dsc = grid_12_template, .col_dsc_len = 12, .row_dsc = grid_12_template, .row_dsc_len = 12}; /********************** @@ -211,7 +211,7 @@ static void calc(struct _lv_obj_t * cont, _lv_grid_calc_t * calc_out) lv_coord_t cont_h = lv_obj_get_height_fit(cont); calc_out->grid_h = grid_place(cont_h, auto_h, g->row_place, row_gap, calc_out->row_num, calc_out->h, calc_out->y, false); - LV_ASSERT_MEM_INTEGRITY(); + LV_ASSERT_MALLOC_INTEGRITY(); } /** diff --git a/src/extra/layouts/lv_layouts.h b/src/extra/layouts/lv_layouts.h index cf65a91f7..b26ef3586 100644 --- a/src/extra/layouts/lv_layouts.h +++ b/src/extra/layouts/lv_layouts.h @@ -13,8 +13,8 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "layouts/flex/lv_flex.h" -#include "layouts/grid/lv_grid.h" +#include "flex/lv_flex.h" +#include "grid/lv_grid.h" /********************* diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 547e23774..1d5b89de6 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -780,6 +780,13 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); } #endif + +#if LV_USE_COLORWHEEL + else if(lv_obj_check_type(obj, &lv_colorwheel_class)) { + lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->pad_normal); + lv_obj_add_style(obj, LV_PART_KNOB, LV_STATE_DEFAULT, &styles->bg_color_panel); + } +#endif } /********************** diff --git a/src/extra/widgets/colorwheel/lv_colorwheel.c b/src/extra/widgets/colorwheel/lv_colorwheel.c index f91e95771..dc3fc76f7 100644 --- a/src/extra/widgets/colorwheel/lv_colorwheel.c +++ b/src/extra/widgets/colorwheel/lv_colorwheel.c @@ -1,7 +1,7 @@ /** * @file lv_colorwheel.c * - * Based on the work of @AloyseTech and @paulpv. + * Based on the work of @AloyseTech and @paulpv. */ /********************* @@ -13,6 +13,7 @@ /********************* * DEFINES *********************/ +#define MY_CLASS &lv_colorwheel_class #define LV_CPICKER_DEF_QF 3 @@ -23,8 +24,6 @@ */ #define OUTER_MASK_WIDTH 3 -#define DRAG_LIMIT (LV_DPI / 10) - /********************** * TYPEDEFS **********************/ @@ -32,28 +31,32 @@ /********************** * STATIC PROTOTYPES **********************/ -static lv_draw_res_t lv_colorwheel_draw(lv_obj_t * colorwheel, const lv_area_t * clip_area, lv_draw_mode_t mode); -static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, void * param); -static lv_style_list_t * lv_colorwheel_get_style(lv_obj_t * colorwheel, uint8_t part); -static bool lv_colorwheel_hit(lv_obj_t * colorwheel, const lv_point_t * p); +static void lv_colorwheel_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); +static lv_draw_res_t lv_colorwheel_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode); +static lv_res_t lv_colorwheel_signal(lv_obj_t * obj, lv_signal_t sign, void * param); -static void draw_disc_grad(lv_obj_t * colorwheel, const lv_area_t * mask); -static void draw_knob(lv_obj_t * colorwheel, const lv_area_t * mask); -static void invalidate_knob(lv_obj_t * colorwheel); -static lv_area_t get_knob_area(lv_obj_t * colorwheel); +static void draw_disc_grad(lv_obj_t * obj, const lv_area_t * mask); +static void draw_knob(lv_obj_t * obj, const lv_area_t * mask); +static void invalidate_knob(lv_obj_t * obj); +static lv_area_t get_knob_area(lv_obj_t * obj); -static void next_color_mode(lv_obj_t * colorwheel); -static lv_res_t double_click_reset(lv_obj_t * colorwheel); -static void refr_knob_pos(lv_obj_t * colorwheel); -static lv_color_t angle_to_mode_color(lv_obj_t * colorwheel, uint16_t angle); -static uint16_t get_angle(lv_obj_t * colorwheel); +static void next_color_mode(lv_obj_t * obj); +static lv_res_t double_click_reset(lv_obj_t * obj); +static void refr_knob_pos(lv_obj_t * obj); +static lv_color_t angle_to_mode_color(lv_obj_t * obj, uint16_t angle); +static uint16_t get_angle(lv_obj_t * obj); /********************** * STATIC VARIABLES **********************/ -static lv_signal_cb_t ancestor_signal; -static lv_draw_cb_t ancestor_draw; -static bool inited; +const lv_obj_class_t lv_colorwheel_class = {.instance_size = sizeof(lv_colorwheel_t), .base_class = &lv_obj_class, + .constructor_cb = lv_colorwheel_constructor, + .draw_cb = lv_colorwheel_draw, + .signal_cb = lv_colorwheel_signal, + .editable = LV_OBJ_CLASS_EDITABLE_TRUE, +}; + +static bool create_knob_recolor; /********************** * MACROS @@ -71,54 +74,8 @@ static bool inited; */ lv_obj_t * lv_colorwheel_create(lv_obj_t * parent, bool knob_recolor) { - static lv_style_t style_knob; - if(!inited) { - lv_style_init(&style_knob); - lv_style_set_bg_color(&style_knob, LV_STATE_DEFAULT, LV_COLOR_GRAY); - lv_style_set_border_color(&style_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); - lv_style_set_border_width(&style_knob, LV_STATE_DEFAULT, LV_DPX(1)); - lv_style_set_bg_opa(&style_knob, LV_STATE_DEFAULT, LV_OPA_COVER); - lv_style_set_radius(&style_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_set_pad_all(&style_knob, LV_STATE_DEFAULT, LV_DPX(5)); - inited = true; - } - lv_obj_t * colorwheel = lv_obj_create(parent, NULL); - LV_ASSERT_MEM(colorwheel); - if(colorwheel == NULL) return NULL; - - if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(colorwheel); - if(ancestor_draw == NULL) ancestor_draw = lv_obj_get_draw_cb(colorwheel); - - /*Allocate the extended data*/ - lv_colorwheel_ext_t * ext = lv_obj_allocate_ext_attr(colorwheel, sizeof(lv_colorwheel_ext_t)); - LV_ASSERT_MEM(ext); - if(ext == NULL) { - lv_obj_del(colorwheel); - return NULL; - } - - /*Initialize the allocated 'ext' */ - ext->hsv.h = 0; - ext->hsv.s = 100; - ext->hsv.v = 100; - ext->mode = LV_COLORWHEEL_MODE_HUE; - ext->mode_fixed = 0; - ext->last_click_time = 0; - ext->last_change_time = 0; - ext->knob.recolor = knob_recolor; - - lv_style_list_init(&ext->knob.style_list); - - /*The signal and draw functions are not copied so set them here*/ - lv_obj_set_signal_cb(colorwheel, lv_colorwheel_signal); - lv_obj_set_draw_cb(colorwheel, lv_colorwheel_draw); - - lv_obj_set_size(colorwheel, LV_DPI * 2, LV_DPI * 2); - lv_obj_add_flag(colorwheel, LV_OBJ_FLAG_ADV_HITTEST); - lv_obj_add_style(colorwheel, LV_COLORWHEEL_PART_KNOB, &style_knob); - refr_knob_pos(colorwheel); - - return colorwheel; + create_knob_recolor = knob_recolor; + return lv_obj_create_from_class(&lv_colorwheel_class, parent, NULL); } /*===================== @@ -131,21 +88,21 @@ lv_obj_t * lv_colorwheel_create(lv_obj_t * parent, bool knob_recolor) * @param color current selected hsv * @return true if changed, otherwise false */ -bool lv_colorwheel_set_hsv(lv_obj_t * colorwheel, lv_color_hsv_t hsv) +bool lv_colorwheel_set_hsv(lv_obj_t * obj, lv_color_hsv_t hsv) { if(hsv.h > 360) hsv.h %= 360; if(hsv.s > 100) hsv.s = 100; if(hsv.v > 100) hsv.v = 100; - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - if(ext->hsv.h == hsv.h && ext->hsv.s == hsv.s && ext->hsv.v == hsv.v) return false; + if(colorwheel->hsv.h == hsv.h && colorwheel->hsv.s == hsv.s && colorwheel->hsv.v == hsv.v) return false; - ext->hsv = hsv; + colorwheel->hsv = hsv; - refr_knob_pos(colorwheel); + refr_knob_pos(obj); - lv_obj_invalidate(colorwheel); + lv_obj_invalidate(obj); return true; } @@ -156,13 +113,12 @@ bool lv_colorwheel_set_hsv(lv_obj_t * colorwheel, lv_color_hsv_t hsv) * @param color current selected color * @return true if changed, otherwise false */ -bool lv_colorwheel_set_rgb(lv_obj_t * colorwheel, lv_color_t color) +bool lv_colorwheel_set_rgb(lv_obj_t * obj, lv_color_t color) { lv_color32_t c32; c32.full = lv_color_to32(color); - return lv_colorwheel_set_hsv(colorwheel, - lv_color_rgb_to_hsv(c32.ch.red, c32.ch.green, c32.ch.blue)); + return lv_colorwheel_set_hsv(obj, lv_color_rgb_to_hsv(c32.ch.red, c32.ch.green, c32.ch.blue)); } /** @@ -170,13 +126,13 @@ bool lv_colorwheel_set_rgb(lv_obj_t * colorwheel, lv_color_t color) * @param colorwheel pointer to color wheel object * @param mode color mode (hue/sat/val) */ -void lv_colorwheel_set_mode(lv_obj_t * colorwheel, lv_colorwheel_mode_t mode) +void lv_colorwheel_set_mode(lv_obj_t * obj, lv_colorwheel_mode_t mode) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - ext->mode = mode; - refr_knob_pos(colorwheel); - lv_obj_invalidate(colorwheel); + colorwheel->mode = mode; + refr_knob_pos(obj); + lv_obj_invalidate(obj); } /** @@ -184,11 +140,11 @@ void lv_colorwheel_set_mode(lv_obj_t * colorwheel, lv_colorwheel_mode_t mode) * @param colorwheel pointer to color wheel object * @param fixed color mode cannot be changed on long press */ -void lv_colorwheel_set_mode_fixed(lv_obj_t * colorwheel, bool fixed) +void lv_colorwheel_set_mode_fixed(lv_obj_t * obj, bool fixed) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - ext->mode_fixed = fixed; + colorwheel->mode_fixed = fixed; } /*===================== @@ -201,11 +157,11 @@ void lv_colorwheel_set_mode_fixed(lv_obj_t * colorwheel, bool fixed) * @param colorwheel pointer to color wheel object * @return current selected hsv */ -lv_color_hsv_t lv_colorwheel_get_hsv(lv_obj_t * colorwheel) +lv_color_hsv_t lv_colorwheel_get_hsv(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - return ext->hsv; + return colorwheel->hsv; } /** @@ -213,11 +169,11 @@ lv_color_hsv_t lv_colorwheel_get_hsv(lv_obj_t * colorwheel) * @param colorwheel pointer to color wheel object * @return color current selected color */ -lv_color_t lv_colorwheel_get_rgb(lv_obj_t * colorwheel) +lv_color_t lv_colorwheel_get_rgb(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - return lv_color_hsv_to_rgb(ext->hsv.h, ext->hsv.s, ext->hsv.v); + return lv_color_hsv_to_rgb(colorwheel->hsv.h, colorwheel->hsv.s, colorwheel->hsv.v); } /** @@ -225,11 +181,11 @@ lv_color_t lv_colorwheel_get_rgb(lv_obj_t * colorwheel) * @param colorwheel pointer to color wheel object * @return color mode (hue/sat/val) */ -lv_colorwheel_mode_t lv_colorwheel_get_color_mode(lv_obj_t * colorwheel) +lv_colorwheel_mode_t lv_colorwheel_get_color_mode(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - return ext->mode; + return colorwheel->mode; } /** @@ -237,11 +193,11 @@ lv_colorwheel_mode_t lv_colorwheel_get_color_mode(lv_obj_t * colorwheel) * @param colorwheel pointer to color wheel object * @return mode cannot be changed on long press */ -bool lv_colorwheel_get_color_mode_fixed(lv_obj_t * colorwheel) +bool lv_colorwheel_get_color_mode_fixed(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - return ext->mode_fixed; + return colorwheel->mode_fixed; } /*===================== @@ -252,150 +208,139 @@ bool lv_colorwheel_get_color_mode_fixed(lv_obj_t * colorwheel) * STATIC FUNCTIONS **********************/ -/** - * Handle the drawing related tasks of the color_picker - * @param colorwheel pointer to an object - * @param mask the object will be drawn only in this area - * @param mode LV_DRAW_COVER_CHK: only check if the object fully covers the 'mask_p' area - * (return 'true' if yes) - * LV_DRAW_DRAW: draw the object (always return 'true') - * LV_DRAW_DRAW_POST: drawing after every children are drawn - * @return return an element of `lv_draw_res_t` - */ -static lv_draw_res_t lv_colorwheel_draw(lv_obj_t * colorwheel, const lv_area_t * clip_area, lv_draw_mode_t mode) +static void lv_colorwheel_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; + colorwheel->hsv.h = 0; + colorwheel->hsv.s = 100; + colorwheel->hsv.v = 100; + colorwheel->mode = LV_COLORWHEEL_MODE_HUE; + colorwheel->mode_fixed = 0; + colorwheel->last_click_time = 0; + colorwheel->last_change_time = 0; + colorwheel->knob.recolor = create_knob_recolor; + + lv_obj_set_size(obj, LV_DPI_DEF * 2, LV_DPI_DEF * 2); + lv_obj_add_flag(obj, LV_OBJ_FLAG_ADV_HITTEST); + refr_knob_pos(obj); +} + +static lv_draw_res_t lv_colorwheel_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv_draw_mode_t mode) { /*Return false if the object is not covers the mask_p area*/ - if(mode == LV_DRAW_COVER_CHK) { + if(mode == LV_DRAW_MODE_COVER_CHECK) { return LV_DRAW_RES_NOT_COVER; } /*Draw the object*/ - else if(mode == LV_DRAW_DRAW_MAIN) { - draw_disc_grad(colorwheel, clip_area); - draw_knob(colorwheel, clip_area); + else if(mode == LV_DRAW_MODE_MAIN_DRAW) { + draw_disc_grad(obj, clip_area); + draw_knob(obj, clip_area); } /*Post draw when the children are drawn*/ - else if(mode == LV_DRAW_DRAW_POST) { + else if(mode == LV_DRAW_MODE_POST_DRAW) { } return LV_DRAW_RES_OK; } -static void draw_disc_grad(lv_obj_t * colorwheel, const lv_area_t * mask) +static void draw_disc_grad(lv_obj_t * obj, const lv_area_t * mask) { - lv_coord_t w = lv_obj_get_width(colorwheel); - lv_coord_t h = lv_obj_get_height(colorwheel); - lv_coord_t cx = colorwheel->coords.x1 + w / 2; - lv_coord_t cy = colorwheel->coords.y1 + h / 2; + lv_coord_t w = lv_obj_get_width(obj); + lv_coord_t h = lv_obj_get_height(obj); + lv_coord_t cx = obj->coords.x1 + w / 2; + lv_coord_t cy = obj->coords.y1 + h / 2; lv_coord_t r = w / 2; lv_draw_line_dsc_t line_dsc; lv_draw_line_dsc_init(&line_dsc); - lv_obj_init_draw_line_dsc(colorwheel, LV_COLORWHEEL_PART_MAIN, &line_dsc); + lv_obj_init_draw_line_dsc(obj, LV_PART_MAIN, &line_dsc); line_dsc.width = (r * 628 / (360 / LV_CPICKER_DEF_QF)) / 100; line_dsc.width += 2; uint16_t i; - lv_coord_t cir_w = lv_obj_get_style_scale_width(colorwheel, LV_COLORWHEEL_PART_MAIN); + lv_coord_t cir_w = lv_obj_get_style_arc_width(obj, LV_PART_MAIN); /* Mask outer ring of widget to tidy up ragged edges of lines while drawing outer ring */ - lv_area_t mask_area_out; - lv_area_copy(&mask_area_out, &colorwheel->coords); - mask_area_out.x1 += OUTER_MASK_WIDTH; - mask_area_out.x2 -= OUTER_MASK_WIDTH; - mask_area_out.y1 += OUTER_MASK_WIDTH; - mask_area_out.y2 -= OUTER_MASK_WIDTH; lv_draw_mask_radius_param_t mask_out_param; - lv_draw_mask_radius_init(&mask_out_param, &mask_area_out, LV_RADIUS_CIRCLE, false); + lv_draw_mask_radius_init(&mask_out_param, &obj->coords, LV_RADIUS_CIRCLE, false); int16_t mask_out_id = lv_draw_mask_add(&mask_out_param, 0); + + lv_area_t mask_area; + lv_area_copy(&mask_area, &obj->coords); + mask_area.x1 += cir_w; + mask_area.x2 -= cir_w; + mask_area.y1 += cir_w; + mask_area.y2 -= cir_w; + lv_draw_mask_radius_param_t mask_in_param; + lv_draw_mask_radius_init(&mask_in_param, &mask_area, LV_RADIUS_CIRCLE, true); + int16_t mask_in_id = lv_draw_mask_add(&mask_in_param, 0); + /* The inner line ends will be masked out. * So make lines a little bit longer because the masking makes a more even result */ lv_coord_t cir_w_extra = cir_w + line_dsc.width; + for(i = 0; i <= 360; i += LV_CPICKER_DEF_QF) { - line_dsc.color = angle_to_mode_color(colorwheel, i); + line_dsc.color = angle_to_mode_color(obj, i); lv_point_t p[2]; - p[0].x = cx + (r * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); - p[0].y = cy + (r * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT); + p[0].x = cx + ((r + line_dsc.width) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); + p[0].y = cy + ((r + line_dsc.width) * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT); p[1].x = cx + ((r - cir_w_extra) * lv_trigo_sin(i) >> LV_TRIGO_SHIFT); p[1].y = cy + ((r - cir_w_extra) * lv_trigo_sin(i + 90) >> LV_TRIGO_SHIFT); lv_draw_line(&p[0], &p[1], mask, &line_dsc); } - /* Now remove mask to continue with inner part */ lv_draw_mask_remove_id(mask_out_id); + lv_draw_mask_remove_id(mask_in_id); - /*Mask out the inner area*/ - lv_draw_rect_dsc_t bg_dsc; - lv_draw_rect_dsc_init(&bg_dsc); - lv_obj_init_draw_rect_dsc(colorwheel, LV_COLORWHEEL_PART_MAIN, &bg_dsc); - bg_dsc.radius = LV_RADIUS_CIRCLE; - - lv_area_t area_mid; - lv_area_copy(&area_mid, &colorwheel->coords); - area_mid.x1 += cir_w; - area_mid.y1 += cir_w; - area_mid.x2 -= cir_w; - area_mid.y2 -= cir_w; - - lv_draw_rect(&area_mid, mask, &bg_dsc); - - lv_coord_t inner = cir_w / 2; - lv_color_t color = lv_colorwheel_get_rgb(colorwheel); - bg_dsc.bg_color = color; - area_mid.x1 += inner; - area_mid.y1 += inner; - area_mid.x2 -= inner; - area_mid.y2 -= inner; - - lv_draw_rect(&area_mid, mask, &bg_dsc); } -static void draw_knob(lv_obj_t * colorwheel, const lv_area_t * mask) +static void draw_knob(lv_obj_t * obj, const lv_area_t * mask) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; lv_draw_rect_dsc_t cir_dsc; lv_draw_rect_dsc_init(&cir_dsc); - lv_obj_init_draw_rect_dsc(colorwheel, LV_COLORWHEEL_PART_KNOB, &cir_dsc); + lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &cir_dsc); cir_dsc.radius = LV_RADIUS_CIRCLE; - if(ext->knob.recolor) { - cir_dsc.bg_color = lv_colorwheel_get_rgb(colorwheel); + if(colorwheel->knob.recolor) { + cir_dsc.bg_color = lv_colorwheel_get_rgb(obj); } - lv_area_t knob_area = get_knob_area(colorwheel); + lv_area_t knob_area = get_knob_area(obj); lv_draw_rect(&knob_area, mask, &cir_dsc); } -static void invalidate_knob(lv_obj_t * colorwheel) +static void invalidate_knob(lv_obj_t * obj) { - lv_area_t knob_area = get_knob_area(colorwheel); + lv_area_t knob_area = get_knob_area(obj); - lv_obj_invalidate_area(colorwheel, &knob_area); + lv_obj_invalidate_area(obj, &knob_area); } -static lv_area_t get_knob_area(lv_obj_t * colorwheel) +static lv_area_t get_knob_area(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; /*Get knob's radius*/ uint16_t r = 0; - r = lv_obj_get_style_scale_width(colorwheel, LV_COLORWHEEL_PART_MAIN) / 2; + r = lv_obj_get_style_arc_width(obj, LV_PART_MAIN) / 2; - lv_coord_t left = lv_obj_get_style_pad_left(colorwheel, LV_COLORWHEEL_PART_KNOB); - lv_coord_t right = lv_obj_get_style_pad_right(colorwheel, LV_COLORWHEEL_PART_KNOB); - lv_coord_t top = lv_obj_get_style_pad_top(colorwheel, LV_COLORWHEEL_PART_KNOB); - lv_coord_t bottom = lv_obj_get_style_pad_bottom(colorwheel, LV_COLORWHEEL_PART_KNOB); + lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB); + lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB); + lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB); + lv_coord_t bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB); lv_area_t knob_area; - knob_area.x1 = colorwheel->coords.x1 + ext->knob.pos.x - r - left; - knob_area.y1 = colorwheel->coords.y1 + ext->knob.pos.y - r - right; - knob_area.x2 = colorwheel->coords.x1 + ext->knob.pos.x + r + top; - knob_area.y2 = colorwheel->coords.y1 + ext->knob.pos.y + r + bottom; + knob_area.x1 = obj->coords.x1 + colorwheel->knob.pos.x - r - left; + knob_area.y1 = obj->coords.y1 + colorwheel->knob.pos.y - r - right; + knob_area.x2 = obj->coords.x1 + colorwheel->knob.pos.x + r + top; + knob_area.y2 = obj->coords.y1 + colorwheel->knob.pos.y + r + bottom; return knob_area; } @@ -407,31 +352,20 @@ static lv_area_t get_knob_area(lv_obj_t * colorwheel) * @param param pointer to a signal specific variable * @return LV_RES_OK: the object is not deleted in the function; LV_RES_INV: the object is deleted */ -static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, void * param) +static lv_res_t lv_colorwheel_signal(lv_obj_t * obj, lv_signal_t sign, void * param) { /* Include the ancient signal function */ - lv_res_t res; + lv_res_t res = lv_obj_signal_base(MY_CLASS, obj, sign, param); - if(sign == LV_SIGNAL_GET_STYLE) { - lv_get_style_info_t * info = param; - info->result = lv_colorwheel_get_style(colorwheel, info->part); - if(info->result != NULL) return LV_RES_OK; - else return ancestor_signal(colorwheel, sign, param); - } - - res = ancestor_signal(colorwheel, sign, param); if(res != LV_RES_OK) return res; - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; - if(sign == LV_SIGNAL_CLEANUP) { - _lv_obj_reset_style_list_no_refr(colorwheel, LV_COLORWHEEL_PART_KNOB); - } - else if(sign == LV_SIGNAL_REFR_EXT_DRAW_PAD) { - lv_coord_t left = lv_obj_get_style_pad_left(colorwheel, LV_COLORWHEEL_PART_KNOB); - lv_coord_t right = lv_obj_get_style_pad_right(colorwheel, LV_COLORWHEEL_PART_KNOB); - lv_coord_t top = lv_obj_get_style_pad_top(colorwheel, LV_COLORWHEEL_PART_KNOB); - lv_coord_t bottom = lv_obj_get_style_pad_bottom(colorwheel, LV_COLORWHEEL_PART_KNOB); + if(sign == LV_SIGNAL_REFR_EXT_DRAW_SIZE) { + lv_coord_t left = lv_obj_get_style_pad_left(obj, LV_PART_KNOB); + lv_coord_t right = lv_obj_get_style_pad_right(obj, LV_PART_KNOB); + lv_coord_t top = lv_obj_get_style_pad_top(obj, LV_PART_KNOB); + lv_coord_t bottom = lv_obj_get_style_pad_bottom(obj, LV_PART_KNOB); lv_coord_t knob_pad = LV_MAX4(left, right, top, bottom) + 2; lv_coord_t * s = param; @@ -439,67 +373,65 @@ static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, vo } else if(sign == LV_SIGNAL_COORD_CHG) { /*Refresh extended draw area to make knob visible*/ - if(lv_obj_get_width(colorwheel) != lv_area_get_width(param) || - lv_obj_get_height(colorwheel) != lv_area_get_height(param)) { - refr_knob_pos(colorwheel); + if(lv_obj_get_width(obj) != lv_area_get_width(param) || + lv_obj_get_height(obj) != lv_area_get_height(param)) { + refr_knob_pos(obj); } } else if(sign == LV_SIGNAL_STYLE_CHG) { /*Refresh extended draw area to make knob visible*/ - refr_knob_pos(colorwheel); + refr_knob_pos(obj); } else if(sign == LV_SIGNAL_CONTROL) { -#if LV_USE_GROUP uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ if(c == LV_KEY_RIGHT || c == LV_KEY_UP) { lv_color_hsv_t hsv_cur; - hsv_cur = ext->hsv; + hsv_cur = colorwheel->hsv; - switch(ext->mode) { + switch(colorwheel->mode) { case LV_COLORWHEEL_MODE_HUE: - hsv_cur.h = (ext->hsv.h + 1) % 360; + hsv_cur.h = (colorwheel->hsv.h + 1) % 360; break; case LV_COLORWHEEL_MODE_SATURATION: - hsv_cur.s = (ext->hsv.s + 1) % 100; + hsv_cur.s = (colorwheel->hsv.s + 1) % 100; break; case LV_COLORWHEEL_MODE_VALUE: - hsv_cur.v = (ext->hsv.v + 1) % 100; + hsv_cur.v = (colorwheel->hsv.v + 1) % 100; break; } - if(lv_colorwheel_set_hsv(colorwheel, hsv_cur)) { - res = lv_event_send(colorwheel, LV_EVENT_VALUE_CHANGED, NULL); + if(lv_colorwheel_set_hsv(obj, hsv_cur)) { + res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } else if(c == LV_KEY_LEFT || c == LV_KEY_DOWN) { lv_color_hsv_t hsv_cur; - hsv_cur = ext->hsv; + hsv_cur = colorwheel->hsv; - switch(ext->mode) { + switch(colorwheel->mode) { case LV_COLORWHEEL_MODE_HUE: - hsv_cur.h = ext->hsv.h > 0 ? (ext->hsv.h - 1) : 360; + hsv_cur.h = colorwheel->hsv.h > 0 ? (colorwheel->hsv.h - 1) : 360; break; case LV_COLORWHEEL_MODE_SATURATION: - hsv_cur.s = ext->hsv.s > 0 ? (ext->hsv.s - 1) : 100; + hsv_cur.s = colorwheel->hsv.s > 0 ? (colorwheel->hsv.s - 1) : 100; break; case LV_COLORWHEEL_MODE_VALUE: - hsv_cur.v = ext->hsv.v > 0 ? (ext->hsv.v - 1) : 100; + hsv_cur.v = colorwheel->hsv.v > 0 ? (colorwheel->hsv.v - 1) : 100; break; } - if(lv_colorwheel_set_hsv(colorwheel, hsv_cur)) { - res = lv_event_send(colorwheel, LV_EVENT_VALUE_CHANGED, NULL); + if(lv_colorwheel_set_hsv(obj, hsv_cur)) { + res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } -#endif } else if(sign == LV_SIGNAL_PRESSED) { - ext->last_change_time = lv_tick_get(); - lv_indev_get_point(lv_indev_get_act(), &ext->last_press_point); - res = double_click_reset(colorwheel); + colorwheel->last_change_time = lv_tick_get(); + lv_indev_get_point(lv_indev_get_act(), &colorwheel->last_press_point); + res = double_click_reset(obj); if(res != LV_RES_OK) return res; } else if(sign == LV_SIGNAL_PRESSING) { @@ -509,39 +441,40 @@ static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, vo lv_indev_type_t indev_type = lv_indev_get_type(indev); lv_point_t p; if(indev_type == LV_INDEV_TYPE_ENCODER || indev_type == LV_INDEV_TYPE_KEYPAD) { - p.x = colorwheel->coords.x1 + lv_obj_get_width(colorwheel) / 2; - p.y = colorwheel->coords.y1 + lv_obj_get_height(colorwheel) / 2; + p.x = obj->coords.x1 + lv_obj_get_width(obj) / 2; + p.y = obj->coords.y1 + lv_obj_get_height(obj) / 2; } else { lv_indev_get_point(indev, &p); } - if((LV_ABS(p.x - ext->last_press_point.x) > DRAG_LIMIT) || - (LV_ABS(p.y - ext->last_press_point.y) > DRAG_LIMIT)) { - ext->last_change_time = lv_tick_get(); - ext->last_press_point.x = p.x; - ext->last_press_point.y = p.y; + lv_coord_t drag_limit = indev->driver.scroll_limit; + if((LV_ABS(p.x - colorwheel->last_press_point.x) > drag_limit) || + (LV_ABS(p.y - colorwheel->last_press_point.y) > drag_limit)) { + colorwheel->last_change_time = lv_tick_get(); + colorwheel->last_press_point.x = p.x; + colorwheel->last_press_point.y = p.y; } - p.x -= colorwheel->coords.x1; - p.y -= colorwheel->coords.y1; + p.x -= obj->coords.x1; + p.y -= obj->coords.y1; /*Ignore pressing in the inner area*/ - uint16_t w = lv_obj_get_width(colorwheel); + uint16_t w = lv_obj_get_width(obj); int16_t angle = 0; - lv_coord_t cir_w = lv_obj_get_style_scale_width(colorwheel, LV_COLORWHEEL_PART_MAIN); + lv_coord_t cir_w = lv_obj_get_style_arc_width(obj, LV_PART_MAIN); lv_coord_t r_in = w / 2; p.x -= r_in; p.y -= r_in; bool on_ring = true; r_in -= cir_w; - if(r_in > LV_DPI / 2) { + if(r_in > LV_DPI_DEF / 2) { lv_coord_t inner = cir_w / 2; r_in -= inner; - if(r_in < LV_DPI / 2) r_in = LV_DPI / 2; + if(r_in < LV_DPI_DEF / 2) r_in = LV_DPI_DEF / 2; } if(p.x * p.x + p.y * p.y < r_in * r_in) { @@ -549,9 +482,9 @@ static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, vo } /*If the inner area is being pressed, go to the next color mode on long press*/ - uint32_t diff = lv_tick_elaps(ext->last_change_time); - if(!on_ring && diff > indev->driver.long_press_time && !ext->mode_fixed) { - next_color_mode(colorwheel); + uint32_t diff = lv_tick_elaps(colorwheel->last_change_time); + if(!on_ring && diff > indev->driver.long_press_time && !colorwheel->mode_fixed) { + next_color_mode(obj); lv_indev_wait_release(lv_indev_get_act()); return res; } @@ -562,9 +495,9 @@ static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, vo angle = lv_atan2(p.x, p.y) % 360; lv_color_hsv_t hsv_cur; - hsv_cur = ext->hsv; + hsv_cur = colorwheel->hsv; - switch(ext->mode) { + switch(colorwheel->mode) { case LV_COLORWHEEL_MODE_HUE: hsv_cur.h = angle; break; @@ -576,92 +509,59 @@ static lv_res_t lv_colorwheel_signal(lv_obj_t * colorwheel, lv_signal_t sign, vo break; } - if(lv_colorwheel_set_hsv(colorwheel, hsv_cur)) { - res = lv_event_send(colorwheel, LV_EVENT_VALUE_CHANGED, NULL); + if(lv_colorwheel_set_hsv(obj, hsv_cur)) { + res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } else if(sign == LV_SIGNAL_HIT_TEST) { lv_hit_test_info_t * info = param; - info->result = lv_colorwheel_hit(colorwheel, info->point); + + /*Valid clicks can be only in the circle*/ + info->result = _lv_area_is_point_on(&obj->coords, info->point, LV_RADIUS_CIRCLE); } return res; } -/** - * Get the style_list descriptor of a part of the object - * @param colorwheel pointer the object - * @param part the part of the colorwheel. (LV_PAGE_CPICKER_...) - * @return pointer to the style_list descriptor of the specified part - */ -static lv_style_list_t * lv_colorwheel_get_style(lv_obj_t * colorwheel, uint8_t part) + +static void next_color_mode(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); - lv_style_list_t * style_dsc_p; - - switch(part) { - case LV_COLORWHEEL_PART_MAIN : - style_dsc_p = &colorwheel->style_list; - break; - case LV_COLORWHEEL_PART_KNOB: - style_dsc_p = &ext->knob.style_list; - break; - default: - style_dsc_p = NULL; - } - - return style_dsc_p; + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; + colorwheel->mode = (colorwheel->mode + 1) % 3; + refr_knob_pos(obj); + lv_obj_invalidate(obj); } -static bool lv_colorwheel_hit(lv_obj_t * colorwheel, const lv_point_t * p) +static void refr_knob_pos(lv_obj_t * obj) { - bool is_point_on_coords = _lv_obj_is_click_point_on(colorwheel, p); - if(!is_point_on_coords) return false; + invalidate_knob(obj); - /*Valid clicks can be only in the circle*/ - if(_lv_area_is_point_on(&colorwheel->coords, p, LV_RADIUS_CIRCLE)) return true; - else return false; -} + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; + lv_coord_t w = lv_obj_get_width(obj); -static void next_color_mode(lv_obj_t * colorwheel) -{ - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); - ext->mode = (ext->mode + 1) % 3; - refr_knob_pos(colorwheel); - lv_obj_invalidate(colorwheel); -} - -static void refr_knob_pos(lv_obj_t * colorwheel) -{ - invalidate_knob(colorwheel); - - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); - lv_coord_t w = lv_obj_get_width(colorwheel); - lv_coord_t h = lv_obj_get_height(colorwheel); - - lv_coord_t scale_w = lv_obj_get_style_scale_width(colorwheel, LV_COLORWHEEL_PART_MAIN); + lv_coord_t scale_w = lv_obj_get_style_arc_width(obj, LV_PART_MAIN); lv_coord_t r = (w - scale_w) / 2; - uint16_t angle = get_angle(colorwheel); - ext->knob.pos.x = (((int32_t)r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT); - ext->knob.pos.y = (((int32_t)r * lv_trigo_sin(angle + 90)) >> LV_TRIGO_SHIFT); - ext->knob.pos.x = ext->knob.pos.x + w / 2; - ext->knob.pos.y = ext->knob.pos.y + h / 2; + uint16_t angle = get_angle(obj); + colorwheel->knob.pos.x = (((int32_t)r * lv_trigo_sin(angle)) >> LV_TRIGO_SHIFT); + colorwheel->knob.pos.y = (((int32_t)r * lv_trigo_cos(angle)) >> LV_TRIGO_SHIFT); + colorwheel->knob.pos.x = colorwheel->knob.pos.x + w / 2; + colorwheel->knob.pos.y = colorwheel->knob.pos.y + w / 2; - invalidate_knob(colorwheel); + invalidate_knob(obj); } -static lv_res_t double_click_reset(lv_obj_t * colorwheel) +static lv_res_t double_click_reset(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; lv_indev_t * indev = lv_indev_get_act(); /*Double clicked? Use long press time as double click time out*/ - if(lv_tick_elaps(ext->last_click_time) < indev->driver.long_press_time) { + if(lv_tick_elaps(colorwheel->last_click_time) < indev->driver.long_press_time) { lv_color_hsv_t hsv_cur; - hsv_cur = ext->hsv; + hsv_cur = colorwheel->hsv; - switch(ext->mode) { + switch(colorwheel->mode) { case LV_COLORWHEEL_MODE_HUE: hsv_cur.h = 0; break; @@ -675,51 +575,51 @@ static lv_res_t double_click_reset(lv_obj_t * colorwheel) lv_indev_wait_release(indev); - if(lv_colorwheel_set_hsv(colorwheel, hsv_cur)) { - lv_res_t res = lv_event_send(colorwheel, LV_EVENT_VALUE_CHANGED, NULL); + if(lv_colorwheel_set_hsv(obj, hsv_cur)) { + lv_res_t res = lv_event_send(obj, LV_EVENT_VALUE_CHANGED, NULL); if(res != LV_RES_OK) return res; } } - ext->last_click_time = lv_tick_get(); + colorwheel->last_click_time = lv_tick_get(); return LV_RES_OK; } -static lv_color_t angle_to_mode_color(lv_obj_t * colorwheel, uint16_t angle) +static lv_color_t angle_to_mode_color(lv_obj_t * obj, uint16_t angle) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; lv_color_t color; angle = angle % 360; - switch(ext->mode) { + switch(colorwheel->mode) { default: case LV_COLORWHEEL_MODE_HUE: - color = lv_color_hsv_to_rgb(angle, ext->hsv.s, ext->hsv.v); + color = lv_color_hsv_to_rgb(angle, colorwheel->hsv.s, colorwheel->hsv.v); break; case LV_COLORWHEEL_MODE_SATURATION: - color = lv_color_hsv_to_rgb(ext->hsv.h, (angle * 100) / 360, ext->hsv.v); + color = lv_color_hsv_to_rgb(colorwheel->hsv.h, (angle * 100) / 360, colorwheel->hsv.v); break; case LV_COLORWHEEL_MODE_VALUE: - color = lv_color_hsv_to_rgb(ext->hsv.h, ext->hsv.s, (angle * 100) / 360); + color = lv_color_hsv_to_rgb(colorwheel->hsv.h, colorwheel->hsv.s, (angle * 100) / 360); break; } return color; } -static uint16_t get_angle(lv_obj_t * colorwheel) +static uint16_t get_angle(lv_obj_t * obj) { - lv_colorwheel_ext_t * ext = lv_obj_get_ext_attr(colorwheel); + lv_colorwheel_t * colorwheel = (lv_colorwheel_t *) obj; uint16_t angle; - switch(ext->mode) { + switch(colorwheel->mode) { default: case LV_COLORWHEEL_MODE_HUE: - angle = ext->hsv.h; + angle = colorwheel->hsv.h; break; case LV_COLORWHEEL_MODE_SATURATION: - angle = (ext->hsv.s * 360) / 100; + angle = (colorwheel->hsv.s * 360) / 100; break; case LV_COLORWHEEL_MODE_VALUE: - angle = (ext->hsv.v * 360) / 100 ; + angle = (colorwheel->hsv.v * 360) / 100 ; break; } return angle; diff --git a/src/extra/widgets/colorwheel/lv_colorwheel.h b/src/extra/widgets/colorwheel/lv_colorwheel.h index 8be55c298..d046bdb45 100644 --- a/src/extra/widgets/colorwheel/lv_colorwheel.h +++ b/src/extra/widgets/colorwheel/lv_colorwheel.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../../lv_core/lv_obj.h" +#include "../../../lvgl.h" #if LV_USE_COLORWHEEL @@ -35,9 +35,9 @@ typedef uint8_t lv_colorwheel_mode_t; /*Data of color picker*/ typedef struct { + lv_obj_t obj; lv_color_hsv_t hsv; struct { - lv_style_list_t style_list; lv_point_t pos; uint8_t recolor : 1; } knob; @@ -46,15 +46,9 @@ typedef struct { lv_point_t last_press_point; lv_colorwheel_mode_t mode : 2; uint8_t mode_fixed : 1; -} lv_colorwheel_ext_t; - -/*Parts*/ -enum { - LV_COLORWHEEL_PART_MAIN = LV_OBJ_PART_MAIN, - LV_COLORWHEEL_PART_KNOB, - _LV_COLORWHEEL_PART_VIRTUAL_LAST, -}; +} lv_colorwheel_t; +extern const lv_obj_class_t lv_colorwheel_class; /********************** * GLOBAL PROTOTYPES diff --git a/src/extra/widgets/imgbtn/lv_imgbtn.c b/src/extra/widgets/imgbtn/lv_imgbtn.c index aceb2f7a9..20cb76170 100644 --- a/src/extra/widgets/imgbtn/lv_imgbtn.c +++ b/src/extra/widgets/imgbtn/lv_imgbtn.c @@ -7,7 +7,7 @@ // * INCLUDES // *********************/ // -//#include "../lv_misc/lv_debug.h" +//#include "../lv_misc/lv_assert.h" //#include "lv_imgbtn.h" //#include "lv_label.h" // @@ -58,12 +58,12 @@ // // /*Create the ancestor of image button*/ // lv_obj_t * imgbtn = lv_btn_create(par, copy); -// LV_ASSERT_MEM(imgbtn); +// LV_ASSERT_MALLOC(imgbtn); // if(imgbtn == NULL) return NULL; // // /*Allocate the image button type specific extended data*/ // lv_imgbtn_ext_t * ext = lv_obj_allocate_ext_attr(imgbtn, sizeof(lv_imgbtn_ext_t)); -// LV_ASSERT_MEM(ext); +// LV_ASSERT_MALLOC(ext); // if(ext == NULL) { // lv_obj_del(imgbtn); // return NULL; diff --git a/src/extra/widgets/led/lv_led.c b/src/extra/widgets/led/lv_led.c index 071b109d0..bec201a15 100644 --- a/src/extra/widgets/led/lv_led.c +++ b/src/extra/widgets/led/lv_led.c @@ -71,14 +71,14 @@ lv_obj_t * lv_led_create(lv_obj_t * parent) /*Create the ancestor basic object*/ lv_obj_t * led = lv_obj_create(parent, NULL); - LV_ASSERT_MEM(led); + LV_ASSERT_MALLOC(led); if(led == NULL) return NULL; if(ancestor_draw == NULL) ancestor_draw = lv_obj_get_draw_cb(led); /*Allocate the object type specific extended data*/ lv_led_ext_t * ext = lv_obj_allocate_ext_attr(led, sizeof(lv_led_ext_t)); - LV_ASSERT_MEM(ext); + LV_ASSERT_MALLOC(ext); if(ext == NULL) { lv_obj_del(led); return NULL; diff --git a/src/extra/widgets/lv_widgets.h b/src/extra/widgets/lv_widgets.h index 60fac6d37..706986c99 100644 --- a/src/extra/widgets/lv_widgets.h +++ b/src/extra/widgets/lv_widgets.h @@ -23,6 +23,7 @@ extern "C" { #include "tabview/lv_tabview.h" #include "tileview/lv_tileview.h" #include "win/lv_win.h" +#include "colorwheel/lv_colorwheel.h" /********************* diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index 0411b68bf..667122130 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -50,7 +50,7 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b lv_obj_remove_style(parent, LV_PART_ANY, LV_STATE_ANY, NULL); lv_obj_t * mbox = lv_obj_create_from_class(&lv_msgbox_class, parent, NULL); - LV_ASSERT_MEM(mbox); + LV_ASSERT_MALLOC(mbox); if(mbox == NULL) return NULL; lv_coord_t w = lv_obj_get_width_fit(parent); diff --git a/src/extra/widgets/spinbox/lv_spinbox.c b/src/extra/widgets/spinbox/lv_spinbox.c index 02ce41f55..348f5d012 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.c +++ b/src/extra/widgets/spinbox/lv_spinbox.c @@ -320,7 +320,7 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * obj, lv_signal_t sign, void * param if(new_step >= spinbox->range_max) break; spinbox->step = new_step; } - lv_spinbox_step_prev(spinbox); + lv_spinbox_step_prev(obj); } } } @@ -365,7 +365,7 @@ static lv_res_t lv_spinbox_signal(lv_obj_t * obj, lv_signal_t sign, void * param } else if(c == LV_KEY_LEFT) { if(indev_type == LV_INDEV_TYPE_ENCODER) - lv_spinbox_decrement(spinbox); + lv_spinbox_decrement(obj); else lv_spinbox_step_prev(obj); } @@ -453,7 +453,7 @@ static void lv_spinbox_updatevalue(lv_obj_t * obj) cur_pos -= cur_shift_left; - lv_textarea_set_cursor_pos(spinbox, cur_pos); + lv_textarea_set_cursor_pos(obj, cur_pos); } #endif /*LV_USE_SPINBOX*/ diff --git a/src/extra/widgets/spinner/lv_spinner.c b/src/extra/widgets/spinner/lv_spinner.c index 1329ecda4..9448f0d85 100644 --- a/src/extra/widgets/spinner/lv_spinner.c +++ b/src/extra/widgets/spinner/lv_spinner.c @@ -44,7 +44,7 @@ lv_obj_t * lv_spinner_create(lv_obj_t * par, uint32_t time, uint32_t arc_length) { /*Create the ancestor of spinner*/ lv_obj_t * spinner = lv_arc_create(par, NULL); - LV_ASSERT_MEM(spinner); + LV_ASSERT_MALLOC(spinner); if(spinner == NULL) return NULL; lv_obj_set_size(spinner, LV_DPI_DEF, LV_DPI_DEF); diff --git a/src/lv_core/lv_group.c b/src/lv_core/lv_group.c index 869c10f3b..c4113fa5a 100644 --- a/src/lv_core/lv_group.c +++ b/src/lv_core/lv_group.c @@ -54,7 +54,7 @@ void _lv_group_init(void) lv_group_t * lv_group_create(void) { lv_group_t * group = _lv_ll_ins_head(&LV_GC_ROOT(_lv_group_ll)); - LV_ASSERT_MEM(group); + LV_ASSERT_MALLOC(group); if(group == NULL) return NULL; _lv_ll_init(&group->obj_ll, sizeof(lv_obj_t *)); @@ -127,7 +127,7 @@ void lv_group_add_obj(lv_group_t * group, lv_obj_t * obj) obj->spec_attr->group_p = group; lv_obj_t ** next = _lv_ll_ins_tail(&group->obj_ll); - LV_ASSERT_MEM(next); + LV_ASSERT_MALLOC(next); if(next == NULL) return; *next = obj; diff --git a/src/lv_core/lv_obj.c b/src/lv_core/lv_obj.c index a6dddacdb..ed259d3d9 100644 --- a/src/lv_core/lv_obj.c +++ b/src/lv_core/lv_obj.c @@ -12,7 +12,7 @@ #include "lv_group.h" #include "lv_disp.h" #include "lv_theme.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_misc/lv_anim.h" #include "../lv_misc/lv_timer.h" @@ -41,7 +41,6 @@ #define STYLE_TRANSITION_MAX 32 #define SCROLLBAR_MIN_SIZE (LV_DPX(10)) - /********************** * TYPEDEFS **********************/ @@ -421,7 +420,7 @@ void lv_obj_add_event_cb(lv_obj_t * obj, lv_event_cb_t event_cb, void * user_dat obj->spec_attr->event_dsc_cnt++; obj->spec_attr->event_dsc = lv_mem_realloc(obj->spec_attr->event_dsc, obj->spec_attr->event_dsc_cnt * sizeof(lv_event_dsc_t)); - LV_ASSERT_MEM(obj->spec_attr->event_dsc); + LV_ASSERT_MALLOC(obj->spec_attr->event_dsc); obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1].cb = event_cb; obj->spec_attr->event_dsc[obj->spec_attr->event_dsc_cnt - 1].user_data = user_data; @@ -527,7 +526,7 @@ void lv_obj_allocate_spec_attr(lv_obj_t * obj) static uint32_t x = 0; x++; obj->spec_attr = lv_mem_alloc(sizeof(lv_obj_spec_attr_t)); - LV_ASSERT_MEM(obj->spec_attr); + LV_ASSERT_MALLOC(obj->spec_attr); if(obj->spec_attr == NULL) return; lv_memset_00(obj->spec_attr, sizeof(lv_obj_spec_attr_t)); @@ -550,18 +549,24 @@ lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj) return (lv_obj_t *)focus_obj; } -bool lv_obj_check_type(const lv_obj_t * obj, const void * class_p) +bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p) { if(obj == NULL) return false; return obj->class_p == class_p ? true : false; } -bool _lv_debug_check_obj_type(const lv_obj_t * obj, const char * obj_type) +bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p) { - return true; + lv_obj_class_t * obj_class = obj->class_p; + while(obj_class) { + if(obj_class == class_p) return true; + obj_class = obj_class->base_class; + } + + return false; } -bool _lv_debug_check_obj_valid(const lv_obj_t * obj) +bool lv_obj_is_valid(const lv_obj_t * obj) { lv_disp_t * disp = lv_disp_get_next(NULL); while(disp) { @@ -1135,9 +1140,11 @@ static void base_dir_refr_children(lv_obj_t * obj) static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_find) { /*Check all children of `parent`*/ + uint32_t child_cnt = 0; + if(parent->spec_attr) child_cnt = parent->spec_attr->child_cnt; uint32_t i; - for(i = 0; i < lv_obj_get_child_cnt(parent); i++) { - lv_obj_t * child = lv_obj_get_child(parent, i); + for(i = 0; i < child_cnt; i++) { + lv_obj_t * child = parent->spec_attr->children[i]; if(child == obj_to_find) return true; /*Check the children*/ diff --git a/src/lv_core/lv_obj.h b/src/lv_core/lv_obj.h index bdba8b761..a6ec8579d 100644 --- a/src/lv_core/lv_obj.h +++ b/src/lv_core/lv_obj.h @@ -21,7 +21,7 @@ extern "C" { #include "../lv_misc/lv_types.h" #include "../lv_misc/lv_area.h" #include "../lv_misc/lv_color.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_hal/lv_hal.h" /********************* @@ -484,7 +484,7 @@ lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj); * @param obj pointer to an object which type should be get * @param buf pointer to an `lv_obj_type_t` buffer to store the types */ -bool lv_obj_check_type(const lv_obj_t * obj, const void * class_p); +bool lv_obj_check_type(const lv_obj_t * obj, const lv_obj_class_t * class_p); /** * Check if any object has a given type @@ -492,7 +492,7 @@ bool lv_obj_check_type(const lv_obj_t * obj, const void * class_p); * @param obj_type type of the object. (e.g. "lv_btn") * @return true: valid */ -bool _lv_debug_check_obj_type(const lv_obj_t * obj, const char * obj_type); +bool lv_obj_has_class(const lv_obj_t * obj, const lv_obj_class_t * class_p); /** * Check if any object is still "alive", and part of the hierarchy @@ -500,34 +500,20 @@ bool _lv_debug_check_obj_type(const lv_obj_t * obj, const char * obj_type); * @param obj_type type of the object. (e.g. "lv_btn") * @return true: valid */ -bool _lv_debug_check_obj_valid(const lv_obj_t * obj); +bool lv_obj_is_valid(const lv_obj_t * obj); /********************** * MACROS **********************/ -#if LV_USE_DEBUG +#if LV_USE_ASSERT && LV_USE_ASSERT_OBJ +# define LV_ASSERT_OBJ(obj_p, obj_class) \ + LV_ASSERT_MSG(obj_p != NULL, "The object is NULL"); \ + LV_ASSERT_MSG(lv_obj_has_class(obj_p, obj_class) == true, "Incompatible object type."); \ + LV_ASSERT_MSG(lv_obj_is_valid(obj_p) == true, "The object is invalid, deleted or corrupted?"); -# ifndef LV_DEBUG_IS_OBJ -# define LV_DEBUG_IS_OBJ(obj_p, obj_type) (lv_debug_check_null(obj_p) && \ - _lv_debug_check_obj_valid(obj_p) && \ - _lv_debug_check_obj_type(obj_p, obj_type)) -# endif - - -# if LV_USE_ASSERT_OBJ -# ifndef LV_ASSERT_OBJ -# define LV_ASSERT_OBJ(obj_p, obj_type) LV_DEBUG_ASSERT(LV_DEBUG_IS_OBJ(obj_p, obj_type), "Invalid object", obj_p); -# endif -# else /* LV_USE_ASSERT_OBJ == 0 */ -# if LV_USE_ASSERT_NULL /*Use at least LV_ASSERT_NULL if enabled*/ -# define LV_ASSERT_OBJ(obj_p, obj_type) LV_ASSERT_NULL(obj_p) -# else -# define LV_ASSERT_OBJ(obj_p, obj_type) -# endif -# endif -#else -# define LV_ASSERT_OBJ(obj, obj_type) +# else +# define LV_ASSERT_OBJ(obj_p, obj_class) do{}while(0) #endif diff --git a/src/lv_core/lv_obj_pos.c b/src/lv_core/lv_obj_pos.c index 18bd84fb7..a9136efa0 100644 --- a/src/lv_core/lv_obj_pos.c +++ b/src/lv_core/lv_obj_pos.c @@ -7,6 +7,8 @@ * INCLUDES *********************/ #include "lv_obj.h" +#include "lv_disp.h" +#include "lv_refr.h" /********************* * DEFINES @@ -43,7 +45,6 @@ void lv_obj_set_pos(lv_obj_t * obj, lv_coord_t x, lv_coord_t y) LV_ASSERT_OBJ(obj, MY_CLASS); if(lv_obj_is_layout_positioned(obj)) { - LV_LOG_WARN("Can't set position because the position is set by a layout"); return; } @@ -559,6 +560,11 @@ void lv_obj_get_click_area(const lv_obj_t * obj, lv_area_t * area) bool lv_obj_hit_test(lv_obj_t * obj, const lv_point_t * point) { + lv_area_t a; + lv_obj_get_click_area(obj, &a); + bool res = _lv_area_is_point_on(&a, point, 0); + if(res == false) return false; + if(lv_obj_has_flag(obj, LV_OBJ_FLAG_ADV_HITTEST)) { lv_hit_test_info_t hit_info; hit_info.point = point; @@ -566,11 +572,8 @@ bool lv_obj_hit_test(lv_obj_t * obj, const lv_point_t * point) lv_signal_send(obj, LV_SIGNAL_HIT_TEST, &hit_info); return hit_info.result; } - else { - lv_area_t a; - lv_obj_get_click_area(obj, &a); - return _lv_area_is_point_on(&a, point, 0); - } + + return res; } diff --git a/src/lv_core/lv_obj_style.c b/src/lv_core/lv_obj_style.c index 9b010b46f..7ff8d3e34 100644 --- a/src/lv_core/lv_obj_style.c +++ b/src/lv_core/lv_obj_style.c @@ -282,7 +282,7 @@ void lv_obj_style_create_transition(lv_obj_t * obj, lv_style_prop_t prop, uint8_ } tr = _lv_ll_ins_head(&LV_GC_ROOT(_lv_obj_style_trans_ll)); - LV_ASSERT_MEM(tr); + LV_ASSERT_MALLOC(tr); if(tr == NULL) return; tr->start_value = v1; tr->end_value = v2; diff --git a/src/lv_core/lv_refr.c b/src/lv_core/lv_refr.c index 57b471cd1..4ee494d55 100644 --- a/src/lv_core/lv_refr.c +++ b/src/lv_core/lv_refr.c @@ -656,9 +656,9 @@ static void lv_refr_obj_and_children(lv_obj_t * top_p, const lv_area_t * mask_p) } /*Call the post draw draw function of the parents of the to object*/ - lv_event_send(par, LV_EVENT_DRAW_POST_BEGIN, mask_p); + lv_event_send(par, LV_EVENT_DRAW_POST_BEGIN, (void*)mask_p); call_draw_cb(par, mask_p, LV_DRAW_MODE_POST_DRAW); - lv_event_send(par, LV_EVENT_DRAW_POST_END, mask_p); + lv_event_send(par, LV_EVENT_DRAW_POST_END, (void*)mask_p); /*The new border will be the last parents, *so the 'younger' brothers of parent will be refreshed*/ diff --git a/src/lv_draw/lv_draw_label.c b/src/lv_draw/lv_draw_label.c index 67ae9975b..d70e362f1 100644 --- a/src/lv_draw/lv_draw_label.c +++ b/src/lv_draw/lv_draw_label.c @@ -11,7 +11,7 @@ #include "../lv_hal/lv_hal_disp.h" #include "../lv_core/lv_refr.h" #include "../lv_misc/lv_bidi.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" /********************* * DEFINES @@ -381,7 +381,7 @@ LV_ATTRIBUTE_FAST_MEM void lv_draw_label(const lv_area_t * coords, const lv_area if(pos.y > mask->y2) return; } - LV_ASSERT_MEM_INTEGRITY(); + LV_ASSERT_MALLOC_INTEGRITY(); } /********************** diff --git a/src/lv_draw/lv_draw_mask.c b/src/lv_draw/lv_draw_mask.c index bdf2bc99f..94a145fb8 100644 --- a/src/lv_draw/lv_draw_mask.c +++ b/src/lv_draw/lv_draw_mask.c @@ -12,7 +12,7 @@ #if LV_DRAW_COMPLEX #include "../lv_misc/lv_math.h" #include "../lv_misc/lv_log.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_misc/lv_gc.h" /********************* @@ -331,16 +331,16 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert param->dsc.cb = (lv_draw_mask_xcb_t)lv_draw_mask_angle; param->dsc.type = LV_DRAW_MASK_TYPE_ANGLE; + LV_ASSERT_MSG(start_angle < 0 && start_angle >= 360, "Unexpected start angle"); + if(start_angle >= 0 && start_angle < 180) { start_side = LV_DRAW_MASK_LINE_SIDE_LEFT; } else if(start_angle >= 180 && start_angle < 360) { start_side = LV_DRAW_MASK_LINE_SIDE_RIGHT; } - else { - LV_DEBUG_ASSERT(false, "Unexpected start_angle", start_angle); - return; - } + + LV_ASSERT_MSG(end_angle < 0 && start_angle >= 360, "Unexpected end angle"); if(end_angle >= 0 && end_angle < 180) { end_side = LV_DRAW_MASK_LINE_SIDE_RIGHT; @@ -348,10 +348,6 @@ void lv_draw_mask_angle_init(lv_draw_mask_angle_param_t * param, lv_coord_t vert else if(end_angle >= 180 && end_angle < 360) { end_side = LV_DRAW_MASK_LINE_SIDE_LEFT; } - else { - LV_DEBUG_ASSERT(false, "Unexpected end_angle", end_angle); - return; - } lv_draw_mask_line_angle_init(¶m->start_line, vertex_x, vertex_y, start_angle, start_side); lv_draw_mask_line_angle_init(¶m->end_line, vertex_x, vertex_y, end_angle, end_side); diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index c62f4f49f..a4ea15196 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -12,7 +12,7 @@ #include "../lv_misc/lv_math.h" #include "../lv_misc/lv_txt_ap.h" #include "../lv_core/lv_refr.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" /********************* * DEFINES @@ -112,7 +112,7 @@ void lv_draw_rect(const lv_area_t * coords, const lv_area_t * clip, const lv_dra draw_outline(coords, clip, dsc); - LV_ASSERT_MEM_INTEGRITY(); + LV_ASSERT_MALLOC_INTEGRITY(); } /********************** diff --git a/src/lv_draw/lv_img_cache.c b/src/lv_draw/lv_img_cache.c index 2cd012c05..1d45f0bfe 100644 --- a/src/lv_draw/lv_img_cache.c +++ b/src/lv_draw/lv_img_cache.c @@ -6,7 +6,7 @@ /********************* * INCLUDES *********************/ -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "lv_img_cache.h" #include "lv_img_decoder.h" #include "lv_draw_img.h" @@ -172,7 +172,7 @@ void lv_img_cache_set_size(uint16_t new_entry_cnt) /*Reallocate the cache*/ LV_GC_ROOT(_lv_img_cache_array) = lv_mem_alloc(sizeof(lv_img_cache_entry_t) * new_entry_cnt); - LV_ASSERT_MEM(LV_GC_ROOT(_lv_img_cache_array)); + LV_ASSERT_MALLOC(LV_GC_ROOT(_lv_img_cache_array)); if(LV_GC_ROOT(_lv_img_cache_array) == NULL) { entry_cnt = 0; return; diff --git a/src/lv_draw/lv_img_decoder.c b/src/lv_draw/lv_img_decoder.c index eb5ce3d6b..80b3a4a1c 100644 --- a/src/lv_draw/lv_img_decoder.c +++ b/src/lv_draw/lv_img_decoder.c @@ -7,7 +7,7 @@ * INCLUDES *********************/ #include "lv_img_decoder.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw_img.h" #include "../lv_misc/lv_ll.h" #include "../lv_misc/lv_color.h" @@ -63,7 +63,7 @@ void _lv_img_decoder_init(void) decoder = lv_img_decoder_create(); if(decoder == NULL) { LV_LOG_WARN("lv_img_decoder_init: out of memory"); - LV_ASSERT_MEM(decoder); + LV_ASSERT_MALLOC(decoder); return; } @@ -191,7 +191,7 @@ lv_img_decoder_t * lv_img_decoder_create(void) { lv_img_decoder_t * decoder; decoder = _lv_ll_ins_head(&LV_GC_ROOT(_lv_img_defoder_ll)); - LV_ASSERT_MEM(decoder); + LV_ASSERT_MALLOC(decoder); if(decoder == NULL) return NULL; lv_memset_00(decoder, sizeof(lv_img_decoder_t)); @@ -323,7 +323,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder /*If the file was open successfully save the file descriptor*/ if(dsc->user_data == NULL) { dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t)); - LV_ASSERT_MEM(dsc->user_data); + LV_ASSERT_MALLOC(dsc->user_data); if(dsc->user_data == NULL) { LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); return LV_RES_INV; @@ -366,7 +366,7 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder /*Allocate the palette*/ if(dsc->user_data == NULL) { dsc->user_data = lv_mem_alloc(sizeof(lv_img_decoder_built_in_data_t)); - LV_ASSERT_MEM(dsc->user_data); + LV_ASSERT_MALLOC(dsc->user_data); if(dsc->user_data == NULL) { LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); lv_img_decoder_built_in_close(decoder, dsc); @@ -377,9 +377,9 @@ lv_res_t lv_img_decoder_built_in_open(lv_img_decoder_t * decoder, lv_img_decoder lv_img_decoder_built_in_data_t * user_data = dsc->user_data; user_data->palette = lv_mem_alloc(palette_size * sizeof(lv_color_t)); - LV_ASSERT_MEM(user_data->palette); + LV_ASSERT_MALLOC(user_data->palette); user_data->opa = lv_mem_alloc(palette_size * sizeof(lv_opa_t)); - LV_ASSERT_MEM(user_data->opa); + LV_ASSERT_MALLOC(user_data->opa); if(user_data->palette == NULL || user_data->opa == NULL) { LV_LOG_ERROR("img_decoder_built_in_open: out of memory"); lv_img_decoder_built_in_close(decoder, dsc); diff --git a/src/lv_font/lv_font_fmt_txt.c b/src/lv_font/lv_font_fmt_txt.c index 4094a23e5..be721da64 100644 --- a/src/lv_font/lv_font_fmt_txt.c +++ b/src/lv_font/lv_font_fmt_txt.c @@ -8,7 +8,7 @@ *********************/ #include "lv_font.h" #include "lv_font_fmt_txt.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_misc/lv_types.h" #include "../lv_misc/lv_gc.h" @@ -115,7 +115,7 @@ const uint8_t * lv_font_get_bitmap_fmt_txt(const lv_font_t * font, uint32_t unic if(lv_mem_get_size(LV_GC_ROOT(_lv_font_decompr_buf)) < buf_size) { LV_GC_ROOT(_lv_font_decompr_buf) = lv_mem_realloc(LV_GC_ROOT(_lv_font_decompr_buf), buf_size); - LV_ASSERT_MEM(LV_GC_ROOT(_lv_font_decompr_buf)); + LV_ASSERT_MALLOC(LV_GC_ROOT(_lv_font_decompr_buf)); if(LV_GC_ROOT(_lv_font_decompr_buf) == NULL) return NULL; } diff --git a/src/lv_hal/lv_hal_disp.c b/src/lv_hal/lv_hal_disp.c index 3655e12b4..c535fc4fb 100644 --- a/src/lv_hal/lv_hal_disp.c +++ b/src/lv_hal/lv_hal_disp.c @@ -14,7 +14,7 @@ #include "lv_hal.h" #include "../lv_misc/lv_mem.h" #include "../lv_misc/lv_gc.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_obj.h" #include "../lv_core/lv_refr.h" @@ -112,7 +112,7 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) { lv_disp_t * disp = _lv_ll_ins_head(&LV_GC_ROOT(_lv_disp_ll)); if(!disp) { - LV_ASSERT_MEM(disp); + LV_ASSERT_MALLOC(disp); return NULL; } @@ -128,7 +128,7 @@ lv_disp_t * lv_disp_drv_register(lv_disp_drv_t * driver) new display*/ /*Create a refresh task*/ disp->read_task = lv_timer_create(_lv_disp_refr_task, LV_DISP_DEF_REFR_PERIOD, disp); - LV_ASSERT_MEM(disp->read_task); + LV_ASSERT_MALLOC(disp->read_task); if(disp->read_task == NULL) return NULL; disp->inv_p = 0; diff --git a/src/lv_hal/lv_hal_indev.c b/src/lv_hal/lv_hal_indev.c index 590840e74..176adcabc 100644 --- a/src/lv_hal/lv_hal_indev.c +++ b/src/lv_hal/lv_hal_indev.c @@ -8,7 +8,7 @@ /********************* * INCLUDES *********************/ -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_hal/lv_hal_indev.h" #include "../lv_core/lv_indev.h" #include "../lv_misc/lv_mem.h" @@ -81,7 +81,7 @@ lv_indev_t * lv_indev_drv_register(lv_indev_drv_t * driver) lv_indev_t * indev = _lv_ll_ins_head(&LV_GC_ROOT(_lv_indev_ll)); if(!indev) { - LV_ASSERT_MEM(indev); + LV_ASSERT_MALLOC(indev); return NULL; } diff --git a/src/lv_misc/lv_anim.c b/src/lv_misc/lv_anim.c index c3243600b..cb1f294da 100644 --- a/src/lv_misc/lv_anim.c +++ b/src/lv_misc/lv_anim.c @@ -10,7 +10,7 @@ #include #include -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_hal/lv_hal_tick.h" #include "lv_timer.h" #include "lv_math.h" @@ -96,7 +96,7 @@ void lv_anim_start(lv_anim_t * a) /*Add the new animation to the animation linked list*/ lv_anim_t * new_anim = _lv_ll_ins_head(&LV_GC_ROOT(_lv_anim_ll)); - LV_ASSERT_MEM(new_anim); + LV_ASSERT_MALLOC(new_anim); if(new_anim == NULL) return; /*Initialize the animation descriptor*/ diff --git a/src/lv_misc/lv_debug.c b/src/lv_misc/lv_assert.c similarity index 96% rename from src/lv_misc/lv_debug.c rename to src/lv_misc/lv_assert.c index 5fcdc7243..c7e5af66f 100644 --- a/src/lv_misc/lv_debug.c +++ b/src/lv_misc/lv_assert.c @@ -1,14 +1,14 @@ /** - * @file lv_debug.c + * @file lv_assert.c * */ /********************* * INCLUDES *********************/ -#include "lv_debug.h" +#include "lv_assert.h" -#if LV_USE_DEBUG +#if LV_USE_ASSERT #include "lv_mem.h" #include @@ -135,4 +135,4 @@ void lv_debug_log_error(const char * msg, uint64_t value) * STATIC FUNCTIONS **********************/ -#endif /*LV_USE_DEBUG*/ +#endif /*LV_USE_ASSERT*/ diff --git a/src/lv_misc/lv_assert.h b/src/lv_misc/lv_assert.h new file mode 100644 index 000000000..bc9a160cd --- /dev/null +++ b/src/lv_misc/lv_assert.h @@ -0,0 +1,100 @@ +/** + * @file lv_assert.h + * + */ + +#ifndef LV_ASSERT_H +#define LV_ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +/********************* + * INCLUDES + *********************/ +#include "../lv_conf_internal.h" + +#if LV_USE_ASSERT +#include + +/********************* + * DEFINES + *********************/ + +/********************** + * TYPEDEFS + **********************/ + +/********************** + * GLOBAL PROTOTYPES + **********************/ +bool lv_debug_check_null(const void * p); + +bool lv_debug_check_mem_integrity(void); + +bool lv_debug_check_str(const void * str); + +void lv_debug_log_error(const char * msg, uint64_t value); + +/********************** + * MACROS + **********************/ + +#define LV_ASSERT(expr) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s", #expr); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + + +#define LV_ASSERT_MSG(expr, msg) \ + do { \ + if(!(expr)) { \ + LV_LOG_ERROR("Asserted at expression: %s (%s)", #expr, msg); \ + LV_ASSERT_HANDLER \ + } \ + } while(0) + + + +/*----------------- + * ASSERTS + *-----------------*/ + +#if LV_USE_ASSERT_NULL +# define LV_ASSERT_NULL(p) LV_ASSERT_MSG(p != NULL, "NULL pointer"); +#else +# define LV_ASSERT_NULL(p) +#endif + +#if LV_USE_ASSERT_MALLOC +# define LV_ASSERT_MALLOC(p) LV_ASSERT_MSG(p != NULL, "Out of memory"); +#else +# define LV_ASSERT_MALLOC(p) +#endif + +#if LV_USE_ASSERT_MEM_INTEGRITY +# define LV_ASSERT_MALLOC_INTEGRITY() LV_ASSERT_MSG(lv_mem_test() == LV_RES_OK, "Memory integrity error"); +#else +# define LV_ASSERT_MALLOC_INTEGRIT() +#endif + +#else /* LV_USE_ASSERT == 0 */ + +#define LV_ASSERT(expr) do{}while(0) +#define LV_ASSERT_MSG(expr, msg) do{}while(0) + +#define LV_ASSERT_NULL(p) +#define LV_ASSERT_MALLOC(p) +#define LV_ASSERT_MALLOC_INTEGRITY() + +#endif /* LV_USE_ASSERT */ + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +#endif /*LV_ASSERT_H*/ diff --git a/src/lv_misc/lv_debug.h b/src/lv_misc/lv_debug.h deleted file mode 100644 index 82c92fe09..000000000 --- a/src/lv_misc/lv_debug.h +++ /dev/null @@ -1,131 +0,0 @@ -/** - * @file lv_debug.h - * - */ - -#ifndef LV_DEBUG_H -#define LV_DEBUG_H - -#ifdef __cplusplus -extern "C" { -#endif - -/********************* - * INCLUDES - *********************/ -#include "../lv_conf_internal.h" - -#if LV_USE_DEBUG -#include - -/********************* - * DEFINES - *********************/ - -/********************** - * TYPEDEFS - **********************/ - -/********************** - * GLOBAL PROTOTYPES - **********************/ -bool lv_debug_check_null(const void * p); - -bool lv_debug_check_mem_integrity(void); - -bool lv_debug_check_str(const void * str); - -void lv_debug_log_error(const char * msg, uint64_t value); - -/********************** - * MACROS - **********************/ - -#ifndef LV_DEBUG_ASSERT -#define LV_DEBUG_ASSERT(expr, msg, value) \ - do { \ - if(!(expr)) { \ - LV_LOG_ERROR(__func__); \ - lv_debug_log_error(msg, (uint64_t)((uintptr_t)value)); \ - while(1); \ - } \ - } while(0) -#endif - -/*---------------- - * CHECKS - *----------------*/ - -#ifndef LV_DEBUG_IS_NULL -#define LV_DEBUG_IS_NULL(p) (lv_debug_check_null(p)) -#endif - -#ifndef LV_DEBUG_CHECK_MEM_INTEGRITY -#define LV_DEBUG_CHECK_MEM_INTEGRITY() (lv_debug_check_mem_integrity()) -#endif - -#ifndef LV_DEBUG_IS_STR -#define LV_DEBUG_IS_STR(str) (lv_debug_check_null(str) && \ - lv_debug_check_str(str)) -#endif - -/*----------------- - * ASSERTS - *-----------------*/ - -/*clang-format off*/ - -#if LV_USE_ASSERT_NULL -# ifndef LV_ASSERT_NULL -# define LV_ASSERT_NULL(p) LV_DEBUG_ASSERT(LV_DEBUG_IS_NULL(p), "NULL pointer", p); -# endif -#else -# define LV_ASSERT_NULL(p) -#endif - -#if LV_USE_ASSERT_MEM -# ifndef LV_ASSERT_MEM -# define LV_ASSERT_MEM(p) LV_DEBUG_ASSERT(LV_DEBUG_IS_NULL(p), "Out of memory", p); -# endif -#else -# define LV_ASSERT_MEM(p) -#endif - -#if LV_USE_ASSERT_MEM_INTEGRITY -# ifndef LV_ASSERT_MEM_INTEGRITY -# define LV_ASSERT_MEM_INTEGRITY() LV_DEBUG_ASSERT(LV_DEBUG_CHECK_MEM_INTEGRITY(), "Memory integrity error", 0); -# endif -#else -# define LV_ASSERT_MEM_INTEGRITY() -#endif - -#if LV_USE_ASSERT_STR -# ifndef LV_ASSERT_STR -# define LV_ASSERT_STR(str) LV_DEBUG_ASSERT(LV_DEBUG_IS_STR(str), "Strange or invalid string", str); -# endif -#else /* LV_USE_ASSERT_OBJ == 0 */ -# if LV_USE_ASSERT_NULL /*Use at least LV_ASSERT_NULL if enabled*/ -# define LV_ASSERT_STR(str) LV_ASSERT_NULL(str) -# else -# define LV_ASSERT_STR(str) -# endif -#endif - -#else /* LV_USE_DEBUG == 0 */ - -#define LV_DEBUG_ASSERT(expr, msg, value) do{}while(0) - -#define LV_ASSERT_NULL(p) -#define LV_ASSERT_MEM(p) -#define LV_ASSERT_MEM_INTEGRITY() -#define LV_ASSERT_STR(p) -#define LV_ASSERT_OBJ(obj, obj_type) - -#endif /* LV_USE_DEBUG */ -/*clang-format on*/ - -#ifdef __cplusplus -} /* extern "C" */ -#endif - -#endif /*LV_DEBUG_H*/ diff --git a/src/lv_misc/lv_fs.c b/src/lv_misc/lv_fs.c index 8f7e01a77..e0d6d7ee9 100644 --- a/src/lv_misc/lv_fs.c +++ b/src/lv_misc/lv_fs.c @@ -8,7 +8,7 @@ *********************/ #include "lv_fs.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "lv_ll.h" #include #include "lv_gc.h" @@ -225,7 +225,7 @@ lv_fs_res_t lv_fs_dir_open(lv_fs_dir_t * rddir_p, const char * path) } rddir_p->dir_d = lv_mem_alloc(rddir_p->drv->rddir_size); - LV_ASSERT_MEM(rddir_p->dir_d); + LV_ASSERT_MALLOC(rddir_p->dir_d); if(rddir_p->dir_d == NULL) { rddir_p->drv = NULL; return LV_FS_RES_OUT_OF_MEM; /* Out of memory */ @@ -288,7 +288,7 @@ void lv_fs_drv_register(lv_fs_drv_t * drv_p) /*Save the new driver*/ lv_fs_drv_t * new_drv; new_drv = _lv_ll_ins_head(&LV_GC_ROOT(_lv_drv_ll)); - LV_ASSERT_MEM(new_drv); + LV_ASSERT_MALLOC(new_drv); if(new_drv == NULL) return; lv_memcpy(new_drv, drv_p, sizeof(lv_fs_drv_t)); diff --git a/src/lv_misc/lv_mem.c b/src/lv_misc/lv_mem.c index 1ae83b6f3..d83e01010 100644 --- a/src/lv_misc/lv_mem.c +++ b/src/lv_misc/lv_mem.c @@ -10,7 +10,7 @@ #include "lv_mem.h" #include "lv_math.h" #include "lv_gc.h" -#include "lv_debug.h" +#include "lv_assert.h" #include #if LV_MEM_CUSTOM != 0 @@ -484,10 +484,7 @@ void * lv_mem_buf_get(uint32_t size) if(LV_GC_ROOT(lv_mem_buf[i]).used == 0) { /*if this fails you probably need to increase your LV_MEM_SIZE/heap size*/ void * buf = lv_mem_realloc(LV_GC_ROOT(lv_mem_buf[i]).p, size); - if(buf == NULL) { - LV_DEBUG_ASSERT(false, "Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size)", 0x00); - return NULL; - } + LV_ASSERT_MSG(buf != NULL, "Out of memory, can't allocate a new buffer (increase your LV_MEM_SIZE/heap size)"); LV_GC_ROOT(lv_mem_buf[i]).used = 1; LV_GC_ROOT(lv_mem_buf[i]).size = size; LV_GC_ROOT(lv_mem_buf[i]).p = buf; @@ -495,7 +492,7 @@ void * lv_mem_buf_get(uint32_t size) } } - LV_DEBUG_ASSERT(false, "No free buffer. Increase LV_MEM_BUF_MAX_NUM.", 0x00); + LV_ASSERT_MSG(false, "No free buffer. Increase LV_MEM_BUF_MAX_NUM."); return NULL; } diff --git a/src/lv_misc/lv_style.c b/src/lv_misc/lv_style.c index e5019af01..7da8e5cb8 100644 --- a/src/lv_misc/lv_style.c +++ b/src/lv_misc/lv_style.c @@ -41,14 +41,14 @@ void lv_style_init(lv_style_t * style) { #if LV_USE_ASSERT_STYLE - if(style->sentinel == LV_DEBUG_STYLE_SENTINEL_VALUE && style->allocated && style->values_and_props != NULL) { + if(style->sentinel == LV_STYLE_SENTINEL_VALUE && style->allocated && style->values_and_props != NULL) { LV_LOG_WARN("Style might be already inited. (Potential memory leak)") } #endif lv_memset_00(style, sizeof(lv_style_t)); #if LV_USE_ASSERT_STYLE - style->sentinel = LV_DEBUG_STYLE_SENTINEL_VALUE; + style->sentinel = LV_STYLE_SENTINEL_VALUE; #endif } @@ -70,7 +70,6 @@ lv_style_prop_t lv_style_register_prop(void) bool lv_style_remove_prop(lv_style_t * style, lv_style_prop_t prop) { - if(style == NULL) return false; LV_ASSERT_STYLE(style); if(!style->allocated) { @@ -131,6 +130,8 @@ uint8_t lv_style_get_prop_group(lv_style_prop_t prop) void lv_style_set_prop(lv_style_t * style, lv_style_prop_t prop, lv_style_value_t value) { + LV_ASSERT_STYLE(style); + uint8_t group = lv_style_get_prop_group(prop); style->has_group |= 1 << group; @@ -257,6 +258,7 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop) value.ptr = LV_THEME_FONT_NORMAL; break; case LV_STYLE_SIZE: + case LV_STYLE_ARC_WIDTH: value.num = 10; break; default: @@ -275,20 +277,6 @@ bool lv_style_is_empty(const lv_style_t * style) return style->prop_cnt == 0 ? true : false; } -bool lv_debug_check_style(const lv_style_t * style) -{ - if(style == NULL) return true; /*NULL style is still valid*/ - -#if LV_USE_ASSERT_STYLE - if(style->sentinel != LV_DEBUG_STYLE_SENTINEL_VALUE) { - LV_LOG_WARN("Invalid style (was local variable or not initialized?)"); - return false; - } -#endif - - return true; -} - /********************** * STATIC FUNCTIONS **********************/ diff --git a/src/lv_misc/lv_style.h b/src/lv_misc/lv_style.h index b8d4cddd3..84fa0b228 100644 --- a/src/lv_misc/lv_style.h +++ b/src/lv_misc/lv_style.h @@ -20,13 +20,13 @@ extern "C" { #include "lv_anim.h" #include "lv_txt.h" #include "lv_types.h" -#include "lv_debug.h" +#include "lv_assert.h" /********************* * DEFINES *********************/ -#define LV_DEBUG_STYLE_SENTINEL_VALUE 0xAABBCCDD +#define LV_STYLE_SENTINEL_VALUE 0xAABBCCDD /** * Flags for style properties @@ -362,13 +362,6 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop); */ bool lv_style_is_empty(const lv_style_t * style); -/** - * Check whether a style is valid (initialized correctly) - * @param style pointer to a style - * @return true: valid - */ -bool lv_debug_check_style(const lv_style_t * style); - static inline void lv_style_set_radius(lv_style_t * style, lv_coord_t value) { lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_RADIUS, v); } @@ -664,42 +657,11 @@ static inline void lv_style_set_pad_all(lv_style_t * style, lv_coord_t value) * MACROS **********************/ -/** - * Create and initialize a `static` style - * Example: - * LV_STYLE_CREATE(my_style, &style_to_copy); - * is equivalent to - * static lv_style_t my_style; - * lv_style_init(&my_style); - * lv_style_copy(&my_style, &style_to_copy); - */ -#define LV_STYLE_CREATE(name, copy_p) static lv_style_t name; lv_style_init(&name); lv_style_copy(&name, copy_p); - -#if LV_USE_DEBUG - -# ifndef LV_DEBUG_IS_STYLE -# define LV_DEBUG_IS_STYLE(style_p) (lv_debug_check_style(style_p)) -# endif - -# ifndef LV_DEBUG_IS_STYLE_LIST -# define LV_DEBUG_IS_STYLE_LIST(list_p) (lv_debug_check_style_list(list_p)) -# endif - -# if LV_USE_ASSERT_STYLE -# ifndef LV_ASSERT_STYLE -# define LV_ASSERT_STYLE(style_p) LV_DEBUG_ASSERT(LV_DEBUG_IS_STYLE(style_p), "Invalid style", style_p); -# endif -# ifndef LV_ASSERT_STYLE_LIST -# define LV_ASSERT_STYLE_LIST(list_p) LV_DEBUG_ASSERT(LV_DEBUG_IS_STYLE_LIST(list_p), "Invalid style list", list_p); -# endif -# else -# define LV_ASSERT_STYLE(style_p) -# define LV_ASSERT_STYLE_LIST(list_p) -# endif - +#if LV_USE_ASSERT && LV_USE_ASSERT_STYLE +# define LV_ASSERT_STYLE(style_p) LV_ASSERT_MSG(style_p != NULL, "The style is NULL"); \ + LV_ASSERT_MSG(style_p->sentinel == LV_STYLE_SENTINEL_VALUE, "Style is not initialized or corrupted"); #else # define LV_ASSERT_STYLE(p) -# define LV_ASSERT_STYLE_LIST(p) #endif #ifdef __cplusplus diff --git a/src/lv_misc/lv_timer.c b/src/lv_misc/lv_timer.c index 8eca3be99..508c3dda8 100644 --- a/src/lv_misc/lv_timer.c +++ b/src/lv_misc/lv_timer.c @@ -7,7 +7,7 @@ *********************/ #include "lv_timer.h" #include -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_hal/lv_hal_tick.h" #include "lv_gc.h" @@ -151,7 +151,7 @@ lv_timer_t * lv_timer_create_basic(void) lv_timer_t * new_timer = NULL; new_timer = _lv_ll_ins_head(&LV_GC_ROOT(_lv_timer_ll)); - LV_ASSERT_MEM(new_timer); + LV_ASSERT_MALLOC(new_timer); if(new_timer == NULL) return NULL; new_timer->period = DEF_PERIOD; @@ -178,7 +178,7 @@ lv_timer_t * lv_timer_create_basic(void) lv_timer_t * lv_timer_create(lv_timer_cb_t timer_xcb, uint32_t period, void * user_data) { lv_timer_t * new_timer = lv_timer_create_basic(); - LV_ASSERT_MEM(new_timer); + LV_ASSERT_MALLOC(new_timer); if(new_timer == NULL) return NULL; lv_timer_set_cb(new_timer, timer_xcb); @@ -307,7 +307,7 @@ static bool lv_timer_exec(lv_timer_t * timer) timer_deleted = false; timer_created = false; if(timer->timer_cb) timer->timer_cb(timer); - LV_ASSERT_MEM_INTEGRITY(); + LV_ASSERT_MALLOC_INTEGRITY(); /*Delete if it was a one shot lv_timer*/ if(timer_deleted == false) { /*The timer might be deleted by itself as well*/ diff --git a/src/lv_misc/lv_txt.c b/src/lv_misc/lv_txt.c index 44a8bd70c..576203d37 100644 --- a/src/lv_misc/lv_txt.c +++ b/src/lv_misc/lv_txt.c @@ -12,7 +12,7 @@ #include "lv_math.h" #include "lv_log.h" #include "lv_mem.h" -#include "lv_debug.h" +#include "lv_assert.h" /********************* * DEFINES @@ -493,7 +493,7 @@ char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) #if LV_USE_ARABIC_PERSIAN_CHARS /*Put together the text according to the format string*/ char * raw_txt = lv_mem_buf_get(len + 1); - LV_ASSERT_MEM(raw_txt); + LV_ASSERT_MALLOC(raw_txt); if(raw_txt == NULL) { return NULL; } @@ -503,7 +503,7 @@ char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) /*Get the size of the Arabic text and process it*/ size_t len_ap = _lv_txt_ap_calc_bytes_cnt(raw_txt); text = lv_mem_alloc(len_ap + 1); - LV_ASSERT_MEM(text); + LV_ASSERT_MALLOC(text); if(text == NULL) { return NULL; } @@ -512,7 +512,7 @@ char * _lv_txt_set_text_vfmt(const char * fmt, va_list ap) lv_mem_buf_release(raw_txt); #else text = lv_mem_alloc(len + 1); - LV_ASSERT_MEM(text); + LV_ASSERT_MALLOC(text); if(text == NULL) { return NULL; } diff --git a/src/lv_widgets/lv_arc.c b/src/lv_widgets/lv_arc.c index 37f01c56f..a345041e6 100644 --- a/src/lv_widgets/lv_arc.c +++ b/src/lv_widgets/lv_arc.c @@ -11,7 +11,7 @@ #include "../lv_core/lv_group.h" #include "../lv_core/lv_indev.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_misc/lv_math.h" #include "../lv_draw/lv_draw_arc.h" diff --git a/src/lv_widgets/lv_bar.c b/src/lv_widgets/lv_bar.c index 8a7c10064..ef00c9ea4 100644 --- a/src/lv_widgets/lv_bar.c +++ b/src/lv_widgets/lv_bar.c @@ -9,7 +9,7 @@ #include "lv_bar.h" #if LV_USE_BAR != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_misc/lv_anim.h" #include "../lv_misc/lv_math.h" diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index 5286600a0..bc430528e 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -9,7 +9,7 @@ #include "lv_btnmatrix.h" #if LV_USE_BTNMATRIX != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_indev.h" #include "../lv_core/lv_group.h" #include "../lv_draw/lv_draw.h" @@ -857,9 +857,9 @@ static void allocate_btn_areas_and_controls(const lv_obj_t * obj, const char ** } btnm->button_areas = lv_mem_alloc(sizeof(lv_area_t) * btn_cnt); - LV_ASSERT_MEM(btnm->button_areas); + LV_ASSERT_MALLOC(btnm->button_areas); btnm->ctrl_bits = lv_mem_alloc(sizeof(lv_btnmatrix_ctrl_t) * btn_cnt); - LV_ASSERT_MEM(btnm->ctrl_bits); + LV_ASSERT_MALLOC(btnm->ctrl_bits); if(btnm->button_areas == NULL || btnm->ctrl_bits == NULL) btn_cnt = 0; lv_memset_00(btnm->ctrl_bits, sizeof(lv_btnmatrix_ctrl_t) * btn_cnt); diff --git a/src/lv_widgets/lv_canvas.c b/src/lv_widgets/lv_canvas.c index 490f13e9e..0d465c64f 100644 --- a/src/lv_widgets/lv_canvas.c +++ b/src/lv_widgets/lv_canvas.c @@ -8,7 +8,7 @@ *********************/ #include #include "lv_canvas.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_misc/lv_math.h" #include "../lv_draw/lv_draw.h" #include "../lv_core/lv_refr.h" diff --git a/src/lv_widgets/lv_chart.c b/src/lv_widgets/lv_chart.c index 1c74a1075..355496533 100644 --- a/src/lv_widgets/lv_chart.c +++ b/src/lv_widgets/lv_chart.c @@ -9,7 +9,7 @@ #include "lv_chart.h" #if LV_USE_CHART != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_refr.h" #include "../lv_draw/lv_draw.h" #include "../lv_core/lv_disp.h" @@ -103,7 +103,7 @@ void lv_chart_set_point_count(lv_obj_t * obj, uint16_t cnt) if(!ser->ext_buf_assigned) { if(ser->last_point != 0) { lv_coord_t * new_points = lv_mem_alloc(sizeof(lv_coord_t) * cnt); - LV_ASSERT_MEM(new_points); + LV_ASSERT_MALLOC(new_points); if(new_points == NULL) return; if(cnt >= point_cnt_old) { @@ -128,7 +128,7 @@ void lv_chart_set_point_count(lv_obj_t * obj, uint16_t cnt) } else { ser->points = lv_mem_realloc(ser->points, sizeof(lv_coord_t) * cnt); - LV_ASSERT_MEM(ser->points); + LV_ASSERT_MALLOC(ser->points); if(ser->points == NULL) return; /*Initialize the new points*/ if(cnt > point_cnt_old) { @@ -333,14 +333,14 @@ lv_chart_series_t * lv_chart_add_series(lv_obj_t * obj, lv_color_t color, lv_cha lv_chart_t * chart = (lv_chart_t *)obj; lv_chart_series_t * ser = _lv_ll_ins_head(&chart->series_ll); - LV_ASSERT_MEM(ser); + LV_ASSERT_MALLOC(ser); if(ser == NULL) return NULL; lv_coord_t def = LV_CHART_POINT_DEF; ser->color = color; ser->points = lv_mem_alloc(sizeof(lv_coord_t) * chart->point_cnt); - LV_ASSERT_MEM(ser->points); + LV_ASSERT_MALLOC(ser->points); if(ser->points == NULL) { _lv_ll_remove(&chart->series_ll, ser); lv_mem_free(ser); diff --git a/src/lv_widgets/lv_checkbox.c b/src/lv_widgets/lv_checkbox.c index 2a0fc026b..69a68d296 100644 --- a/src/lv_widgets/lv_checkbox.c +++ b/src/lv_widgets/lv_checkbox.c @@ -9,7 +9,7 @@ #include "lv_checkbox.h" #if LV_USE_CHECKBOX != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_group.h" #include "../lv_draw/lv_draw.h" diff --git a/src/lv_widgets/lv_dropdown.c b/src/lv_widgets/lv_dropdown.c index 488ccc9fe..ede6b1c1f 100644 --- a/src/lv_widgets/lv_dropdown.c +++ b/src/lv_widgets/lv_dropdown.c @@ -9,7 +9,7 @@ #include "lv_dropdown.h" #if LV_USE_DROPDOWN != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_core/lv_group.h" #include "../lv_core/lv_indev.h" @@ -105,7 +105,7 @@ void lv_dropdown_set_text(lv_obj_t * obj, const char * txt) void lv_dropdown_set_options(lv_obj_t * obj, const char * options) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(options); + LV_ASSERT_NULL(options); lv_dropdown_t * dropdown = (lv_dropdown_t *) obj; @@ -133,7 +133,7 @@ void lv_dropdown_set_options(lv_obj_t * obj, const char * options) dropdown->options = lv_mem_alloc(len); - LV_ASSERT_MEM(dropdown->options); + LV_ASSERT_MALLOC(dropdown->options); if(dropdown->options == NULL) return; #if LV_USE_ARABIC_PERSIAN_CHARS == 0 @@ -149,7 +149,7 @@ void lv_dropdown_set_options(lv_obj_t * obj, const char * options) void lv_dropdown_set_options_static(lv_obj_t * obj, const char * options) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(options); + LV_ASSERT_NULL(options); lv_dropdown_t * dropdown = (lv_dropdown_t *) obj; @@ -175,7 +175,7 @@ void lv_dropdown_set_options_static(lv_obj_t * obj, const char * options) void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(option); + LV_ASSERT_NULL(option); lv_dropdown_t * dropdown = (lv_dropdown_t *) obj; @@ -185,7 +185,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos) size_t len = strlen(static_options) + 1; dropdown->options = lv_mem_alloc(len); - LV_ASSERT_MEM(dropdown->options); + LV_ASSERT_MALLOC(dropdown->options); if(dropdown->options == NULL) return; strcpy(dropdown->options, static_options); @@ -202,7 +202,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos) size_t new_len = ins_len + old_len + 2; /* +2 for terminating NULL and possible \n */ dropdown->options = lv_mem_realloc(dropdown->options, new_len + 1); - LV_ASSERT_MEM(dropdown->options); + LV_ASSERT_MALLOC(dropdown->options); if(dropdown->options == NULL) return; dropdown->options[old_len] = '\0'; @@ -225,7 +225,7 @@ void lv_dropdown_add_option(lv_obj_t * obj, const char * option, uint32_t pos) /*Insert the new option, adding \n if necessary*/ char * ins_buf = lv_mem_buf_get(ins_len + 2); /* + 2 for terminating NULL and possible \n */ - LV_ASSERT_MEM(ins_buf); + LV_ASSERT_MALLOC(ins_buf); if(ins_buf == NULL) return; #if LV_USE_ARABIC_PERSIAN_CHARS == 0 strcpy(ins_buf, option); diff --git a/src/lv_widgets/lv_img.c b/src/lv_widgets/lv_img.c index 12a6eef80..2ac010419 100644 --- a/src/lv_widgets/lv_img.c +++ b/src/lv_widgets/lv_img.c @@ -9,7 +9,7 @@ #include "lv_img.h" #if LV_USE_IMG != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_img_decoder.h" #include "../lv_misc/lv_fs.h" #include "../lv_misc/lv_txt.h" @@ -122,7 +122,7 @@ void lv_img_set_src(lv_obj_t * obj, const void * src) old_src = img->src; } char * new_str = lv_mem_alloc(strlen(src) + 1); - LV_ASSERT_MEM(new_str); + LV_ASSERT_MALLOC(new_str); if(new_str == NULL) return; strcpy(new_str, src); img->src = new_str; diff --git a/src/lv_widgets/lv_label.c b/src/lv_widgets/lv_label.c index 1b6a85fe3..779966d5c 100644 --- a/src/lv_widgets/lv_label.c +++ b/src/lv_widgets/lv_label.c @@ -9,7 +9,7 @@ #include "lv_label.h" #if LV_USE_LABEL != 0 #include "../lv_core/lv_obj.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_group.h" #include "../lv_draw/lv_draw.h" #include "../lv_misc/lv_color.h" @@ -89,8 +89,6 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) /*If text is NULL then just refresh with the current text */ if(text == NULL) text = label->text; - LV_ASSERT_STR(text); - if(label->text == text && label->static_txt == 0) { /*If set its own text then reallocate it (maybe its size changed)*/ #if LV_USE_ARABIC_PERSIAN_CHARS @@ -98,7 +96,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) size_t len = _lv_txt_ap_calc_bytes_cnt(text); label->text = lv_mem_realloc(label->text, len); - LV_ASSERT_MEM(label->text); + LV_ASSERT_MALLOC(label->text); if(label->text == NULL) return; _lv_txt_ap_proc(label->text, label->text); @@ -106,7 +104,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) label->text = lv_mem_realloc(label->text, strlen(label->text) + 1); #endif - LV_ASSERT_MEM(label->text); + LV_ASSERT_MALLOC(label->text); if(label->text == NULL) return; } else { @@ -121,7 +119,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) size_t len = _lv_txt_ap_calc_bytes_cnt(text); label->text = lv_mem_alloc(len); - LV_ASSERT_MEM(label->text); + LV_ASSERT_MALLOC(label->text); if(label->text == NULL) return; _lv_txt_ap_proc(text, label->text); @@ -131,7 +129,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) /*Allocate space for the new text*/ label->text = lv_mem_alloc(len); - LV_ASSERT_MEM(label->text); + LV_ASSERT_MALLOC(label->text); if(label->text == NULL) return; strcpy(label->text, text); #endif @@ -146,7 +144,7 @@ void lv_label_set_text(lv_obj_t * obj, const char * text) void lv_label_set_text_fmt(lv_obj_t * obj, const char * fmt, ...) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(fmt); + LV_ASSERT_NULL(fmt); lv_obj_invalidate(obj); lv_label_t * label = (lv_label_t *)obj; @@ -638,7 +636,7 @@ uint32_t lv_label_get_text_sel_end(const lv_obj_t * obj) void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(txt); + LV_ASSERT_NULL(txt); lv_label_t * label = (lv_label_t *)obj; @@ -652,7 +650,7 @@ void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt) size_t ins_len = strlen(txt); size_t new_len = ins_len + old_len; label->text = lv_mem_realloc(label->text, new_len + 1); - LV_ASSERT_MEM(label->text); + LV_ASSERT_MALLOC(label->text); if(label->text == NULL) return; if(pos == LV_LABEL_POS_LAST) { @@ -661,7 +659,7 @@ void lv_label_ins_text(lv_obj_t * obj, uint32_t pos, const char * txt) #if LV_USE_BIDI char * bidi_buf = lv_mem_buf_get(ins_len + 1); - LV_ASSERT_MEM(bidi_buf); + LV_ASSERT_MALLOC(bidi_buf); if(bidi_buf == NULL) return; _lv_bidi_process(txt, bidi_buf, lv_obj_get_base_dir(obj)); diff --git a/src/lv_widgets/lv_line.c b/src/lv_widgets/lv_line.c index ff8b7851b..2b2ac7ff4 100644 --- a/src/lv_widgets/lv_line.c +++ b/src/lv_widgets/lv_line.c @@ -9,7 +9,7 @@ #include "lv_line.h" #if LV_USE_LINE != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_misc/lv_math.h" #include diff --git a/src/lv_widgets/lv_meter.c b/src/lv_widgets/lv_meter.c index ec5dea4de..3873807c8 100644 --- a/src/lv_widgets/lv_meter.c +++ b/src/lv_widgets/lv_meter.c @@ -9,7 +9,7 @@ #include #if LV_USE_METER != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_core/lv_group.h" #include "../lv_misc/lv_math.h" @@ -67,7 +67,7 @@ lv_meter_scale_t * lv_meter_add_scale(lv_obj_t * obj) lv_meter_t * meter = (lv_meter_t *)obj; lv_meter_scale_t * scale = _lv_ll_ins_head(&meter->scale_ll); - LV_ASSERT_MEM(scale); + LV_ASSERT_MALLOC(scale); lv_memset_00(scale, sizeof(lv_meter_scale_t)); _lv_ll_init(&scale->indicator_ll, sizeof(lv_meter_indicator_t)); @@ -118,7 +118,7 @@ void lv_meter_set_scale_range(lv_obj_t * obj, lv_meter_scale_t * scale, int32_t lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, int16_t r_mod) { lv_meter_indicator_t * indic = _lv_ll_ins_head(&scale->indicator_ll); - LV_ASSERT_MEM(indic); + LV_ASSERT_MALLOC(indic); lv_memset_00(indic, sizeof(lv_meter_indicator_t)); indic->opa = LV_OPA_COVER; @@ -134,7 +134,7 @@ lv_meter_indicator_t * lv_meter_add_needle_line(lv_obj_t * obj, lv_meter_scale_t lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t * scale, const void * src, lv_coord_t pivot_x, lv_coord_t pivot_y) { lv_meter_indicator_t * indic = _lv_ll_ins_head(&scale->indicator_ll); - LV_ASSERT_MEM(indic); + LV_ASSERT_MALLOC(indic); lv_memset_00(indic, sizeof(lv_meter_indicator_t)); indic->opa = LV_OPA_COVER; @@ -150,7 +150,7 @@ lv_meter_indicator_t * lv_meter_add_needle_img(lv_obj_t * obj, lv_meter_scale_t lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale, uint16_t width, lv_color_t color, int16_t r_mod) { lv_meter_indicator_t * indic = _lv_ll_ins_head(&scale->indicator_ll); - LV_ASSERT_MEM(indic); + LV_ASSERT_MALLOC(indic); lv_memset_00(indic, sizeof(lv_meter_indicator_t)); indic->opa = LV_OPA_COVER; @@ -166,7 +166,7 @@ lv_meter_indicator_t * lv_meter_add_arc(lv_obj_t * obj, lv_meter_scale_t * scale lv_meter_indicator_t * lv_meter_add_scale_lines(lv_obj_t * obj, lv_meter_scale_t * scale, lv_color_t color_start, lv_color_t color_end, bool local, int16_t width_mod) { lv_meter_indicator_t * indic = _lv_ll_ins_head(&scale->indicator_ll); - LV_ASSERT_MEM(indic); + LV_ASSERT_MALLOC(indic); lv_memset_00(indic, sizeof(lv_meter_indicator_t)); indic->opa = LV_OPA_COVER; diff --git a/src/lv_widgets/lv_objx_templ.c b/src/lv_widgets/lv_objx_templ.c index ff71ba280..18fd78e7d 100644 --- a/src/lv_widgets/lv_objx_templ.c +++ b/src/lv_widgets/lv_objx_templ.c @@ -15,7 +15,7 @@ /********************* * INCLUDES *********************/ -#include "../lv_misc/lv_debug.h" +#include //#include "lv_templ.h" /*TODO uncomment this*/ #if defined(LV_USE_TEMPL) && LV_USE_TEMPL != 0 @@ -62,7 +62,7 @@ lv_obj_t * lv_templ_create(lv_obj_t * par, const lv_obj_t * copy) /*Create the ancestor of template*/ /*TODO modify it to the ancestor create function */ lv_obj_t * new_templ = lv_ANCESTOR_create(par, copy); - LV_ASSERT_MEM(new_templ); + LV_ASSERT_MALLOC(new_templ); if(new_templ == NULL) return NULL; /*Allocate the template type specific extended data*/ diff --git a/src/lv_widgets/lv_roller.c b/src/lv_widgets/lv_roller.c index 5f144e526..21045582a 100644 --- a/src/lv_widgets/lv_roller.c +++ b/src/lv_widgets/lv_roller.c @@ -9,7 +9,7 @@ #include "lv_roller.h" #if LV_USE_ROLLER != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_draw/lv_draw.h" #include "../lv_core/lv_group.h" #include "../lv_core/lv_indev.h" @@ -90,7 +90,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * parent, const lv_obj_t * copy) void lv_roller_set_options(lv_obj_t * obj, const char * options, lv_roller_mode_t mode) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(options); + LV_ASSERT_NULL(options); lv_roller_t * roller = (lv_roller_t*)obj; lv_obj_t * label = get_label(obj); diff --git a/src/lv_widgets/lv_slider.c b/src/lv_widgets/lv_slider.c index 471330801..0f612e4d5 100644 --- a/src/lv_widgets/lv_slider.c +++ b/src/lv_widgets/lv_slider.c @@ -10,7 +10,7 @@ #include "lv_slider.h" #if LV_USE_SLIDER != 0 -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_group.h" #include "../lv_core/lv_indev.h" #include "../lv_draw/lv_draw.h" diff --git a/src/lv_widgets/lv_switch.c b/src/lv_widgets/lv_switch.c index a686325a2..8391756f4 100644 --- a/src/lv_widgets/lv_switch.c +++ b/src/lv_widgets/lv_switch.c @@ -15,7 +15,7 @@ #error "lv_sw: lv_slider is required. Enable it in lv_conf.h (LV_USE_SLIDER 1)" #endif -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_misc/lv_math.h" #include "../lv_core/lv_indev.h" #include "../lv_core/lv_disp.h" diff --git a/src/lv_widgets/lv_table.c b/src/lv_widgets/lv_table.c index bcbe8371a..ee5a8d5bb 100644 --- a/src/lv_widgets/lv_table.c +++ b/src/lv_widgets/lv_table.c @@ -10,7 +10,7 @@ #if LV_USE_TABLE != 0 #include "../lv_core/lv_indev.h" -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_misc/lv_txt.h" #include "../lv_misc/lv_txt_ap.h" #include "../lv_misc/lv_math.h" @@ -108,13 +108,13 @@ void lv_table_set_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col, const c /*Get the size of the Arabic text and process it*/ size_t len_ap = _lv_txt_ap_calc_bytes_cnt(txt); table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], len_ap + 1); - LV_ASSERT_MEM(table->cell_data[cell]); + LV_ASSERT_MALLOC(table->cell_data[cell]); if(table->cell_data[cell] == NULL) return; _lv_txt_ap_proc(txt, &table->cell_data[cell][1]); #else table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], strlen(txt) + 2); /*+1: trailing '\0; +1: format byte*/ - LV_ASSERT_MEM(table->cell_data[cell]); + LV_ASSERT_MALLOC(table->cell_data[cell]); strcpy(table->cell_data[cell] + 1, txt); /*+1 to skip the format byte*/ #endif @@ -133,7 +133,7 @@ void lv_table_set_cell_value(lv_obj_t * obj, uint16_t row, uint16_t col, const c void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, const char * fmt, ...) { LV_ASSERT_OBJ(obj, MY_CLASS); - LV_ASSERT_STR(fmt); + LV_ASSERT_NULL(fmt); lv_table_t * table = (lv_table_t *) obj; if(col >= table->col_cnt) { @@ -170,7 +170,7 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con #if LV_USE_ARABIC_PERSIAN_CHARS /*Put together the text according to the format string*/ char * raw_txt = lv_mem_buf_get(len + 1); - LV_ASSERT_MEM(raw_txt); + LV_ASSERT_MALLOC(raw_txt); if(raw_txt == NULL) { va_end(ap2); return; @@ -181,7 +181,7 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con /*Get the size of the Arabic text and process it*/ size_t len_ap = _lv_txt_ap_calc_bytes_cnt(raw_txt); table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], len_ap + 1); - LV_ASSERT_MEM(table->cell_data[cell]); + LV_ASSERT_MALLOC(table->cell_data[cell]); if(table->cell_data[cell] == NULL) { va_end(ap2); return; @@ -191,7 +191,7 @@ void lv_table_set_cell_value_fmt(lv_obj_t * obj, uint16_t row, uint16_t col, con lv_mem_buf_release(raw_txt); #else table->cell_data[cell] = lv_mem_realloc(table->cell_data[cell], len + 2); /*+1: trailing '\0; +1: format byte*/ - LV_ASSERT_MEM(table->cell_data[cell]); + LV_ASSERT_MALLOC(table->cell_data[cell]); if(table->cell_data[cell] == NULL) { va_end(ap2); return; @@ -222,11 +222,11 @@ void lv_table_set_row_cnt(lv_obj_t * obj, uint16_t row_cnt) table->row_cnt = row_cnt; table->row_h = lv_mem_realloc(table->row_h, table->row_cnt * sizeof(table->row_h[0])); - LV_ASSERT_MEM(table->row_h); + LV_ASSERT_MALLOC(table->row_h); if(table->row_h == NULL) return; table->cell_data = lv_mem_realloc(table->cell_data, table->row_cnt * table->col_cnt * sizeof(char *)); - LV_ASSERT_MEM(table->cell_data); + LV_ASSERT_MALLOC(table->cell_data); if(table->cell_data == NULL) return; /*Initialize the new fields*/ @@ -252,11 +252,11 @@ void lv_table_set_col_cnt(lv_obj_t * obj, uint16_t col_cnt) uint16_t old_col_cnt = table->col_cnt; table->col_cnt = col_cnt; table->col_w = lv_mem_realloc(table->col_w, col_cnt * sizeof(table->row_h[0])); - LV_ASSERT_MEM(table->col_w); + LV_ASSERT_MALLOC(table->col_w); if(table->col_w == NULL) return; char ** new_cell_data = lv_mem_alloc(table->row_cnt * table->col_cnt * sizeof(char *)); - LV_ASSERT_MEM(new_cell_data); + LV_ASSERT_MALLOC(new_cell_data); if(new_cell_data == NULL) return; uint32_t new_cell_cnt = table->col_cnt * table->row_cnt; lv_memset_00(new_cell_data, new_cell_cnt * sizeof(table->cell_data[0])); @@ -328,7 +328,7 @@ void lv_table_set_cell_crop(lv_obj_t * obj, uint16_t row, uint16_t col, bool cro if(table->cell_data[cell] == NULL) { table->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ - LV_ASSERT_MEM(table->cell_data[cell]); + LV_ASSERT_MALLOC(table->cell_data[cell]); if(table->cell_data[cell] == NULL) return; table->cell_data[cell][0] = 0; @@ -362,7 +362,7 @@ void lv_table_set_cell_merge_right(lv_obj_t * obj, uint16_t row, uint16_t col, b if(table->cell_data[cell] == NULL) { table->cell_data[cell] = lv_mem_alloc(2); /*+1: trailing '\0; +1: format byte*/ - LV_ASSERT_MEM(table->cell_data[cell]); + LV_ASSERT_MALLOC(table->cell_data[cell]); if(table->cell_data[cell] == NULL) return; table->cell_data[cell][0] = 0; diff --git a/src/lv_widgets/lv_textarea.c b/src/lv_widgets/lv_textarea.c index 3c6788378..66ba47530 100644 --- a/src/lv_widgets/lv_textarea.c +++ b/src/lv_widgets/lv_textarea.c @@ -10,7 +10,7 @@ #if LV_USE_TEXTAREA != 0 #include -#include "../lv_misc/lv_debug.h" +#include "../lv_misc/lv_assert.h" #include "../lv_core/lv_group.h" #include "../lv_core/lv_refr.h" #include "../lv_core/lv_indev.h" @@ -152,7 +152,7 @@ void lv_textarea_add_char(lv_obj_t * obj, uint32_t c) if(ta->pwd_mode != 0) { ta->pwd_tmp = lv_mem_realloc(ta->pwd_tmp, strlen(ta->pwd_tmp) + strlen(letter_buf) + 1); /*+2: the new char + \0 */ - LV_ASSERT_MEM(ta->pwd_tmp); + LV_ASSERT_MALLOC(ta->pwd_tmp); if(ta->pwd_tmp == NULL) return; _lv_txt_ins(ta->pwd_tmp, ta->cursor.pos, (const char *)letter_buf); @@ -223,7 +223,7 @@ void lv_textarea_add_text(lv_obj_t * obj, const char * txt) if(ta->pwd_mode != 0) { ta->pwd_tmp = lv_mem_realloc(ta->pwd_tmp, strlen(ta->pwd_tmp) + strlen(txt) + 1); - LV_ASSERT_MEM(ta->pwd_tmp); + LV_ASSERT_MALLOC(ta->pwd_tmp); if(ta->pwd_tmp == NULL) return; _lv_txt_ins(ta->pwd_tmp, ta->cursor.pos, txt); @@ -292,7 +292,7 @@ void lv_textarea_del_char(lv_obj_t * obj) _lv_txt_cut(ta->pwd_tmp, ta->cursor.pos - 1, _lv_txt_encoded_size(&ta->pwd_tmp[byte_pos])); ta->pwd_tmp = lv_mem_realloc(ta->pwd_tmp, strlen(ta->pwd_tmp) + 1); - LV_ASSERT_MEM(ta->pwd_tmp); + LV_ASSERT_MALLOC(ta->pwd_tmp); if(ta->pwd_tmp == NULL) return; } @@ -361,7 +361,7 @@ void lv_textarea_set_text(lv_obj_t * obj, const char * txt) if(ta->pwd_mode != 0) { ta->pwd_tmp = lv_mem_realloc(ta->pwd_tmp, strlen(txt) + 1); - LV_ASSERT_MEM(ta->pwd_tmp); + LV_ASSERT_MALLOC(ta->pwd_tmp); if(ta->pwd_tmp == NULL) return; strcpy(ta->pwd_tmp, txt); @@ -419,7 +419,7 @@ void lv_textarea_set_placeholder_text(lv_obj_t * obj, const char * txt) ta->placeholder_txt = lv_mem_realloc(ta->placeholder_txt, txt_len + 1); } - LV_ASSERT_MEM(ta->placeholder_txt); + LV_ASSERT_MALLOC(ta->placeholder_txt); if(ta->placeholder_txt == NULL) { LV_LOG_ERROR("lv_textarea_set_placeholder_text: couldn't allocate memory for placeholder"); return; @@ -510,7 +510,7 @@ void lv_textarea_set_pwd_mode(lv_obj_t * obj, bool en) char * txt = lv_label_get_text(ta->label); size_t len = strlen(txt); ta->pwd_tmp = lv_mem_alloc(len + 1); - LV_ASSERT_MEM(ta->pwd_tmp); + LV_ASSERT_MALLOC(ta->pwd_tmp); if(ta->pwd_tmp == NULL) return; strcpy(ta->pwd_tmp, txt); @@ -994,7 +994,7 @@ static void lv_textarea_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_ if(copy_ta->pwd_tmp) { uint32_t len = lv_mem_get_size(copy_ta->pwd_tmp); ta->pwd_tmp = lv_mem_alloc(len); - LV_ASSERT_MEM(ta->pwd_tmp); + LV_ASSERT_MALLOC(ta->pwd_tmp); if(ta->pwd_tmp == NULL) return; lv_memcpy(ta->pwd_tmp, copy_ta->pwd_tmp, len);