From 2cae4a27c118e8e8d031f02aa59ba1e720cb9773 Mon Sep 17 00:00:00 2001 From: Gabor Kiss-Vamosi Date: Fri, 5 Feb 2021 16:52:51 +0100 Subject: [PATCH] add some extra components and examples --- .../btnmatrix/lv_btnmatrix_example_3.c | 71 ++++ examples/widgets/msgbox/lv_msgbox_example_1.c | 10 +- .../widgets/spinbox/lv_spinbox_example_1.c | 12 +- .../widgets/spinner/lv_spinner_example_1.c | 2 +- .../widgets/tabview/lv_tabview_example_1.c | 9 +- lvgl.h | 4 + scripts/style_api_gen.py | 24 +- src/extra/layouts/flex/lv_flex.c | 10 +- src/extra/layouts/flex/lv_flex.h | 3 +- src/extra/themes/default/lv_theme_default.c | 70 ++-- src/extra/widgets/msgbox/lv_msgbox.c | 62 ++-- src/extra/widgets/msgbox/lv_msgbox.h | 3 +- src/extra/widgets/spinbox/lv_spinbox.c | 316 +++++++++--------- src/extra/widgets/spinbox/lv_spinbox.h | 37 +- src/extra/widgets/spinner/lv_spinner.c | 34 +- src/extra/widgets/spinner/lv_spinner.h | 6 +- src/extra/widgets/tabview/lv_tabview.c | 240 +++++++------ src/extra/widgets/tabview/lv_tabview.h | 9 +- src/lv_core/lv_obj_draw.c | 20 +- src/lv_core/lv_obj_pos.c | 6 +- src/lv_core/lv_obj_pos.h | 23 +- src/lv_core/lv_obj_style.h | 43 ++- src/lv_draw/lv_draw_arc.c | 9 +- src/lv_draw/lv_draw_arc.h | 2 +- src/lv_draw/lv_draw_rect.c | 7 +- src/lv_misc/lv_anim.h | 2 +- src/lv_misc/lv_style.c | 9 +- src/lv_misc/lv_style.h | 49 ++- src/lv_widgets/lv_arc.c | 83 +---- src/lv_widgets/lv_arc.h | 1 - src/lv_widgets/lv_btnmatrix.c | 5 +- 31 files changed, 646 insertions(+), 535 deletions(-) create mode 100644 examples/widgets/btnmatrix/lv_btnmatrix_example_3.c diff --git a/examples/widgets/btnmatrix/lv_btnmatrix_example_3.c b/examples/widgets/btnmatrix/lv_btnmatrix_example_3.c new file mode 100644 index 000000000..07256b55a --- /dev/null +++ b/examples/widgets/btnmatrix/lv_btnmatrix_example_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_ex_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/msgbox/lv_msgbox_example_1.c b/examples/widgets/msgbox/lv_msgbox_example_1.c index cede7d285..c13a79740 100644 --- a/examples/widgets/msgbox/lv_msgbox_example_1.c +++ b/examples/widgets/msgbox/lv_msgbox_example_1.c @@ -2,7 +2,7 @@ #include #if LV_USE_MSGBOX -static void event_handler(lv_obj_t * obj, lv_event_t event) +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)); @@ -11,15 +11,15 @@ static void event_handler(lv_obj_t * obj, lv_event_t event) void lv_ex_msgbox_1(void) { - static lv_style_t style; - lv_style_init(&style); - lv_style_set_radius(&style, LV_STATE_DEFAULT, 30); +// 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_set_event_cb(mbox1, event_handler); + lv_obj_add_event_cb(mbox1, event_cb, NULL); lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/ } diff --git a/examples/widgets/spinbox/lv_spinbox_example_1.c b/examples/widgets/spinbox/lv_spinbox_example_1.c index 489d9c1d0..362bdeeba 100644 --- a/examples/widgets/spinbox/lv_spinbox_example_1.c +++ b/examples/widgets/spinbox/lv_spinbox_example_1.c @@ -30,16 +30,18 @@ void lv_ex_spinbox_1(void) 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_local_value_str(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_PLUS); - lv_obj_set_event_cb(btn, lv_spinbox_increment_event_cb); + 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(), btn); + 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_event_cb(btn, lv_spinbox_decrement_event_cb); - lv_obj_set_style_local_value_str(btn, LV_BTN_PART_MAIN, LV_STATE_DEFAULT, LV_SYMBOL_MINUS); + 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/spinner/lv_spinner_example_1.c b/examples/widgets/spinner/lv_spinner_example_1.c index a4c7fee04..09585e8d3 100644 --- a/examples/widgets/spinner/lv_spinner_example_1.c +++ b/examples/widgets/spinner/lv_spinner_example_1.c @@ -4,7 +4,7 @@ void lv_ex_spinner_1(void) { /*Create a Preloader object*/ - lv_obj_t * spinner = lv_spinner_create(lv_scr_act(), 500, 60); + 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); } diff --git a/examples/widgets/tabview/lv_tabview_example_1.c b/examples/widgets/tabview/lv_tabview_example_1.c index 4364dc24b..f156dc42e 100644 --- a/examples/widgets/tabview/lv_tabview_example_1.c +++ b/examples/widgets/tabview/lv_tabview_example_1.c @@ -19,13 +19,16 @@ void lv_ex_tabview_1(void) "If the content\n" "of a tab\n" "becomes too\n" - "long then\n" - "it will \n" + "longer\n" + "than the\n" + "container\n" + "then it\n" "automatically\n" - "become\n" + "becomes\n" "scrollable.\n" "\n" "\n" + "\n" "Can you see it?"); label = lv_label_create(tab2, NULL); diff --git a/lvgl.h b/lvgl.h index fa647db79..d65367fe7 100644 --- a/lvgl.h +++ b/lvgl.h @@ -73,6 +73,10 @@ extern "C" { #include "src/extra/widgets/calendar/lv_calendar_header_arrow.h" #include "src/extra/widgets/keyboard/lv_keyboard.h" #include "src/extra/widgets/list/lv_list.h" +#include "src/extra/widgets/msgbox/lv_msgbox.h" +#include "src/extra/widgets/spinbox/lv_spinbox.h" +#include "src/extra/widgets/spinner/lv_spinner.h" +#include "src/extra/widgets/tabview/lv_tabview.h" /* LAYOUTS */ #include "src/extra/layouts/flex/lv_flex.h" diff --git a/scripts/style_api_gen.py b/scripts/style_api_gen.py index aef41446f..103166358 100755 --- a/scripts/style_api_gen.py +++ b/scripts/style_api_gen.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 + props = [ {'name': 'RADIUS', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'CLIP_CORNER', 'style_type': 'num', 'var_type': 'bool' }, @@ -68,7 +70,13 @@ props = [ {'name': 'LINE_ROUNDED', 'style_type': 'num', 'var_type': 'lv_coord_t' }, {'name': 'LINE_COLOR', 'style_type': 'color', 'var_type': 'lv_color_t' }, {'name': 'LINE_COLOR_FILTERED', 'style_type': 'color', 'var_type': 'lv_color_t' }, -{'name': 'LINE_OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' }, +{'name': 'LINE_OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' }, +{'name': 'ARC_WIDTH', 'style_type': 'num', 'var_type': 'lv_coord_t' }, +{'name': 'ARC_ROUNDED', 'style_type': 'num', 'var_type': 'lv_coord_t' }, +{'name': 'ARC_COLOR', 'style_type': 'color', 'var_type': 'lv_color_t' }, +{'name': 'ARC_COLOR_FILTERED', 'style_type': 'color', 'var_type': 'lv_color_t' }, +{'name': 'ARC_OPA', 'style_type': 'num', 'var_type': 'lv_opa_t' }, +{'name': 'ARC_IMG_SRC', 'style_type': 'ptr', 'var_type': 'const void *' }, {'name': 'CONTENT_TEXT', 'style_type': 'ptr', 'var_type': 'const char *' }, {'name': 'CONTENT_ALIGN', 'style_type': 'num', 'var_type': 'lv_align_t' }, {'name': 'CONTENT_OFS_X', 'style_type': 'num', 'var_type': 'lv_coord_t' }, @@ -99,9 +107,23 @@ def local_style_set(i): print("") +for i in range(len(props)): + obj_style_get(i) + +print("") +print("--------------------------------------------------------------------------------------------") +print("") + + for i in range(len(props)): local_style_set(i) +print("") +print("--------------------------------------------------------------------------------------------") +print("") + +for i in range(len(props)): + style_set(i) diff --git a/src/extra/layouts/flex/lv_flex.c b/src/extra/layouts/flex/lv_flex.c index 2761d7583..17490a44a 100644 --- a/src/extra/layouts/flex/lv_flex.c +++ b/src/extra/layouts/flex/lv_flex.c @@ -44,7 +44,7 @@ static lv_obj_t * get_next_item(lv_obj_t * cont, bool rev, int32_t * item_id); const lv_flex_t lv_flex_inline = { .base.update_cb = flex_update, .item_main_place = LV_FLEX_PLACE_START, - .item_cross_place = LV_FLEX_PLACE_START, + .item_cross_place = LV_FLEX_PLACE_CENTER, .track_cross_place = LV_FLEX_PLACE_START, .dir = LV_FLEX_FLOW_ROW, .wrap = 1 @@ -77,6 +77,14 @@ const lv_flex_t lv_flex_stacked = { .dir = LV_FLEX_FLOW_COLUMN }; +const lv_flex_t lv_flex_queue = { + .base.update_cb = flex_update, + .item_main_place = LV_FLEX_PLACE_START, + .item_cross_place = LV_FLEX_PLACE_START, + .track_cross_place = LV_FLEX_PLACE_START, + .dir = LV_FLEX_FLOW_ROW +}; + const lv_flex_t lv_flex_even = { .base.update_cb = flex_update, .item_main_place = LV_FLEX_PLACE_SPACE_EVENLY, diff --git a/src/extra/layouts/flex/lv_flex.h b/src/extra/layouts/flex/lv_flex.h index 88a52dee3..694044366 100644 --- a/src/extra/layouts/flex/lv_flex.h +++ b/src/extra/layouts/flex/lv_flex.h @@ -104,7 +104,8 @@ void lv_obj_set_flex_grow(struct _lv_obj_t * obj, uint8_t grow); extern const lv_flex_t lv_flex_inline; /**< Just put the items next to each other with wrap*/ extern const lv_flex_t lv_flex_center_row; /**< Center in a row with wrap*/ extern const lv_flex_t lv_flex_center_column; /**< Center in a column with wrap*/ -extern const lv_flex_t lv_flex_stacked; /**< Stack the items vertically*/ +extern const lv_flex_t lv_flex_stacked; /**< Stack the items vertically without wrapping*/ +extern const lv_flex_t lv_flex_queue; /**< Put the items next to each other without wrap*/ extern const lv_flex_t lv_flex_even; /**< Place the items evenly in row with wrapping and vertical centering*/ /********************** diff --git a/src/extra/themes/default/lv_theme_default.c b/src/extra/themes/default/lv_theme_default.c index 461346835..3b6c2e3a2 100644 --- a/src/extra/themes/default/lv_theme_default.c +++ b/src/extra/themes/default/lv_theme_default.c @@ -152,7 +152,6 @@ typedef struct { #if LV_USE_LIST lv_style_t list_bg, list_btn, list_item_grow, list_label; #endif - } my_theme_styles_t; typedef struct { @@ -206,7 +205,6 @@ static void style_init(void) style_init_reset(&styles->transition_normal); lv_style_set_transition(&styles->transition_normal, &trans_normal); /*Go back to default state with delay*/ - style_init_reset(&styles->scrollbar); lv_style_set_bg_opa(&styles->scrollbar, LV_OPA_COVER); lv_style_set_bg_color(&styles->scrollbar, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x777f85))); @@ -268,7 +266,7 @@ static void style_init(void) style_init_reset(&styles->pressed); lv_style_set_color_filter_cb(&styles->pressed, lv_color_darken); - lv_style_set_color_filter_opa(&styles->pressed, LV_OPA_20); + lv_style_set_color_filter_opa(&styles->pressed, 35); style_init_reset(&styles->disabled); lv_style_set_color_filter_cb(&styles->disabled, gray_filter); @@ -308,21 +306,26 @@ static void style_init(void) style_init_reset(&styles->bg_color_primary); lv_style_set_bg_color(&styles->bg_color_primary, theme.color_primary); lv_style_set_text_color(&styles->bg_color_primary, LV_COLOR_WHITE); + lv_style_set_content_color(&styles->bg_color_primary, LV_COLOR_WHITE); lv_style_set_bg_opa(&styles->bg_color_primary, LV_OPA_COVER); style_init_reset(&styles->bg_color_secondary); lv_style_set_bg_color(&styles->bg_color_secondary, theme.color_secondary); lv_style_set_text_color(&styles->bg_color_secondary, LV_COLOR_WHITE); + lv_style_set_content_color(&styles->bg_color_secondary, LV_COLOR_WHITE); lv_style_set_bg_opa(&styles->bg_color_secondary, LV_OPA_COVER); style_init_reset(&styles->bg_color_gray); lv_style_set_bg_color(&styles->bg_color_gray, COLOR_GRAY); lv_style_set_bg_opa(&styles->bg_color_gray, LV_OPA_COVER); lv_style_set_text_color(&styles->bg_color_gray, CARD_TEXT_COLOR); + lv_style_set_content_color(&styles->bg_color_gray, CARD_TEXT_COLOR); style_init_reset(&styles->bg_color_white); lv_style_set_bg_color(&styles->bg_color_white, LV_COLOR_WHITE); lv_style_set_bg_opa(&styles->bg_color_white, LV_OPA_COVER); + lv_style_set_text_color(&styles->bg_color_white, CARD_TEXT_COLOR); + lv_style_set_content_color(&styles->bg_color_white, CARD_TEXT_COLOR); style_init_reset(&styles->circle); lv_style_set_radius(&styles->circle, LV_RADIUS_CIRCLE); @@ -349,14 +352,12 @@ static void style_init(void) #if LV_USE_ARC style_init_reset(&styles->arc_indic); - lv_style_set_line_color(&styles->arc_indic, COLOR_GRAY); - lv_style_set_line_width(&styles->arc_indic, LV_DPX(15)); - lv_style_set_line_rounded(&styles->arc_indic, true); + lv_style_set_arc_color(&styles->arc_indic, COLOR_GRAY); + lv_style_set_arc_width(&styles->arc_indic, LV_DPX(15)); + lv_style_set_arc_rounded(&styles->arc_indic, true); style_init_reset(&styles->arc_indic_primary); - lv_style_set_line_color(&styles->arc_indic_primary, theme.color_primary); - LV_IMG_DECLARE(asd); - lv_style_set_bg_img_src(&styles->arc_indic_primary, &asd); + lv_style_set_arc_color(&styles->arc_indic_primary, theme.color_primary); #endif #if LV_USE_DROPDOWN @@ -527,6 +528,15 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_BTNMATRIX else if(lv_obj_check_type(obj, &lv_btnmatrix)) { +#if LV_USE_MSGBOX + if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_msgbox)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_gap); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); + lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_primary); + return; + } +#endif lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); @@ -647,17 +657,16 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) #if LV_USE_LABEL else if(lv_obj_check_type(obj, &lv_label)) { #if LV_USE_LIST - if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_list)) { - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray); - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_item_grow); - } + if(lv_obj_check_type(lv_obj_get_parent(obj), &lv_list)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->bg_color_gray); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_item_grow); + } #endif } #endif #if LV_USE_ARC else if(lv_obj_check_type(obj, &lv_arc)) { - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->arc_indic); lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->arc_indic); lv_obj_add_style(obj, LV_PART_INDICATOR, LV_STATE_DEFAULT, &styles->arc_indic_primary); @@ -700,23 +709,28 @@ static void theme_apply(lv_theme_t * th, lv_obj_t * obj) lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->bg_color_white); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_gray); -// lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); -// lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->no_radius); -// lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->pad_small); -// lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_DEFAULT, &styles->btn); -// lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_PRESSED, &styles->pressed); -// lv_obj_add_style(obj, LV_PART_ITEMS, LV_STATE_CHECKED, &styles->bg_color_primary); } #endif #if LV_USE_LIST - /*Add different buttons to the lists*/ - if(lv_obj_check_type(obj, &lv_list)) { - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); - lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_bg); - lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); - lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); - return; - } + else if(lv_obj_check_type(obj, &lv_list)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->list_bg); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_DEFAULT, &styles->scrollbar); + lv_obj_add_style(obj, LV_PART_SCROLLBAR, LV_STATE_SCROLLED, &styles->scrollbar_scrolled); + return; + } +#endif +#if LV_USE_MSGBOX + else if(lv_obj_check_type(obj, &lv_msgbox)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); + return; + } +#endif +#if LV_USE_SPINBOX + else if(lv_obj_check_type(obj, &lv_spinbox)) { + lv_obj_add_style(obj, LV_PART_MAIN, LV_STATE_DEFAULT, &styles->card); + lv_obj_add_style(obj, LV_PART_MARKER, LV_STATE_DEFAULT, &styles->bg_color_gray); + } #endif } diff --git a/src/extra/widgets/msgbox/lv_msgbox.c b/src/extra/widgets/msgbox/lv_msgbox.c index 5a4f6403e..91056d546 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.c +++ b/src/extra/widgets/msgbox/lv_msgbox.c @@ -26,7 +26,7 @@ static void msgbox_close_event_cb(lv_obj_t * btn, lv_event_t e); /********************** * STATIC VARIABLES **********************/ -static bool inited = false; +const lv_obj_class_t lv_msgbox = {.base_class = &lv_obj}; /********************** * MACROS @@ -45,74 +45,54 @@ static bool inited = false; */ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * btn_txts[], bool add_close_btn) { - static lv_style_t style_title; - static lv_style_t style_btnm_bg; - if(!inited) { - lv_style_init(&style_title); - lv_style_set_text_font(&style_title, LV_STATE_DEFAULT, lv_theme_get_font_subtitle()); - lv_style_set_margin_bottom(&style_title, LV_STATE_DEFAULT, LV_DPX(8)); - - lv_style_init(&style_btnm_bg); - lv_style_set_margin_top(&style_btnm_bg, LV_STATE_DEFAULT, LV_DPX(8)); - - inited = true; - } - lv_obj_t * parent = lv_obj_create(lv_layer_top(), NULL); - lv_obj_reset_style_list(parent, LV_OBJ_PART_MAIN); lv_obj_set_size(parent, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_remove_style(parent, LV_PART_ANY, LV_STATE_ANY, NULL); - lv_obj_t * mbox = lv_obj_create(parent, NULL); + lv_obj_t * mbox = lv_obj_create_from_class(&lv_msgbox, parent, NULL); LV_ASSERT_MEM(mbox); if(mbox == NULL) return NULL; lv_coord_t w = lv_obj_get_width_fit(parent); - if(w > 2 * LV_DPI) w = 2 * LV_DPI; + if(w > 2 * LV_DPI_DEF) w = 2 * LV_DPI_DEF; lv_obj_set_size(mbox, w, LV_SIZE_AUTO); - lv_obj_set_flex_dir(mbox, LV_FLEX_DIR_ROW_WRAP); + lv_obj_set_layout(mbox, &lv_flex_inline); lv_obj_t * label; label = lv_label_create(mbox, NULL); lv_label_set_text(label, title); - lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); - lv_obj_set_width(label, add_close_btn ? LV_FLEX_GROW(1) : LV_COORD_PCT(100)); - lv_obj_set_flex_item(label, true); - lv_obj_add_style(label, LV_LABEL_PART_MAIN, &style_title); + lv_label_set_long_mode(label, LV_LABEL_LONG_SROLL_CIRC); + if(add_close_btn) lv_obj_set_flex_grow(label, 1); + else lv_obj_set_width(label, LV_COORD_PCT(100)); if(add_close_btn) { lv_obj_t * close_btn = lv_btn_create(mbox, NULL); - lv_obj_add_style(close_btn, LV_BTN_PART_MAIN, &style_title); - lv_obj_set_ext_click_area(close_btn, LV_DPX(10), LV_DPX(10), LV_DPX(10), LV_DPX(10)); - lv_obj_set_event_cb(close_btn, msgbox_close_event_cb); + lv_obj_set_ext_click_area(close_btn, LV_DPX(10)); + lv_obj_add_event_cb(close_btn, msgbox_close_event_cb, NULL); label = lv_label_create(close_btn, NULL); lv_label_set_text(label, LV_SYMBOL_CLOSE); lv_coord_t close_btn_size = LV_MAX(lv_obj_get_width(label), lv_obj_get_height(label)) + LV_DPX(10); lv_obj_set_size(close_btn, close_btn_size, close_btn_size); lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); - lv_obj_set_flex_item_place(close_btn, LV_FLEX_PLACE_CENTER); } label = lv_label_create(mbox, NULL); lv_label_set_text(label, txt); - lv_label_set_long_mode(label, LV_LABEL_LONG_BREAK); + lv_label_set_long_mode(label, LV_LABEL_LONG_WRAP); lv_obj_set_width(label, LV_COORD_PCT(100)); - lv_obj_set_flex_item(label, LV_FLEX_PLACE_START); lv_obj_t * btns = lv_btnmatrix_create(mbox, NULL); lv_btnmatrix_set_map(btns, btn_txts); - lv_obj_reset_style_list(btns, LV_BTNMATRIX_PART_MAIN); - lv_obj_add_style(btns, LV_BTNMATRIX_PART_MAIN, &style_btnm_bg); - lv_obj_set_flex_item(btns, LV_FLEX_PLACE_START); uint32_t btn_cnt = 0; while(btn_txts[btn_cnt][0] != '\0') { btn_cnt++; } - const lv_font_t * font = lv_obj_get_style_text_font(btns, LV_BTNMATRIX_PART_BTN); - lv_coord_t btn_h = lv_font_get_line_height(font) + LV_DPI / 10; - lv_obj_set_size(btns, btn_cnt * (2 * LV_DPI / 3), btn_h); + const lv_font_t * font = lv_obj_get_style_text_font(btns, LV_PART_ITEMS); + lv_coord_t btn_h = lv_font_get_line_height(font) + LV_DPI_DEF / 10; + lv_obj_set_size(btns, btn_cnt * (2 * LV_DPI_DEF / 3), btn_h); lv_obj_add_flag(btns, LV_OBJ_FLAG_EVENT_BUBBLE); /*To see the event directly on the message box*/ return mbox; } @@ -120,30 +100,30 @@ lv_obj_t * lv_msgbox_create(const char * title, const char * txt, const char * b lv_obj_t * lv_msgbox_get_title(lv_obj_t * mbox) { - return lv_obj_get_child_by_id(mbox, 0); + return lv_obj_get_child(mbox, 0); } lv_obj_t * lv_msgbox_get_close_btn(lv_obj_t * mbox) { - uint32_t cnt = lv_obj_count_children(mbox); - if(cnt == 3) return NULL; /*No close button*/ - else return lv_obj_get_child_by_id(mbox, 1); + lv_obj_t * obj = lv_obj_get_child(mbox, 1); + if(lv_obj_check_type(obj, &lv_btn)) return obj; + else return NULL; } lv_obj_t * lv_msgbox_get_text(lv_obj_t * mbox) { - return lv_obj_get_child_by_id(mbox, lv_obj_count_children(mbox) - 2); + return lv_obj_get_child(mbox, lv_obj_get_child_cnt(mbox) - 2); } lv_obj_t * lv_msgbox_get_btns(lv_obj_t * mbox) { - return lv_obj_get_child_by_id(mbox, lv_obj_count_children(mbox) - 1); + return lv_obj_get_child(mbox, lv_obj_get_child_cnt(mbox) - 1); } const char * lv_msgbox_get_active_btn_text(lv_obj_t * mbox) { lv_obj_t * btnm = lv_msgbox_get_btns(mbox); - return lv_btnmatrix_get_active_btn_text(btnm); + return lv_btnmatrix_get_btn_text(btnm, lv_btnmatrix_get_active_btn(btnm)); } void lv_msgbox_close(lv_obj_t * mbox) diff --git a/src/extra/widgets/msgbox/lv_msgbox.h b/src/extra/widgets/msgbox/lv_msgbox.h index 2afce5d5c..c5c3c464f 100644 --- a/src/extra/widgets/msgbox/lv_msgbox.h +++ b/src/extra/widgets/msgbox/lv_msgbox.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../../lv_core/lv_obj.h" +#include "../../../lvgl.h" #if LV_USE_MSGBOX @@ -33,6 +33,7 @@ extern "C" { /********************** * TYPEDEFS **********************/ +extern const lv_obj_class_t lv_msgbox; /********************** * GLOBAL PROTOTYPES diff --git a/src/extra/widgets/spinbox/lv_spinbox.c b/src/extra/widgets/spinbox/lv_spinbox.c index 8cd444de0..2654c239e 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.c +++ b/src/extra/widgets/spinbox/lv_spinbox.c @@ -12,6 +12,7 @@ /********************* * DEFINES *********************/ +#define MY_CLASS &lv_spinbox /********************** * TYPEDEFS @@ -20,14 +21,22 @@ /********************** * STATIC PROTOTYPES **********************/ -static lv_res_t lv_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param); -static void lv_spinbox_updatevalue(lv_obj_t * spinbox); + +static void lv_spinbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); +static void lv_spinbox_destructor(lv_obj_t * obj); +static lv_res_t lv_spinbox_signal(lv_obj_t * obj, lv_signal_t sign, void * param); +static void lv_spinbox_updatevalue(lv_obj_t * obj); /********************** * STATIC VARIABLES **********************/ -static lv_signal_cb_t ancestor_signal; - +const lv_obj_class_t lv_spinbox = { + .constructor_cb = lv_spinbox_constructor, + .destructor_cb = lv_spinbox_destructor, + .signal_cb = lv_spinbox_signal, + .instance_size = sizeof(lv_spinbox_t), + .base_class = &lv_textarea +}; /********************** * MACROS **********************/ @@ -44,45 +53,7 @@ static lv_signal_cb_t ancestor_signal; */ lv_obj_t * lv_spinbox_create(lv_obj_t * parent) { - LV_LOG_TRACE("spinbox create started"); - - /*Create the ancestor of spinbox*/ - lv_obj_t * spinbox = lv_textarea_create(parent, NULL); - LV_ASSERT_MEM(spinbox); - if(spinbox == NULL) return NULL; - - /*Allocate the spinbox type specific extended data*/ - lv_spinbox_ext_t * ext = lv_obj_allocate_ext_attr(spinbox, sizeof(lv_spinbox_ext_t)); - LV_ASSERT_MEM(ext); - if(ext == NULL) { - lv_obj_del(spinbox); - return NULL; - } - - if(ancestor_signal == NULL) ancestor_signal = lv_obj_get_signal_cb(spinbox); - - /*Initialize the allocated 'ext'*/ - ext->value = 0; - ext->dec_point_pos = 0; - ext->digit_count = 5; - ext->step = 1; - ext->range_max = 99999; - ext->range_min = -99999; - ext->rollover = false; - - - /*The signal and draw functions are not copied so set them here*/ - lv_obj_set_signal_cb(spinbox, lv_spinbox_signal); - - lv_textarea_set_one_line(spinbox, true); - lv_textarea_set_cursor_click_pos(spinbox, true); - lv_obj_set_width(spinbox, LV_DPI); - - lv_spinbox_updatevalue(spinbox); - - LV_LOG_INFO("spinbox created"); - - return spinbox; + return lv_obj_create_from_class(&lv_spinbox, parent, NULL); } /*===================== @@ -94,17 +65,16 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * parent) * @param spinbox pointer to spinbox * @param i value to be set */ -void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i) +void lv_spinbox_set_value(lv_obj_t * obj, int32_t i) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - if(ext == NULL) return; + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - if(i > ext->range_max) i = ext->range_max; - if(i < ext->range_min) i = ext->range_min; + if(i > spinbox->range_max) i = spinbox->range_max; + if(i < spinbox->range_min) i = spinbox->range_min; - ext->value = i; + spinbox->value = i; - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /** @@ -112,11 +82,11 @@ void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i) * @param spinbox pointer to spinbox * @param b true or false to enable or disable (default) */ -void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b) +void lv_spinbox_set_rollover(lv_obj_t * obj, bool b) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - ext->rollover = b; + spinbox->rollover = b; } /** @@ -126,10 +96,9 @@ void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b) * @param separator_position number of digit before the decimal point. If 0, decimal point is not * shown */ -void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position) +void lv_spinbox_set_digit_format(lv_obj_t * obj, uint8_t digit_count, uint8_t separator_position) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - if(ext == NULL) return; + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; if(digit_count > LV_SPINBOX_MAX_DIGIT_COUNT) digit_count = LV_SPINBOX_MAX_DIGIT_COUNT; @@ -138,14 +107,14 @@ void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_ if(digit_count < LV_SPINBOX_MAX_DIGIT_COUNT) { int64_t max_val = lv_pow(10, digit_count); - if(ext->range_max > max_val - 1) ext->range_max = max_val - 1; - if(ext->range_min < - max_val + 1) ext->range_min = - max_val + 1; + if(spinbox->range_max > max_val - 1) spinbox->range_max = max_val - 1; + if(spinbox->range_min < - max_val + 1) spinbox->range_min = - max_val + 1; } - ext->digit_count = digit_count; - ext->dec_point_pos = separator_position; + spinbox->digit_count = digit_count; + spinbox->dec_point_pos = separator_position; - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /** @@ -153,13 +122,12 @@ void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_ * @param spinbox pointer to spinbox * @param step steps on increment/decrement */ -void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step) +void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - if(ext == NULL) return; + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - ext->step = step; - lv_spinbox_updatevalue(spinbox); + spinbox->step = step; + lv_spinbox_updatevalue(obj); } /** @@ -168,18 +136,17 @@ void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step) * @param range_min maximum value, inclusive * @param range_max minimum value, inclusive */ -void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max) +void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); - if(ext == NULL) return; + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - ext->range_max = range_max; - ext->range_min = range_min; + spinbox->range_max = range_max; + spinbox->range_min = range_min; - if(ext->value > ext->range_max) ext->value = ext->range_max; - if(ext->value < ext->range_min) ext->value = ext->range_min; + if(spinbox->value > spinbox->range_max) spinbox->value = spinbox->range_max; + if(spinbox->value < spinbox->range_min) spinbox->value = spinbox->range_min; - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /*===================== @@ -191,11 +158,11 @@ void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_m * @param spinbox pointer to spinbox * @return value integer value of the spinbox */ -int32_t lv_spinbox_get_value(lv_obj_t * spinbox) +int32_t lv_spinbox_get_value(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - return ext->value; + return spinbox->value; } /*===================== @@ -206,209 +173,230 @@ int32_t lv_spinbox_get_value(lv_obj_t * spinbox) * Select next lower digit for edition * @param spinbox pointer to spinbox */ -void lv_spinbox_step_next(lv_obj_t * spinbox) +void lv_spinbox_step_next(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - int32_t new_step = ext->step / 10; + int32_t new_step = spinbox->step / 10; if((new_step) > 0) - ext->step = new_step; + spinbox->step = new_step; else - ext->step = 1; + spinbox->step = 1; - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /** * Select next higher digit for edition * @param spinbox pointer to spinbox */ -void lv_spinbox_step_prev(lv_obj_t * spinbox) +void lv_spinbox_step_prev(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; int32_t step_limit; - step_limit = LV_MAX(ext->range_max, (ext->range_min < 0 ? (-ext->range_min) : ext->range_min)); - int32_t new_step = ext->step * 10; - if(new_step <= step_limit) ext->step = new_step; + step_limit = LV_MAX(spinbox->range_max, (spinbox->range_min < 0 ? (-spinbox->range_min) : spinbox->range_min)); + int32_t new_step = spinbox->step * 10; + if(new_step <= step_limit) spinbox->step = new_step; - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /** * Get spinbox rollover function status * @param spinbox pointer to spinbox */ -bool lv_spinbox_get_rollover(lv_obj_t * spinbox) +bool lv_spinbox_get_rollover(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - return ext->rollover; + return spinbox->rollover; } /** * Increment spinbox value by one step * @param spinbox pointer to spinbox */ -void lv_spinbox_increment(lv_obj_t * spinbox) +void lv_spinbox_increment(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - if(ext->value + ext->step <= ext->range_max) { + if(spinbox->value + spinbox->step <= spinbox->range_max) { /*Special mode when zero crossing*/ - if((ext->value + ext->step) > 0 && ext->value < 0) ext->value = -ext->value; - ext->value += ext->step; + if((spinbox->value + spinbox->step) > 0 && spinbox->value < 0) spinbox->value = -spinbox->value; + spinbox->value += spinbox->step; } else { // Rollover? - if((ext->rollover) && (ext->value == ext->range_max)) - ext->value = ext->range_min; + if((spinbox->rollover) && (spinbox->value == spinbox->range_max)) + spinbox->value = spinbox->range_min; else - ext->value = ext->range_max; + spinbox->value = spinbox->range_max; } - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /** * Decrement spinbox value by one step * @param spinbox pointer to spinbox */ -void lv_spinbox_decrement(lv_obj_t * spinbox) +void lv_spinbox_decrement(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; - if(ext->value - ext->step >= ext->range_min) { + if(spinbox->value - spinbox->step >= spinbox->range_min) { /*Special mode when zero crossing*/ - if((ext->value - ext->step) < 0 && ext->value > 0) ext->value = -ext->value; - ext->value -= ext->step; + if((spinbox->value - spinbox->step) < 0 && spinbox->value > 0) spinbox->value = -spinbox->value; + spinbox->value -= spinbox->step; } else { - // Rollover? - if((ext->rollover) && (ext->value == ext->range_min)) - ext->value = ext->range_max; + /*Rollover?*/ + if((spinbox->rollover) && (spinbox->value == spinbox->range_min)) + spinbox->value = spinbox->range_max; else - ext->value = ext->range_min; + spinbox->value = spinbox->range_min; } - lv_spinbox_updatevalue(spinbox); + lv_spinbox_updatevalue(obj); } /********************** * STATIC FUNCTIONS **********************/ -/** - * Signal function of the spinbox - * @param spinbox pointer to a spinbox object - * @param sign a signal type from lv_signal_t enum - * @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_spinbox_signal(lv_obj_t * spinbox, lv_signal_t sign, void * param) +static void lv_spinbox_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + LV_LOG_TRACE("spinbox create started"); + + lv_obj_construct_base(obj, parent, copy); + + + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; + + /*Initialize the allocated 'ext'*/ + spinbox->value = 0; + spinbox->dec_point_pos = 0; + spinbox->digit_count = 5; + spinbox->step = 1; + spinbox->range_max = 99999; + spinbox->range_min = -99999; + spinbox->rollover = false; + + lv_textarea_set_one_line(obj, true); + lv_textarea_set_cursor_click_pos(obj, true); + lv_obj_set_width(obj, LV_DPI_DEF); + + lv_spinbox_updatevalue(obj); + + LV_LOG_INFO("spinbox created"); +} + +static void lv_spinbox_destructor(lv_obj_t * obj) +{ + +} + +static lv_res_t lv_spinbox_signal(lv_obj_t * obj, lv_signal_t sign, void * param) { /* Include the ancient signal function */ lv_res_t res = LV_RES_OK; - res = ancestor_signal(spinbox, sign, param); + res = lv_obj_signal_base(MY_CLASS, obj, sign, param); if(res != LV_RES_OK) return res; + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; if(sign == LV_SIGNAL_RELEASED) { /*If released with an ENCODER then move to the next digit*/ - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); lv_indev_t * indev = lv_indev_get_act(); if(lv_indev_get_type(indev) == LV_INDEV_TYPE_ENCODER) { -#if LV_USE_GROUP - if(lv_group_get_editing(lv_obj_get_group(spinbox))) { - if(ext->step > 1) { - lv_spinbox_step_next(spinbox); + if(lv_group_get_editing(lv_obj_get_group(obj))) { + if(spinbox->step > 1) { + lv_spinbox_step_next(obj); } else { /*Restart from the MSB*/ - ext->step = 1; + spinbox->step = 1; uint32_t i; - for(i = 0; i < ext->digit_count; i++) { - int32_t new_step = ext->step * 10; - if(new_step >= ext->range_max) break; - ext->step = new_step; + for(i = 0; i < spinbox->digit_count; i++) { + int32_t new_step = spinbox->step * 10; + if(new_step >= spinbox->range_max) break; + spinbox->step = new_step; } lv_spinbox_step_prev(spinbox); } } -#endif } /*The cursor has been positioned to a digit. * Set `step` accordingly*/ else { - const char * txt = lv_textarea_get_text(spinbox); + const char * txt = lv_textarea_get_text(obj); size_t txt_len = strlen(txt); - if(txt[ext->ta.cursor.pos] == '.') { - lv_textarea_cursor_left(spinbox); + if(txt[spinbox->ta.cursor.pos] == '.') { + lv_textarea_cursor_left(obj); } - else if(ext->ta.cursor.pos == (uint32_t)txt_len) { - lv_textarea_set_cursor_pos(spinbox, txt_len - 1); + else if(spinbox->ta.cursor.pos == (uint32_t)txt_len) { + lv_textarea_set_cursor_pos(obj, txt_len - 1); } - else if(ext->ta.cursor.pos == 0 && ext->range_min < 0) { - lv_textarea_set_cursor_pos(spinbox, 1); + else if(spinbox->ta.cursor.pos == 0 && spinbox->range_min < 0) { + lv_textarea_set_cursor_pos(obj, 1); } - size_t len = ext->digit_count - 1; - uint16_t cp = ext->ta.cursor.pos; + size_t len = spinbox->digit_count - 1; + uint16_t cp = spinbox->ta.cursor.pos; - if(ext->ta.cursor.pos > ext->dec_point_pos && ext->dec_point_pos != 0) cp--; + if(spinbox->ta.cursor.pos > spinbox->dec_point_pos && spinbox->dec_point_pos != 0) cp--; uint32_t pos = len - cp; - if(ext->range_min < 0) pos++; + if(spinbox->range_min < 0) pos++; - ext->step = 1; + spinbox->step = 1; uint16_t i; - for(i = 0; i < pos; i++) ext->step *= 10; + for(i = 0; i < pos; i++) spinbox->step *= 10; } } else if(sign == LV_SIGNAL_CONTROL) { -#if LV_USE_GROUP lv_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act()); uint32_t c = *((uint32_t *)param); /*uint32_t because can be UTF-8*/ if(c == LV_KEY_RIGHT) { if(indev_type == LV_INDEV_TYPE_ENCODER) - lv_spinbox_increment(spinbox); + lv_spinbox_increment(obj); else - lv_spinbox_step_next(spinbox); + lv_spinbox_step_next(obj); } else if(c == LV_KEY_LEFT) { if(indev_type == LV_INDEV_TYPE_ENCODER) lv_spinbox_decrement(spinbox); else - lv_spinbox_step_prev(spinbox); + lv_spinbox_step_prev(obj); } else if(c == LV_KEY_UP) { - lv_spinbox_increment(spinbox); + lv_spinbox_increment(obj); } else if(c == LV_KEY_DOWN) { - lv_spinbox_decrement(spinbox); + lv_spinbox_decrement(obj); } else { - lv_textarea_add_char(spinbox, c); + lv_textarea_add_char(obj, c); } -#endif } return res; } -static void lv_spinbox_updatevalue(lv_obj_t * spinbox) +static void lv_spinbox_updatevalue(lv_obj_t * obj) { - lv_spinbox_ext_t * ext = lv_obj_get_ext_attr(spinbox); + lv_spinbox_t * spinbox = (lv_spinbox_t *) obj; char buf[LV_SPINBOX_MAX_DIGIT_COUNT + 8]; lv_memset_00(buf, sizeof(buf)); char * buf_p = buf; uint8_t cur_shift_left = 0; - if(ext->range_min < 0) { // hide sign if there are only positive values + if(spinbox->range_min < 0) { // hide sign if there are only positive values /*Add the sign*/ - (*buf_p) = ext->value >= 0 ? '+' : '-'; + (*buf_p) = spinbox->value >= 0 ? '+' : '-'; buf_p++; } else { @@ -419,10 +407,10 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) int32_t i; char digits[LV_SPINBOX_MAX_DIGIT_COUNT + 4]; /*Convert the numbers to string (the sign is already handled so always covert positive number)*/ - lv_snprintf(digits, sizeof(digits), "%d", LV_ABS(ext->value)); + lv_snprintf(digits, sizeof(digits), "%d", LV_ABS(spinbox->value)); /*Add leading zeros*/ - int lz_cnt = ext->digit_count - (int)strlen(digits); + int lz_cnt = spinbox->digit_count - (int)strlen(digits); if(lz_cnt > 0) { for(i = (uint16_t)strlen(digits); i >= 0; i--) { digits[i + lz_cnt] = digits[i]; @@ -433,7 +421,7 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) } int32_t intDigits; - intDigits = (ext->dec_point_pos == 0) ? ext->digit_count : ext->dec_point_pos; + intDigits = (spinbox->dec_point_pos == 0) ? spinbox->digit_count : spinbox->dec_point_pos; /*Add the decimal part*/ for(i = 0; i < intDigits && digits[i] != '\0'; i++) { @@ -441,23 +429,23 @@ static void lv_spinbox_updatevalue(lv_obj_t * spinbox) buf_p++; } - if(ext->dec_point_pos != 0) { + if(spinbox->dec_point_pos != 0) { /*Insert the decimal point*/ (*buf_p) = '.'; buf_p++; - for(/*Leave i*/; i < ext->digit_count && digits[i] != '\0'; i++) { + for(/*Leave i*/; i < spinbox->digit_count && digits[i] != '\0'; i++) { (*buf_p) = digits[i]; buf_p++; } } /*Refresh the text*/ - lv_textarea_set_text(spinbox, (char *)buf); + lv_textarea_set_text(obj, (char *)buf); /*Set the cursor position*/ - int32_t step = ext->step; - uint8_t cur_pos = (uint8_t)ext->digit_count; + int32_t step = spinbox->step; + uint8_t cur_pos = (uint8_t)spinbox->digit_count; while(step >= 10) { step /= 10; cur_pos--; diff --git a/src/extra/widgets/spinbox/lv_spinbox.h b/src/extra/widgets/spinbox/lv_spinbox.h index 6d4a6d8bc..0aa710c48 100644 --- a/src/extra/widgets/spinbox/lv_spinbox.h +++ b/src/extra/widgets/spinbox/lv_spinbox.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../../lv_core/lv_obj.h" +#include "../../../lvgl.h" #if LV_USE_SPINBOX @@ -33,7 +33,7 @@ extern "C" { /*Data of spinbox*/ typedef struct { - lv_textarea_ext_t ta; /*Ext. of ancestor*/ + lv_textarea_t ta; /*Ext. of ancestor*/ /*New data for this type */ int32_t value; int32_t range_max; @@ -42,14 +42,9 @@ typedef struct { uint16_t digit_count : 4; uint16_t dec_point_pos : 4; /*if 0, there is no separator and the number is an integer*/ uint16_t rollover : 1; // Set to true for rollover functionality -} lv_spinbox_ext_t; +} lv_spinbox_t; -enum { - LV_SPINBOX_PART_MAIN = LV_TEXTAREA_PART_MAIN, - LV_SPINBOX_PART_CURSOR = LV_TEXTAREA_PART_CURSOR, - _LV_SPINBOX_PART_VIRTUAL_LAST = _LV_TEXTAREA_PART_VIRTUAL_LAST, -}; -typedef uint8_t lv_spinbox_part_t; +extern const lv_obj_class_t lv_spinbox; /********************** * GLOBAL PROTOTYPES @@ -72,14 +67,14 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * parent); * @param spinbox pointer to spinbox * @param b true or false to enable or disable (default) */ -void lv_spinbox_set_rollover(lv_obj_t * spinbox, bool b); +void lv_spinbox_set_rollover(lv_obj_t * obj, bool b); /** * Set spinbox value * @param spinbox pointer to spinbox * @param i value to be set */ -void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i); +void lv_spinbox_set_value(lv_obj_t * obj, int32_t i); /** * Set spinbox digit format (digit count and decimal format) @@ -88,14 +83,14 @@ void lv_spinbox_set_value(lv_obj_t * spinbox, int32_t i); * @param separator_position number of digit before the decimal point. If 0, decimal point is not * shown */ -void lv_spinbox_set_digit_format(lv_obj_t * spinbox, uint8_t digit_count, uint8_t separator_position); +void lv_spinbox_set_digit_format(lv_obj_t * obj, uint8_t digit_count, uint8_t separator_position); /** * Set spinbox step * @param spinbox pointer to spinbox * @param step steps on increment/decrement */ -void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step); +void lv_spinbox_set_step(lv_obj_t * obj, uint32_t step); /** * Set spinbox value range @@ -103,14 +98,14 @@ void lv_spinbox_set_step(lv_obj_t * spinbox, uint32_t step); * @param range_min maximum value, inclusive * @param range_max minimum value, inclusive */ -void lv_spinbox_set_range(lv_obj_t * spinbox, int32_t range_min, int32_t range_max); +void lv_spinbox_set_range(lv_obj_t * obj, int32_t range_min, int32_t range_max); /** * Set spinbox left padding in digits count (added between sign and first digit) * @param spinbox pointer to spinbox * @param cb Callback function called on value change event */ -void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding); +void lv_spinbox_set_padding_left(lv_obj_t * obj, uint8_t padding); /*===================== * Getter functions @@ -120,14 +115,14 @@ void lv_spinbox_set_padding_left(lv_obj_t * spinbox, uint8_t padding); * Get spinbox rollover function status * @param spinbox pointer to spinbox */ -bool lv_spinbox_get_rollover(lv_obj_t * spinbox); +bool lv_spinbox_get_rollover(lv_obj_t * obj); /** * Get the spinbox numeral value (user has to convert to float according to its digit format) * @param spinbox pointer to spinbox * @return value integer value of the spinbox */ -int32_t lv_spinbox_get_value(lv_obj_t * spinbox); +int32_t lv_spinbox_get_value(lv_obj_t * obj); /*===================== * Other functions @@ -137,25 +132,25 @@ int32_t lv_spinbox_get_value(lv_obj_t * spinbox); * Select next lower digit for edition by dividing the step by 10 * @param spinbox pointer to spinbox */ -void lv_spinbox_step_next(lv_obj_t * spinbox); +void lv_spinbox_step_next(lv_obj_t * obj); /** * Select next higher digit for edition by multiplying the step by 10 * @param spinbox pointer to spinbox */ -void lv_spinbox_step_prev(lv_obj_t * spinbox); +void lv_spinbox_step_prev(lv_obj_t * obj); /** * Increment spinbox value by one step * @param spinbox pointer to spinbox */ -void lv_spinbox_increment(lv_obj_t * spinbox); +void lv_spinbox_increment(lv_obj_t * obj); /** * Decrement spinbox value by one step * @param spinbox pointer to spinbox */ -void lv_spinbox_decrement(lv_obj_t * spinbox); +void lv_spinbox_decrement(lv_obj_t * obj); /********************** * MACROS diff --git a/src/extra/widgets/spinner/lv_spinner.c b/src/extra/widgets/spinner/lv_spinner.c index 7f0a6f923..75edd5c0d 100644 --- a/src/extra/widgets/spinner/lv_spinner.c +++ b/src/extra/widgets/spinner/lv_spinner.c @@ -48,25 +48,27 @@ lv_obj_t * lv_spinner_create(lv_obj_t * par, uint32_t time, uint32_t arc_length) LV_ASSERT_MEM(spinner); if(spinner == NULL) return NULL; - lv_obj_set_size(spinner, LV_DPI, LV_DPI); + lv_obj_set_size(spinner, LV_DPI_DEF, LV_DPI_DEF); - lv_anim_path_t path; - lv_anim_path_init(&path); - lv_anim_path_set_cb(&path, lv_anim_path_ease_in_out); + lv_obj_remove_style(spinner, LV_PART_KNOB, LV_STATE_ANY, NULL); - lv_anim_t a; - lv_anim_init(&a); - lv_anim_set_var(&a, spinner); - lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_angle_anim_cb); - lv_anim_set_path(&a, &path); - lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); - lv_anim_set_time(&a, time); - lv_anim_set_values(&a, 0, 360); - lv_anim_start(&a); + lv_anim_path_t path; + lv_anim_path_init(&path); + lv_anim_path_set_cb(&path, lv_anim_path_ease_in_out); - lv_arc_set_angles(spinner, 0, arc_length); - lv_arc_set_bg_angles(spinner, 0, 360); - lv_arc_set_rotation(spinner, 270 - arc_length / 2); + lv_anim_t a; + lv_anim_init(&a); + lv_anim_set_var(&a, spinner); + lv_anim_set_exec_cb(&a, (lv_anim_exec_xcb_t)lv_spinner_angle_anim_cb); + lv_anim_set_path(&a, &path); + lv_anim_set_repeat_count(&a, LV_ANIM_REPEAT_INFINITE); + lv_anim_set_time(&a, time); + lv_anim_set_values(&a, 0, 360); + lv_anim_start(&a); + + lv_arc_set_bg_angles(spinner, 0, 360); + lv_arc_set_angles(spinner, 0, arc_length); + lv_arc_set_angle_ofs(spinner, 270 - arc_length / 2); return spinner; } diff --git a/src/extra/widgets/spinner/lv_spinner.h b/src/extra/widgets/spinner/lv_spinner.h index 11e63212a..8f465dfab 100644 --- a/src/extra/widgets/spinner/lv_spinner.h +++ b/src/extra/widgets/spinner/lv_spinner.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../../lv_core/lv_obj.h" +#include "../../../lvgl.h" #if LV_USE_SPINNER @@ -22,10 +22,6 @@ extern "C" { #error "lv_spinner: lv_arc is required. Enable it in lv_conf.h (LV_USE_ARC 1) " #endif -#if LV_USE_ANIMATION == 0 -#error "lv_spinner: animations are required. Enable it in lv_conf.h (LV_USE_ANIMATION 1) " -#endif - /********************* * DEFINES *********************/ diff --git a/src/extra/widgets/tabview/lv_tabview.c b/src/extra/widgets/tabview/lv_tabview.c index 64f5c99c3..3b83c4607 100644 --- a/src/extra/widgets/tabview/lv_tabview.c +++ b/src/extra/widgets/tabview/lv_tabview.c @@ -16,22 +16,24 @@ /********************** * TYPEDEFS **********************/ -typedef struct { - uint16_t tab_cnt; - uint16_t tab_cur; -}lv_tabview_ext_t; /********************** * STATIC PROTOTYPES **********************/ +static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy); static void btns_event_cb(lv_obj_t * btns, lv_event_t e); static void cont_event_cb(lv_obj_t * cont, lv_event_t e); /********************** * STATIC VARIABLES **********************/ -static bool inited; -static lv_style_t style_bg; +const lv_obj_class_t lv_tabview = { + .constructor_cb = lv_tabview_constructor, + .base_class = &lv_obj, + .instance_size = sizeof(lv_tabview_t)}; + +static lv_dir_t tabpos_create; +static lv_coord_t tabsize_create; /********************** * MACROS @@ -43,174 +45,166 @@ static lv_style_t style_bg; lv_obj_t * lv_tabview_create(lv_obj_t * parent, lv_dir_t tab_pos, lv_coord_t tab_size) { - if(!inited) { - lv_style_init(&style_bg); - lv_style_set_radius(&style_bg, LV_STATE_DEFAULT, 0); - - inited = true; - } - - lv_obj_t * tabview = lv_obj_create(parent, NULL); - lv_tabview_ext_t * ext = lv_obj_allocate_ext_attr(tabview, sizeof(lv_tabview_ext_t)); - - lv_memset_00(ext, sizeof(lv_tabview_ext_t)); - lv_flex_dir_t flex_dir; - switch(tab_pos) { - case LV_DIR_TOP: - flex_dir = LV_FLEX_DIR_COLUMN; - break; - case LV_DIR_BOTTOM: - flex_dir = LV_FLEX_DIR_COLUMN_REVERSE; - break; - case LV_DIR_LEFT: - flex_dir = LV_FLEX_DIR_ROW; - break; - case LV_DIR_RIGHT: - flex_dir = LV_FLEX_DIR_ROW_REVERSE; - break; - } - - lv_obj_reset_style_list(tabview, LV_OBJ_PART_MAIN); - - lv_obj_set_size(tabview, LV_COORD_PCT(100), LV_COORD_PCT(100)); - lv_obj_set_flex_dir(tabview, flex_dir); - - lv_obj_t * btnm; - lv_obj_t * cont; - - - btnm = lv_btnmatrix_create(tabview, NULL); - cont = lv_obj_create(tabview, NULL); - - lv_btnmatrix_set_one_checked(btnm, true); - const char ** map = lv_mem_alloc(sizeof(const char *)); - map[0] = ""; - lv_btnmatrix_set_map(btnm, map); - lv_obj_add_style(btnm, LV_BTNMATRIX_PART_MAIN, &style_bg); - lv_obj_set_event_cb(btnm, btns_event_cb); - lv_obj_add_flag(btnm, LV_OBJ_FLAG_EVENT_BUBBLE); - - lv_obj_set_event_cb(cont, cont_event_cb); - lv_obj_reset_style_list(cont, LV_OBJ_PART_MAIN); - lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF); - - lv_obj_set_flex_item(btnm, LV_FLEX_PLACE_START); - lv_obj_set_flex_item(cont, LV_FLEX_PLACE_START); - - switch(tab_pos) { - case LV_DIR_TOP: - case LV_DIR_LEFT: - lv_obj_set_size(btnm, LV_COORD_PCT(100), tab_size); - lv_obj_set_size(cont, LV_COORD_PCT(100), LV_FLEX_GROW(1)); - break; - case LV_DIR_BOTTOM: - case LV_DIR_RIGHT: - lv_obj_set_size(btnm, LV_COORD_PCT(100), tab_size); - lv_obj_set_size(cont, LV_FLEX_GROW(1), LV_COORD_PCT(100)); - break; - } - - lv_obj_set_flex_dir(cont, LV_FLEX_DIR_ROW); - lv_obj_set_snap_align_x(cont, LV_SCROLL_SNAP_ALIGN_CENTER); - lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_STOP); - lv_obj_clear_flag(cont, LV_OBJ_FLAG_FOCUS_SCROLL); - - return tabview; + tabpos_create = tab_pos; + tabsize_create = tab_size; + return lv_obj_create_from_class(&lv_tabview, parent, NULL); } -lv_obj_t * lv_tabview_add_tab(lv_obj_t * tv, const char * name) +lv_obj_t * lv_tabview_add_tab(lv_obj_t * obj, const char * name) { - lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv); - lv_obj_t * cont = lv_tabview_get_content(tv); + lv_tabview_t * tabview = (lv_tabview_t *) obj; + lv_obj_t * cont = lv_tabview_get_content(obj); lv_obj_t * page = lv_obj_create(cont, NULL); lv_obj_clear_flag(page, LV_OBJ_FLAG_CLICK_FOCUSABLE); - lv_obj_add_style(page, LV_BTNMATRIX_PART_MAIN, &style_bg); - uint32_t tab_id = lv_obj_count_children(cont); + uint32_t tab_id = lv_obj_get_child_cnt(cont); - lv_obj_set_flex_item(page, true); lv_obj_set_size(page, LV_COORD_PCT(100), LV_COORD_PCT(100)); - lv_obj_t * btns = lv_tabview_get_tab_btns(tv); + lv_obj_t * btns = lv_tabview_get_tab_btns(obj); - const char ** old_map = lv_btnmatrix_get_map_array(btns); + const char ** old_map = lv_btnmatrix_get_map(btns); const char ** new_map; /*top or bottom dir*/ - if(lv_obj_get_flex_dir(tv) == LV_FLEX_DIR_COLUMN) { +// if(lv_obj_get_flex_dir(tv) == LV_FLEX_DIR_COLUMN) { new_map = lv_mem_alloc((tab_id + 1) * sizeof(const char *)); lv_memcpy_small(new_map, old_map, sizeof(const char *) * (tab_id - 1)); new_map[tab_id - 1] = lv_mem_alloc(strlen(name) + 1); strcpy((char *)new_map[tab_id - 1], name); new_map[tab_id] = ""; - } - /*left or right dir*/ - else { - new_map = lv_mem_alloc((tab_id * 2) * sizeof(const char *)); - lv_memcpy_small(new_map, old_map, sizeof(const char *) * tab_id * 2); - if(ext->tab_cnt == 0) { - new_map[0] = lv_mem_alloc(strlen(name) + 1); - strcpy((char *)new_map[0], name); - new_map[1] = ""; - } else { - new_map[tab_id * 2 - 3] = "\n"; - new_map[tab_id * 2 - 2] = lv_mem_alloc(strlen(name) + 1); - new_map[tab_id * 2 - 1] = ""; - strcpy((char *)new_map[(tab_id * 2) - 2], name); - } - } +// } +// /*left or right dir*/ +// else { +// new_map = lv_mem_alloc((tab_id * 2) * sizeof(const char *)); +// lv_memcpy_small(new_map, old_map, sizeof(const char *) * tab_id * 2); +// if(ext->tab_cnt == 0) { +// new_map[0] = lv_mem_alloc(strlen(name) + 1); +// strcpy((char *)new_map[0], name); +// new_map[1] = ""; +// } else { +// new_map[tab_id * 2 - 3] = "\n"; +// new_map[tab_id * 2 - 2] = lv_mem_alloc(strlen(name) + 1); +// new_map[tab_id * 2 - 1] = ""; +// strcpy((char *)new_map[(tab_id * 2) - 2], name); +// } +// } lv_btnmatrix_set_map(btns, new_map); lv_mem_free(old_map); lv_btnmatrix_set_btn_ctrl_all(btns, LV_BTNMATRIX_CTRL_CHECKABLE | LV_BTNMATRIX_CTRL_CLICK_TRIG | LV_BTNMATRIX_CTRL_NO_REPEAT); - ext->tab_cnt++; - if(ext->tab_cnt == 1) { - lv_tabview_set_act(tv, 0); + tabview->tab_cnt++; + if(tabview->tab_cnt == 1) { + lv_tabview_set_act(obj, 0); } - lv_btnmatrix_set_btn_ctrl(btns, ext->tab_cur, LV_BTNMATRIX_CTRL_CHECKED); + lv_btnmatrix_set_btn_ctrl(btns, tabview->tab_cur, LV_BTNMATRIX_CTRL_CHECKED); return page; } -void lv_tabview_set_act(lv_obj_t * tv, uint32_t id) +void lv_tabview_set_act(lv_obj_t * obj, uint32_t id) { - lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv); - if(id >= ext->tab_cnt) { - id = ext->tab_cnt - 1; + lv_tabview_t * tabview = (lv_tabview_t *) obj; + + if(id >= tabview->tab_cnt) { + id = tabview->tab_cnt - 1; } - lv_obj_t * cont = lv_tabview_get_content(tv); - lv_obj_t * tab = lv_obj_get_child(cont, NULL); - lv_obj_scroll_to_x(cont, id * lv_obj_get_width(tab), LV_ANIM_ON); + lv_obj_t * cont = lv_tabview_get_content(obj); + lv_obj_t * tab = lv_obj_get_child(cont, 0); + lv_coord_t gap = lv_obj_get_style_pad_column(cont, LV_PART_MAIN); + lv_obj_scroll_to_x(cont, id * (gap + lv_obj_get_width(tab)), LV_ANIM_ON); - lv_obj_t * btns = lv_tabview_get_tab_btns(tv); + lv_obj_t * btns = lv_tabview_get_tab_btns(obj); lv_btnmatrix_set_btn_ctrl(btns, id, LV_BTNMATRIX_CTRL_CHECKED); - ext->tab_cur = id; + tabview->tab_cur = id; } -uint16_t lv_tabview_get_tab_act(lv_obj_t * tv) +uint16_t lv_tabview_get_tab_act(lv_obj_t * obj) { - lv_tabview_ext_t * ext = lv_obj_get_ext_attr(tv); - return ext->tab_cur; - + lv_tabview_t * tabview = (lv_tabview_t *) obj; + return tabview->tab_cur; } lv_obj_t * lv_tabview_get_content(lv_obj_t * tv) { - return lv_obj_get_child(tv, NULL); + return lv_obj_get_child(tv, 1); } lv_obj_t * lv_tabview_get_tab_btns(lv_obj_t * tv) { - return lv_obj_get_child_back(tv, NULL); + return lv_obj_get_child(tv, 0); } /********************** * STATIC FUNCTIONS **********************/ + +static void lv_tabview_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t * copy) +{ + lv_obj_construct_base(obj, parent, copy); + lv_tabview_t * tabview = (lv_tabview_t *) obj; + +// lv_flex_flow_t flex_dir; +// switch(tab_pos) { +// case LV_DIR_TOP: +// flex_dir = LV_FLEX_DIR_COLUMN; +// break; +// case LV_DIR_BOTTOM: +// flex_dir = LV_FLEX_DIR_COLUMN_REVERSE; +// break; +// case LV_DIR_LEFT: +// flex_dir = LV_FLEX_DIR_ROW; +// break; +// case LV_DIR_RIGHT: +// flex_dir = LV_FLEX_DIR_ROW_REVERSE; +// break; +// } + + lv_obj_set_size(obj, LV_COORD_PCT(100), LV_COORD_PCT(100)); + lv_obj_set_layout(obj, &lv_flex_stacked); + + lv_obj_t * btnm; + lv_obj_t * cont; + + + btnm = lv_btnmatrix_create(obj, NULL); + cont = lv_obj_create(obj, NULL); + + lv_btnmatrix_set_one_checked(btnm, true); + const char ** map = lv_mem_alloc(sizeof(const char *)); + map[0] = ""; + lv_btnmatrix_set_map(btnm, map); + lv_obj_add_event_cb(btnm, btns_event_cb, NULL); + lv_obj_add_flag(btnm, LV_OBJ_FLAG_EVENT_BUBBLE); + + lv_obj_add_event_cb(cont, cont_event_cb, NULL); + lv_obj_set_scrollbar_mode(cont, LV_SCROLLBAR_MODE_OFF); + + switch(tabpos_create) { + case LV_DIR_TOP: + case LV_DIR_LEFT: + lv_obj_set_size(btnm, LV_COORD_PCT(100), tabsize_create); + lv_obj_set_width(cont, LV_COORD_PCT(100)); + lv_obj_set_flex_grow(cont, 1); + break; + case LV_DIR_BOTTOM: + case LV_DIR_RIGHT: + lv_obj_set_size(btnm, LV_COORD_PCT(100), tabsize_create); + lv_obj_set_height(cont, LV_COORD_PCT(100)); + lv_obj_set_flex_grow(cont, 1); + break; + } + + lv_obj_set_layout(cont, &lv_flex_queue); + lv_obj_set_snap_align_x(cont, LV_SCROLL_SNAP_ALIGN_CENTER); + lv_obj_add_flag(cont, LV_OBJ_FLAG_SCROLL_ONE); + lv_obj_clear_flag(cont, LV_OBJ_FLAG_SCROLL_ON_FOCUS); +} + static void btns_event_cb(lv_obj_t * btns, lv_event_t e) { if(e == LV_EVENT_VALUE_CHANGED) { diff --git a/src/extra/widgets/tabview/lv_tabview.h b/src/extra/widgets/tabview/lv_tabview.h index 48aa5ed7e..f99d41cfb 100644 --- a/src/extra/widgets/tabview/lv_tabview.h +++ b/src/extra/widgets/tabview/lv_tabview.h @@ -13,7 +13,7 @@ extern "C" { /********************* * INCLUDES *********************/ -#include "../../../lv_core/lv_obj.h" +#include "../../../lvgl.h" #if LV_USE_TABVIEW @@ -25,6 +25,13 @@ extern "C" { * TYPEDEFS **********************/ +typedef struct +{ + lv_obj_t obj; + uint16_t tab_cnt; + uint16_t tab_cur; +}lv_tabview_t; + /********************** * GLOBAL PROTOTYPES **********************/ diff --git a/src/lv_core/lv_obj_draw.c b/src/lv_core/lv_obj_draw.c index ba2dcf41a..de5f15fd4 100644 --- a/src/lv_core/lv_obj_draw.c +++ b/src/lv_core/lv_obj_draw.c @@ -174,8 +174,8 @@ void lv_obj_init_draw_rect_dsc(lv_obj_t * obj, uint8_t part, lv_draw_rect_dsc_t } if(draw_dsc->bg_img_opa != LV_OPA_TRANSP) { - draw_dsc->bg_img_src = lv_obj_get_style_bg_img_src(obj, part); - if(draw_dsc->bg_img_src) { + draw_dsc->img_src = lv_obj_get_style_bg_img_src(obj, part); + if(draw_dsc->img_src) { draw_dsc->bg_img_opa = lv_obj_get_style_bg_img_opa(obj, part); if(draw_dsc->bg_img_opa > LV_OPA_MIN) { draw_dsc->bg_img_tiled = lv_obj_get_style_bg_img_tiled(obj, part); @@ -201,13 +201,11 @@ void lv_obj_init_draw_label_dsc(lv_obj_t * obj, uint8_t part, lv_draw_label_dsc_ draw_dsc->opa = lv_obj_get_style_text_opa(obj, part); if(draw_dsc->opa <= LV_OPA_MIN) return; -#if LV_USE_OPA_SCALE lv_opa_t opa = lv_obj_get_style_opa(obj, part); if(opa < LV_OPA_MAX) { draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8; } if(draw_dsc->opa <= LV_OPA_MIN) return; -#endif draw_dsc->color = lv_obj_get_style_text_color_filtered(obj, part); draw_dsc->letter_space = lv_obj_get_style_text_letter_space(obj, part); @@ -235,13 +233,11 @@ void lv_obj_init_draw_img_dsc(lv_obj_t * obj, uint8_t part, lv_draw_img_dsc_t * draw_dsc->opa = lv_obj_get_style_img_opa(obj, part); if(draw_dsc->opa <= LV_OPA_MIN) return; -#if LV_USE_OPA_SCALE lv_opa_t opa_scale = lv_obj_get_style_opa(obj, part); if(opa_scale < LV_OPA_MAX) { draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa_scale) >> 8; } if(draw_dsc->opa <= LV_OPA_MIN) return; -#endif draw_dsc->angle = 0; draw_dsc->zoom = LV_IMG_ZOOM_NONE; @@ -265,13 +261,11 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t draw_dsc->opa = lv_obj_get_style_line_opa(obj, part); if(draw_dsc->opa <= LV_OPA_MIN) return; -#if LV_USE_OPA_SCALE lv_opa_t opa = lv_obj_get_style_opa(obj, part); if(opa < LV_OPA_MAX) { draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8; } if(draw_dsc->opa <= LV_OPA_MIN) return; -#endif draw_dsc->color = lv_obj_get_style_line_color(obj, part); @@ -290,22 +284,20 @@ void lv_obj_init_draw_line_dsc(lv_obj_t * obj, uint8_t part, lv_draw_line_dsc_t void lv_obj_init_draw_arc_dsc(lv_obj_t * obj, uint8_t part, lv_draw_arc_dsc_t * draw_dsc) { - draw_dsc->width = lv_obj_get_style_line_width(obj, part); + draw_dsc->width = lv_obj_get_style_arc_width(obj, part); if(draw_dsc->width == 0) return; - draw_dsc->opa = lv_obj_get_style_line_opa(obj, part); + draw_dsc->opa = lv_obj_get_style_arc_opa(obj, part); if(draw_dsc->opa <= LV_OPA_MIN) return; -#if LV_USE_OPA_SCALE lv_opa_t opa = lv_obj_get_style_opa(obj, part); if(opa < LV_OPA_MAX) { draw_dsc->opa = (uint16_t)((uint16_t)draw_dsc->opa * opa) >> 8; } if(draw_dsc->opa <= LV_OPA_MIN) return; -#endif - draw_dsc->color = lv_obj_get_style_line_color(obj, part); - draw_dsc->bg_img_src = lv_obj_get_style_bg_img_src(obj, part); + draw_dsc->color = lv_obj_get_style_arc_color(obj, part); + draw_dsc->img_src = lv_obj_get_style_arc_img_src(obj, part); draw_dsc->rounded = lv_obj_get_style_line_rounded(obj, part); diff --git a/src/lv_core/lv_obj_pos.c b/src/lv_core/lv_obj_pos.c index e9289ed28..dbebe870a 100644 --- a/src/lv_core/lv_obj_pos.c +++ b/src/lv_core/lv_obj_pos.c @@ -95,13 +95,17 @@ void lv_obj_set_size(lv_obj_t * obj, lv_coord_t w, lv_coord_t h) /*If the width or height is set by a layout do not modify them*/ if(obj->w_set == LV_SIZE_LAYOUT && obj->h_set == LV_SIZE_LAYOUT) return; - if(obj->w_set == LV_SIZE_LAYOUT) w = lv_obj_get_width(obj); if(obj->h_set == LV_SIZE_LAYOUT) h = lv_obj_get_height(obj); obj->w_set = w; obj->h_set = h; + /* If the width or height is set to special layout related value save them in w_set and h_set + * but use the current size on the object width*/ + if(LV_COORD_IS_LAYOUT(w)) w = lv_obj_get_width(obj); + if(LV_COORD_IS_LAYOUT(h)) h = lv_obj_get_height(obj); + /*Calculate the required auto sizes*/ bool x_auto = obj->w_set == LV_SIZE_AUTO ? true : false; bool y_auto = obj->h_set == LV_SIZE_AUTO ? true : false; diff --git a/src/lv_core/lv_obj_pos.h b/src/lv_core/lv_obj_pos.h index 32d8e4979..d1578dd56 100644 --- a/src/lv_core/lv_obj_pos.h +++ b/src/lv_core/lv_obj_pos.h @@ -64,22 +64,37 @@ void lv_obj_set_y(struct _lv_obj_t * obj, lv_coord_t y); /** * Set the size of an object. * @param obj: pointer to an object - * @param w: new width in pixels or `LV_SIZE_AUTO` to set the size to involve all children - * @param h: new height in pixels or `LV_SIZE_AUTO` to set the size to involve all children + * @param w: the new width + * @param h: the new height + * @note possible values are: + * pixel: simple set the size accordingly + * LV_SIZE_AUTO: to set the size to involve all children in the given direction + * LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings). + * x should be [0..1000] range */ void lv_obj_set_size(struct _lv_obj_t * obj, lv_coord_t w, lv_coord_t h); /** * Set the width of an object * @param obj: pointer to an object - * @param w: new width in pixels or `LV_SIZE_AUTO` to set the size to involve all children + * @param w: the new width + * @note possible values are: + * pixel: simple set the size accordingly + * LV_SIZE_AUTO: to set the size to involve all children in the given direction + * LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings). + * x should be [0..1000] range */ void lv_obj_set_width(struct _lv_obj_t * obj, lv_coord_t w); /** * Set the height of an object * @param obj: pointer to an object - * @param h: new height in pixels or `LV_SIZE_AUTO` to set the size to involve all children + * @param h: the new height + * @note possible values are: + * pixel: simple set the size accordingly + * LV_SIZE_AUTO: to set the size to involve all children in the given direction + * LV_COORD_PCT(x): to set size to a percentage of the parent's content area size (the size without paddings). + * x should be [0..1000] range */ void lv_obj_set_height(struct _lv_obj_t * obj, lv_coord_t h); diff --git a/src/lv_core/lv_obj_style.h b/src/lv_core/lv_obj_style.h index 522804aaa..ed33fadcc 100644 --- a/src/lv_core/lv_obj_style.h +++ b/src/lv_core/lv_obj_style.h @@ -369,6 +369,24 @@ static inline lv_color_t lv_obj_get_style_line_color_filtered(const struct _lv_o static inline lv_opa_t lv_obj_get_style_line_opa(const struct _lv_obj_t * obj, uint32_t part) { lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_LINE_OPA); return (lv_opa_t) v.num; } +static inline lv_coord_t lv_obj_get_style_arc_width(const struct _lv_obj_t * obj, uint32_t part) { + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_WIDTH); return (lv_coord_t) v.num; } + +static inline lv_coord_t lv_obj_get_style_arc_rounded(const struct _lv_obj_t * obj, uint32_t part) { + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_ROUNDED); return (lv_coord_t) v.num; } + +static inline lv_color_t lv_obj_get_style_arc_color(const struct _lv_obj_t * obj, uint32_t part) { + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR); return (lv_color_t) v.color; } + +static inline lv_color_t lv_obj_get_style_arc_color_filtered(const struct _lv_obj_t * obj, uint32_t part) { + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_COLOR_FILTERED); return (lv_color_t) v.color; } + +static inline lv_opa_t lv_obj_get_style_arc_opa(const struct _lv_obj_t * obj, uint32_t part) { + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_OPA); return (lv_opa_t) v.num; } + +static inline const void * lv_obj_get_style_arc_img_src(const struct _lv_obj_t * obj, uint32_t part) { + lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_ARC_IMG_SRC); return (const void *) v.ptr; } + static inline const char * lv_obj_get_style_content_text(const struct _lv_obj_t * obj, uint32_t part) { lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_TEXT); return (const char *) v.ptr; } @@ -403,9 +421,10 @@ static inline lv_text_decor_t lv_obj_get_style_content_decor(const struct _lv_ob lv_style_value_t v = lv_obj_get_style_prop(obj, part, LV_STYLE_CONTENT_DECOR); return (lv_text_decor_t) v.num; } -/*===================== - * Local style set - *====================*/ +/********************* + * LOCAL STYLE SET + *********************/ + static inline void lv_obj_set_style_radius(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) { lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_RADIUS, v); } @@ -616,6 +635,24 @@ static inline void lv_obj_set_style_line_color_filtered(struct _lv_obj_t * obj, static inline void lv_obj_set_style_line_opa(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_opa_t value) { lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_LINE_OPA, v); } +static inline void lv_obj_set_style_arc_width(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) { + lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_WIDTH, v); } + +static inline void lv_obj_set_style_arc_rounded(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_coord_t value) { + lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_ROUNDED, v); } + +static inline void lv_obj_set_style_arc_color(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value) { + lv_style_value_t v = {.color = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_COLOR, v); } + +static inline void lv_obj_set_style_arc_color_filtered(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_color_t value) { + lv_style_value_t v = {.color = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_COLOR_FILTERED, v); } + +static inline void lv_obj_set_style_arc_opa(struct _lv_obj_t * obj, uint32_t part, uint32_t state, lv_opa_t value) { + lv_style_value_t v = {.num = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_OPA, v); } + +static inline void lv_obj_set_style_arc_img_src(struct _lv_obj_t * obj, uint32_t part, uint32_t state, const void * value) { + lv_style_value_t v = {.ptr = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_ARC_IMG_SRC, v); } + static inline void lv_obj_set_style_content_text(struct _lv_obj_t * obj, uint32_t part, uint32_t state, const char * value) { lv_style_value_t v = {.ptr = value}; lv_obj_set_local_style_prop(obj, part, state, LV_STYLE_CONTENT_TEXT, v); } diff --git a/src/lv_draw/lv_draw_arc.c b/src/lv_draw/lv_draw_arc.c index 8ad1b8cf8..40c3e598a 100644 --- a/src/lv_draw/lv_draw_arc.c +++ b/src/lv_draw/lv_draw_arc.c @@ -91,9 +91,9 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin lv_draw_rect_dsc_t cir_dsc; lv_draw_rect_dsc_init(&cir_dsc); cir_dsc.blend_mode = dsc->blend_mode; - if(dsc->bg_img_src) { + if(dsc->img_src) { cir_dsc.bg_opa = LV_OPA_TRANSP; - cir_dsc.bg_img_src = dsc->bg_img_src; + cir_dsc.bg_img_src = dsc->img_src; cir_dsc.bg_img_opa = dsc->opa; } else { cir_dsc.bg_opa = dsc->opa; @@ -115,6 +115,11 @@ void lv_draw_arc(lv_coord_t center_x, lv_coord_t center_y, uint16_t radius, uin /*Draw a full ring*/ if(start_angle + 360 == end_angle || start_angle == end_angle + 360) { + cir_dsc.border_width = dsc->width; + cir_dsc.border_color = dsc->color; + cir_dsc.border_opa = dsc->opa; + cir_dsc.bg_opa = LV_OPA_TRANSP; + cir_dsc.radius = LV_RADIUS_CIRCLE; lv_draw_rect(&area_out, clip_area, &cir_dsc); return; } diff --git a/src/lv_draw/lv_draw_arc.h b/src/lv_draw/lv_draw_arc.h index 8055447f7..3c1dd6344 100644 --- a/src/lv_draw/lv_draw_arc.h +++ b/src/lv_draw/lv_draw_arc.h @@ -25,7 +25,7 @@ extern "C" { typedef struct { lv_color_t color; lv_coord_t width; - const void * bg_img_src; + const void * img_src; lv_opa_t opa; lv_blend_mode_t blend_mode : 2; uint8_t rounded : 1; diff --git a/src/lv_draw/lv_draw_rect.c b/src/lv_draw/lv_draw_rect.c index 6a6139250..c62f4f49f 100644 --- a/src/lv_draw/lv_draw_rect.c +++ b/src/lv_draw/lv_draw_rect.c @@ -468,12 +468,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv fill_area.y1 = disp_area->y1 + draw_area.y1; fill_area.y2 = fill_area.y1; - uint32_t buf_ofs = 0; if(dsc->border_side == LV_BORDER_SIDE_LEFT) fill_area.x2 = coords->x1 + corner_size; - else if(dsc->border_side == LV_BORDER_SIDE_RIGHT) { - fill_area.x1 = coords->x2 - corner_size; - buf_ofs = fill_area.x1 - coords->x1; - } volatile bool top_only = false; volatile bool bottom_only = false; @@ -492,7 +487,7 @@ LV_ATTRIBUTE_FAST_MEM static void draw_border(const lv_area_t * coords, const lv (bottom_only && fill_area.y1 >= coords->y2 - corner_size)) { lv_memset_ff(mask_buf, draw_area_w); mask_res = lv_draw_mask_apply(mask_buf, vdb->area.x1 + draw_area.x1, vdb->area.y1 + h, draw_area_w); - _lv_blend_fill(clip, &fill_area, color, mask_buf + buf_ofs, mask_res, opa, blend_mode); + _lv_blend_fill(clip, &fill_area, color, mask_buf, mask_res, opa, blend_mode); } fill_area.y1++; fill_area.y2++; diff --git a/src/lv_misc/lv_anim.h b/src/lv_misc/lv_anim.h index 88fb77042..575a5b564 100644 --- a/src/lv_misc/lv_anim.h +++ b/src/lv_misc/lv_anim.h @@ -411,7 +411,7 @@ extern const lv_anim_path_t lv_anim_path_def; * MACROS **********************/ -#endif /*LV_USE_ANIMATION == 0*/ +#endif /*LV_ANIM_H*/ #ifdef __cplusplus } /* extern "C" */ diff --git a/src/lv_misc/lv_style.c b/src/lv_misc/lv_style.c index 87a691398..92dec7aad 100644 --- a/src/lv_misc/lv_style.c +++ b/src/lv_misc/lv_style.c @@ -40,6 +40,12 @@ void lv_style_init(lv_style_t * style) { +#if LV_USE_ASSERT_STYLE + if(style->sentinel == LV_DEBUG_STYLE_SENTINEL_VALUE && style->allocated && style->props_and_values != 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; @@ -215,9 +221,10 @@ lv_style_value_t lv_style_prop_get_default(lv_style_prop_t prop) case LV_STYLE_TEXT_OPA: case LV_STYLE_IMG_OPA: case LV_STYLE_BG_IMG_OPA: - case LV_STYLE_LINE_OPA: case LV_STYLE_OUTLINE_OPA: case LV_STYLE_SHADOW_OPA: + case LV_STYLE_LINE_OPA: + case LV_STYLE_ARC_OPA: case LV_STYLE_CONTENT_OPA: value.num = LV_OPA_COVER; break; diff --git a/src/lv_misc/lv_style.h b/src/lv_misc/lv_style.h index 07e8aedd1..403504892 100644 --- a/src/lv_misc/lv_style.h +++ b/src/lv_misc/lv_style.h @@ -193,19 +193,26 @@ typedef enum { LV_STYLE_LINE_COLOR_FILTERED = 104 | LV_STYLE_PROP_FILTER, LV_STYLE_LINE_OPA = 105, - LV_STYLE_CONTENT_TEXT = 110 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_ALIGN = 111 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_OFS_X = 112 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_OFS_Y = 113 | LV_STYLE_PROP_EXT_DRAW, - LV_STYLE_CONTENT_FONT = 114 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_COLOR = 115 | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_COLOR_FILTERED = 115 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER, - LV_STYLE_CONTENT_OPA = 116 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_LETTER_SPACE = 117 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_LINE_SPACE = 118 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, - LV_STYLE_CONTENT_DECOR = 119 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_ARC_WIDTH = 110 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_ARC_ROUNDED = 111, + LV_STYLE_ARC_COLOR = 112, + LV_STYLE_ARC_COLOR_FILTERED = 112 | LV_STYLE_PROP_FILTER, + LV_STYLE_ARC_OPA = 113, + LV_STYLE_ARC_IMG_SRC = 114, - _LV_STYLE_LAST_BUILT_IN_PROP = 128, + LV_STYLE_CONTENT_TEXT = 120 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_ALIGN = 121 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_OFS_X = 122 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_OFS_Y = 123 | LV_STYLE_PROP_EXT_DRAW, + LV_STYLE_CONTENT_FONT = 124 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_COLOR = 125 | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_COLOR_FILTERED = 125 | LV_STYLE_PROP_INHERIT | LV_STYLE_PROP_FILTER, + LV_STYLE_CONTENT_OPA = 126 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_LETTER_SPACE = 127 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_LINE_SPACE = 128 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + LV_STYLE_CONTENT_DECOR = 129 | LV_STYLE_PROP_EXT_DRAW | LV_STYLE_PROP_INHERIT, + + _LV_STYLE_LAST_BUILT_IN_PROP = 140, LV_STYLE_PROP_ALL = 0xFFFF }lv_style_prop_t; @@ -562,6 +569,24 @@ static inline void lv_style_set_line_color_filtered(lv_style_t * style, lv_color static inline void lv_style_set_line_opa(lv_style_t * style, lv_opa_t value) { lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_LINE_OPA, v); } +static inline void lv_style_set_arc_width(lv_style_t * style, lv_coord_t value) { + lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ARC_WIDTH, v); } + +static inline void lv_style_set_arc_rounded(lv_style_t * style, lv_coord_t value) { + lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ARC_ROUNDED, v); } + +static inline void lv_style_set_arc_color(lv_style_t * style, lv_color_t value) { + lv_style_value_t v = {.color = value}; lv_style_set_prop(style, LV_STYLE_ARC_COLOR, v); } + +static inline void lv_style_set_arc_color_filtered(lv_style_t * style, lv_color_t value) { + lv_style_value_t v = {.color = value}; lv_style_set_prop(style, LV_STYLE_ARC_COLOR_FILTERED, v); } + +static inline void lv_style_set_arc_opa(lv_style_t * style, lv_opa_t value) { + lv_style_value_t v = {.num = value}; lv_style_set_prop(style, LV_STYLE_ARC_OPA, v); } + +static inline void lv_style_set_arc_img_src(lv_style_t * style, const void * value) { + lv_style_value_t v = {.ptr = value}; lv_style_set_prop(style, LV_STYLE_ARC_IMG_SRC, v); } + static inline void lv_style_set_content_text(lv_style_t * style, const char * value) { lv_style_value_t v = {.ptr = value}; lv_style_set_prop(style, LV_STYLE_CONTENT_TEXT, v); } diff --git a/src/lv_widgets/lv_arc.c b/src/lv_widgets/lv_arc.c index 75347fb26..9fd18e8c4 100644 --- a/src/lv_widgets/lv_arc.c +++ b/src/lv_widgets/lv_arc.c @@ -163,8 +163,8 @@ void lv_arc_set_angles(lv_obj_t * obj, uint16_t start, uint16_t end) inv_arc_area(obj,arc->indic_angle_start,arc->indic_angle_end, LV_PART_INDICATOR); - arc->indic_angle_start = start; - arc->indic_angle_end = end; + arc->indic_angle_start = start; + arc->indic_angle_end = end; inv_arc_area(obj,arc->indic_angle_start,arc->indic_angle_end, LV_PART_INDICATOR); } @@ -375,25 +375,6 @@ void lv_arc_set_chg_rate(lv_obj_t * obj, uint16_t rate) arc->chg_rate = rate; } -/** - * Set whether the arc is adjustable. - * @param arc pointer to a arc object - * @param adjustable whether the arc has a knob that can be dragged - */ -void lv_arc_set_adjustable(lv_obj_t * obj, bool adjustable) -{ - LV_ASSERT_OBJ(obj, MY_CLASS); - lv_arc_t * arc = (lv_arc_t *)obj; - - if(arc->adjustable == adjustable) - return; - - arc->adjustable = adjustable; - if(!adjustable) - arc->dragging = false; - lv_obj_invalidate(obj); -} - /*===================== * Getter functions *====================*/ @@ -487,17 +468,6 @@ lv_arc_type_t lv_arc_get_type(const lv_obj_t * obj) return ((lv_arc_t*) obj)->type; } -/** - * Get whether the arc is adjustable. - * @param arc pointer to a arc object - * @return whether the arc has a knob that can be dragged - */ -bool lv_arc_get_adjustable(lv_obj_t * obj) -{ - LV_ASSERT_OBJ(obj, MY_CLASS); - return ((lv_arc_t*) obj)->adjustable; -} - /*===================== * Other functions *====================*/ @@ -533,7 +503,6 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t arc->min_value = 0; arc->max_value = 100; arc->dragging = false; - arc->adjustable = false; arc->chg_rate = 540; arc->last_tick = lv_tick_get(); arc->last_angle =arc->indic_angle_end; @@ -558,7 +527,6 @@ static void lv_arc_constructor(lv_obj_t * obj, lv_obj_t * parent, const lv_obj_t arc->min_value = copy_arc->min_value; arc->max_value = copy_arc->max_value; arc->dragging = copy_arc->dragging; - arc->adjustable = copy_arc->adjustable; arc->chg_rate = copy_arc->chg_rate; arc->last_tick = copy_arc->last_tick; arc->last_angle = copy_arc->last_angle; @@ -580,16 +548,6 @@ static void lv_arc_destructor(lv_obj_t * obj) } -/** - * Handle the drawing related tasks of the arcs - * @param arc pointer to an object - * @param clip_area 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 - * @param return an element of `lv_draw_res_t` - */ static lv_draw_res_t lv_arc_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*/ @@ -633,16 +591,14 @@ static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv &arc_dsc); } - if(arc->adjustable) { - lv_area_t knob_area; - get_knob_area(obj, ¢er, arc_r, &knob_area); + lv_area_t knob_area; + get_knob_area(obj, ¢er, arc_r, &knob_area); - lv_draw_rect_dsc_t knob_rect_dsc; - lv_draw_rect_dsc_init(&knob_rect_dsc); - lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc); + lv_draw_rect_dsc_t knob_rect_dsc; + lv_draw_rect_dsc_init(&knob_rect_dsc); + lv_obj_init_draw_rect_dsc(obj, LV_PART_KNOB, &knob_rect_dsc); - lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc); - } + lv_draw_rect(&knob_area, clip_area, &knob_rect_dsc); } /*Post draw when the children are drawn*/ @@ -653,13 +609,6 @@ static lv_draw_res_t lv_arc_draw(lv_obj_t * obj, const lv_area_t * clip_area, lv return LV_DRAW_RES_OK; } -/** - * Signal function of the arc - * @param arc pointer to a arc object - * @param sign a signal type from lv_signal_t enum - * @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_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param) { lv_res_t res; @@ -670,9 +619,6 @@ static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param) lv_arc_t * arc = (lv_arc_t *)obj; if(sign == LV_SIGNAL_PRESSING) { - /* Only adjustable arcs can be dragged */ - if(!arc->adjustable) return res; - lv_indev_t * indev = lv_indev_get_act(); if(indev == NULL) return res; @@ -693,7 +639,7 @@ static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param) /*Enter dragging mode if pressed out of the knob*/ if(arc->dragging == false) { - lv_coord_t indic_width = lv_obj_get_style_line_width(obj, LV_PART_INDICATOR); + lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR); r -= indic_width; r -= r / 2; /*Add some more sensitive area*/ if(p.x * p.x + p.y * p.y > r * r) { @@ -789,8 +735,6 @@ static lv_res_t lv_arc_signal(lv_obj_t * obj, lv_signal_t sign, void * param) } else if(sign == LV_SIGNAL_CONTROL) { - if(!arc->adjustable) return res; - char c = *((char *)param); int16_t old_value =arc->value; @@ -834,8 +778,8 @@ static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angl lv_coord_t rout = (LV_MIN(lv_obj_get_width(obj) - left - right, lv_obj_get_height(obj) - top - bottom)) / 2; lv_coord_t x = obj->coords.x1 + rout + left; lv_coord_t y = obj->coords.y1 + rout + top; - lv_coord_t w = lv_obj_get_style_line_width(obj, part); - lv_coord_t rounded = lv_obj_get_style_line_rounded(obj, part); + lv_coord_t w = lv_obj_get_style_arc_width(obj, part); + lv_coord_t rounded = lv_obj_get_style_arc_rounded(obj, part); lv_coord_t rin = rout - w; lv_coord_t extra_area = 0; @@ -852,7 +796,6 @@ static void inv_arc_area(lv_obj_t * obj, uint16_t start_angle, uint16_t end_angl knob_extra_size += LV_MAX4(knob_left, knob_right, knob_top, knob_bottom); extra_area = LV_MAX(extra_area, w / 2 + 2 + knob_extra_size); - } lv_area_t inv_area; @@ -949,7 +892,7 @@ static void get_center(lv_obj_t * obj, lv_point_t * center, lv_coord_t * arc_r) center->x = obj->coords.x1 + r + left_bg; center->y = obj->coords.y1 + r + top_bg; - lv_coord_t indic_width = lv_obj_get_style_line_width(obj, LV_PART_INDICATOR); + lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR); r -= indic_width; } @@ -958,7 +901,7 @@ static void get_knob_area(lv_obj_t * obj, const lv_point_t * center, lv_coord_t LV_ASSERT_OBJ(obj, MY_CLASS); lv_arc_t * arc = (lv_arc_t *)obj; - lv_coord_t indic_width = lv_obj_get_style_line_width(obj, LV_PART_INDICATOR); + lv_coord_t indic_width = lv_obj_get_style_arc_width(obj, LV_PART_INDICATOR); lv_coord_t indic_width_half = indic_width / 2; r -= indic_width_half; diff --git a/src/lv_widgets/lv_arc.h b/src/lv_widgets/lv_arc.h index 7b5acc609..525a27e8a 100644 --- a/src/lv_widgets/lv_arc.h +++ b/src/lv_widgets/lv_arc.h @@ -46,7 +46,6 @@ typedef struct { int16_t max_value; /*Maximum value of the arc*/ uint16_t dragging : 1; uint16_t type : 2; - uint16_t adjustable : 1; uint16_t min_close : 1; /*1: the last pressed angle was closer to minimum end*/ uint16_t chg_rate; /*Drag angle rate of change of the arc (degrees/sec)*/ uint32_t last_tick; /*Last dragging event timestamp of the arc*/ diff --git a/src/lv_widgets/lv_btnmatrix.c b/src/lv_widgets/lv_btnmatrix.c index b339879d6..31295131e 100644 --- a/src/lv_widgets/lv_btnmatrix.c +++ b/src/lv_widgets/lv_btnmatrix.c @@ -528,10 +528,11 @@ static lv_draw_res_t lv_btnmatrix_draw(lv_obj_t * obj, const lv_area_t * clip_ar hook_dsc.id = btn_i; lv_event_send(obj,LV_EVENT_DRAW_PART_BEGIN, &hook_dsc); - /*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/ +// /*Remove borders on the edges if `LV_BORDER_SIDE_INTERNAL`*/ if(draw_rect_dsc_act.border_side & LV_BORDER_SIDE_INTERNAL) { + draw_rect_dsc_act.border_side = LV_BORDER_SIDE_FULL; if(btn_area.x1 == obj->coords.x1 + pleft) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_LEFT; - if(btn_area.y2 == obj->coords.x2 - pright) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_RIGHT; + if(btn_area.x2 == obj->coords.x2 - pright) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_RIGHT; if(btn_area.y1 == obj->coords.y1 + ptop) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_TOP; if(btn_area.y2 == obj->coords.y2 - pbottom) draw_rect_dsc_act.border_side &= ~LV_BORDER_SIDE_BOTTOM; }