diff --git a/src/lv_themes/lv_theme_material.c b/src/lv_themes/lv_theme_material.c index 37786645e..fd6b3dbc2 100644 --- a/src/lv_themes/lv_theme_material.c +++ b/src/lv_themes/lv_theme_material.c @@ -72,11 +72,13 @@ * STATIC PROTOTYPES **********************/ static void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name); +static void style_init_reset(lv_style_t * style); /********************** * STATIC VARIABLES **********************/ static lv_theme_t theme; +static bool inited; static lv_style_t scr; static lv_style_t bg; @@ -180,17 +182,16 @@ static lv_style_t pad_small; * STATIC FUNCTIONS **********************/ - static void basic_init(void) { - lv_style_init(&scr); + style_init_reset(&scr); lv_style_set_bg_opa(&scr, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&scr, LV_STATE_DEFAULT, COLOR_SCR); lv_style_set_text_color(&scr, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_value_color(&scr, LV_STATE_DEFAULT, COLOR_SCR_TEXT); lv_style_set_border_post(&scr, LV_STATE_DEFAULT, true); - lv_style_init(&bg); + style_init_reset(&bg); lv_style_set_radius(&bg, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_bg_opa(&bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&bg, LV_STATE_DEFAULT, COLOR_BG); @@ -212,7 +213,7 @@ static void basic_init(void) lv_style_set_transition_time(&bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&bg, LV_STATE_DEFAULT, LV_STYLE_BORDER_COLOR); - lv_style_init(&bg_sec); + style_init_reset(&bg_sec); lv_style_copy(&bg_sec, &bg); lv_style_set_bg_color(&bg_sec, LV_STATE_DEFAULT, COLOR_BG_SEC); lv_style_set_border_color(&bg_sec, LV_STATE_DEFAULT, COLOR_BG_SEC_BORDER); @@ -221,7 +222,7 @@ static void basic_init(void) lv_style_set_image_recolor(&bg_sec, LV_STATE_DEFAULT, COLOR_BG_SEC_TEXT); lv_style_set_line_color(&bg_sec, LV_STATE_DEFAULT, COLOR_BG_SEC_TEXT); - lv_style_init(&bg_click); + style_init_reset(&bg_click); lv_style_set_bg_color(&bg_click, LV_STATE_PRESSED, COLOR_BG_PR); lv_style_set_bg_color(&bg_click, LV_STATE_CHECKED, COLOR_BG_CHK); lv_style_set_bg_color(&bg_click, LV_STATE_PRESSED | LV_STATE_CHECKED, COLOR_BG_PR_CHK); @@ -242,7 +243,7 @@ static void basic_init(void) lv_style_set_image_recolor(&bg_click, LV_STATE_DISABLED, COLOR_BG_TEXT_DIS); lv_style_set_transition_prop_5(&bg_click, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); - lv_style_init(&btn); + style_init_reset(&btn); lv_style_set_radius(&btn, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_bg_opa(&btn, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&btn, LV_STATE_DEFAULT, COLOR_BTN); @@ -291,10 +292,10 @@ static void basic_init(void) lv_style_set_transition_delay(&btn, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_delay(&btn, LV_STATE_PRESSED, 0); - lv_style_init(&pad_inner); + style_init_reset(&pad_inner); lv_style_set_pad_inner(&pad_inner, LV_STATE_DEFAULT, LV_DPI / 10); - lv_style_init(&pad_small); + style_init_reset(&pad_small); lv_style_set_pad_left(&pad_small, LV_STATE_DEFAULT, LV_DPI / 15); lv_style_set_pad_right(&pad_small, LV_STATE_DEFAULT, LV_DPI / 15); lv_style_set_pad_top(&pad_small, LV_STATE_DEFAULT, LV_DPI / 15); @@ -326,7 +327,7 @@ static void label_init(void) static void bar_init(void) { #if LV_USE_BAR - lv_style_init(&bar_bg); + style_init_reset(&bar_bg); lv_style_set_radius(&bar_bg, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_bg_opa(&bar_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&bar_bg, LV_STATE_DEFAULT, COLOR_BG_SEC); @@ -338,7 +339,7 @@ static void bar_init(void) lv_style_set_transition_time(&bar_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&bar_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); - lv_style_init(&bar_indic); + style_init_reset(&bar_indic); lv_style_set_bg_opa(&bar_indic, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_radius(&bar_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_bg_color(&bar_indic, LV_STATE_DEFAULT, theme.color_primary); @@ -364,7 +365,7 @@ static void line_init(void) static void led_init(void) { #if LV_USE_LED != 0 - lv_style_init(&led); + style_init_reset(&led); lv_style_set_bg_opa(&led, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&led, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_border_width(&led, LV_STATE_DEFAULT, 2); @@ -380,7 +381,7 @@ static void led_init(void) static void slider_init(void) { #if LV_USE_SLIDER != 0 - lv_style_init(&slider_knob); + style_init_reset(&slider_knob); lv_style_set_bg_opa(&slider_knob, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? theme.color_primary : LV_COLOR_WHITE); lv_style_set_value_color(&slider_knob, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); @@ -390,7 +391,7 @@ static void slider_init(void) lv_style_set_pad_top(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_pad_bottom(&slider_knob, LV_STATE_DEFAULT, LV_DPI / 20); - lv_style_init(&slider_bg); + style_init_reset(&slider_bg); lv_style_set_margin_left(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 12); lv_style_set_margin_right(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 12); lv_style_set_margin_top(&slider_bg, LV_STATE_DEFAULT, LV_DPI / 20); @@ -402,7 +403,7 @@ static void slider_init(void) static void switch_init(void) { #if LV_USE_SWITCH != 0 - lv_style_init(&sw_knob); + style_init_reset(&sw_knob); lv_style_set_bg_opa(&sw_knob, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&sw_knob, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_radius(&sw_knob, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); @@ -416,7 +417,7 @@ static void switch_init(void) static void linemeter_init(void) { #if LV_USE_LINEMETER != 0 - lv_style_init(&lmeter); + style_init_reset(&lmeter); lv_style_set_radius(&lmeter, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_pad_left(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_right(&lmeter, LV_STATE_DEFAULT, LV_DPI / 10); @@ -435,7 +436,7 @@ static void linemeter_init(void) static void gauge_init(void) { #if LV_USE_GAUGE != 0 - lv_style_init(&gauge_main); + style_init_reset(&gauge_main); lv_style_set_line_color(&gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_grad_color(&gauge_main, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_end_color(&gauge_main, LV_STATE_DEFAULT, theme.color_primary); @@ -450,7 +451,7 @@ static void gauge_init(void) lv_style_set_radius(&gauge_main, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_border_width(&gauge_main, LV_STATE_DEFAULT, LV_DPI / 50); - lv_style_init(&gauge_strong); + style_init_reset(&gauge_strong); lv_style_set_line_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_grad_color(&gauge_strong, LV_STATE_DEFAULT, lv_color_hex3(0x888)); lv_style_set_scale_end_color(&gauge_strong, LV_STATE_DEFAULT, theme.color_primary); @@ -458,7 +459,7 @@ static void gauge_init(void) lv_style_set_scale_end_line_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_scale_width(&gauge_strong, LV_STATE_DEFAULT, LV_DPI / 6); - lv_style_init(&gauge_needle); + style_init_reset(&gauge_needle); lv_style_set_line_color(&gauge_needle, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x464b5b) : LV_COLOR_WHITE); lv_style_set_line_width(&gauge_needle, LV_STATE_DEFAULT, LV_DPI / 25); lv_style_set_bg_opa(&gauge_needle, LV_STATE_DEFAULT, LV_OPA_COVER); @@ -472,12 +473,12 @@ static void gauge_init(void) static void arc_init(void) { #if LV_USE_ARC != 0 - lv_style_init(&arc_indic); + style_init_reset(&arc_indic); lv_style_set_line_color(&arc_indic, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_line_width(&arc_indic, LV_STATE_DEFAULT, LV_DPI / 8); lv_style_set_line_rounded(&arc_indic, LV_STATE_DEFAULT, true); - lv_style_init(&arc_bg); + style_init_reset(&arc_bg); lv_style_set_line_color(&arc_bg, LV_STATE_DEFAULT, COLOR_BG_SEC); lv_style_set_line_width(&arc_bg, LV_STATE_DEFAULT, LV_DPI / 8); lv_style_set_line_rounded(&arc_bg, LV_STATE_DEFAULT, true); @@ -494,16 +495,16 @@ static void spinner_init(void) static void chart_init(void) { #if LV_USE_CHART - lv_style_init(&chart_bg); + style_init_reset(&chart_bg); lv_style_set_text_color(&chart_bg, LV_STATE_DEFAULT, COLOR_BG_TEXT_DIS); - lv_style_init(&chart_series_bg); + style_init_reset(&chart_series_bg); lv_style_set_line_width(&chart_series_bg, LV_STATE_DEFAULT, 1); lv_style_set_line_dash_width(&chart_series_bg, LV_STATE_DEFAULT, 4); lv_style_set_line_dash_gap(&chart_series_bg, LV_STATE_DEFAULT, 4); lv_style_set_line_color(&chart_series_bg, LV_STATE_DEFAULT, COLOR_BG_BORDER); - lv_style_init(&chart_series); + style_init_reset(&chart_series); lv_style_set_line_width(&chart_series, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_size(&chart_series, LV_STATE_DEFAULT, LV_DPI / 40); lv_style_set_pad_inner(&chart_series, LV_STATE_DEFAULT, LV_MATH_MAX(LV_DPI / 100, 1)); /*Space between columns*/ @@ -516,20 +517,20 @@ static void calendar_init(void) { #if LV_USE_CALENDAR - lv_style_init(&calendar_header); + style_init_reset(&calendar_header); lv_style_set_pad_top(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_left(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_right(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_bottom(&calendar_header, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_text_color(&calendar_header, LV_STATE_PRESSED, IS_LIGHT ? lv_color_hex(0x888888) : LV_COLOR_WHITE); - lv_style_init(&calendar_daynames); + style_init_reset(&calendar_daynames); lv_style_set_text_color(&calendar_daynames, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex(0x31404f) : lv_color_hex3(0xeee)); lv_style_set_pad_left(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_right(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_bottom(&calendar_daynames, LV_STATE_DEFAULT, LV_DPI / 10); - lv_style_init(&calendar_date_nums); + style_init_reset(&calendar_date_nums); lv_style_set_radius(&calendar_date_nums, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_text_color(&calendar_date_nums, LV_STATE_CHECKED, IS_LIGHT ? lv_color_hex(0x31404f) : LV_COLOR_WHITE); lv_style_set_text_color(&calendar_date_nums, LV_STATE_FOCUSED, theme.color_primary); @@ -552,14 +553,14 @@ static void calendar_init(void) static void cpicker_init(void) { #if LV_USE_CPICKER - lv_style_init(&cpicker_bg); + style_init_reset(&cpicker_bg); lv_style_set_scale_width(&cpicker_bg, LV_STATE_DEFAULT, LV_DPI / 4); lv_style_set_bg_opa(&cpicker_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&cpicker_bg, LV_STATE_DEFAULT, COLOR_SCR); lv_style_set_pad_inner(&cpicker_bg, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_radius(&cpicker_bg, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_init(&cpicker_indic); + style_init_reset(&cpicker_indic); lv_style_set_radius(&cpicker_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); lv_style_set_bg_color(&cpicker_indic, LV_STATE_DEFAULT, LV_COLOR_WHITE); lv_style_set_bg_opa(&cpicker_indic, LV_STATE_DEFAULT, LV_OPA_COVER); @@ -576,7 +577,7 @@ static void cpicker_init(void) static void checkbox_init(void) { #if LV_USE_CHECKBOX != 0 - lv_style_init(&cb_bg); + style_init_reset(&cb_bg); lv_style_set_radius(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_pad_inner(&cb_bg, LV_STATE_DEFAULT, LV_DPI / 20); lv_style_set_outline_color(&cb_bg, LV_STATE_DEFAULT, theme.color_primary); @@ -587,7 +588,7 @@ static void checkbox_init(void) lv_style_set_transition_time(&cb_bg, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&cb_bg, LV_STATE_DEFAULT, LV_STYLE_OUTLINE_OPA); - lv_style_init(&cb_bullet); + style_init_reset(&cb_bullet); lv_style_set_outline_opa(&cb_bullet, LV_STATE_FOCUSED, LV_OPA_TRANSP); lv_style_set_radius(&cb_bullet, LV_STATE_DEFAULT, LV_DPI / 50); lv_style_set_pattern_image(&cb_bullet, LV_STATE_CHECKED, LV_SYMBOL_OK); @@ -603,7 +604,7 @@ static void btnmatrix_init(void) static void keyboard_init(void) { #if LV_USE_KEYBOARD - lv_style_init(&kb_bg); + style_init_reset(&kb_bg); lv_style_set_radius(&kb_bg, LV_STATE_DEFAULT, 0); lv_style_set_border_width(&kb_bg, LV_STATE_DEFAULT, (LV_DPI / 50 > 0 ? LV_DPI / 50 : 1)); lv_style_set_border_side(&kb_bg, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP); @@ -619,7 +620,7 @@ static void keyboard_init(void) static void msgbox_init(void) { #if LV_USE_MSGBOX - lv_style_init(&mbox_bg); + style_init_reset(&mbox_bg); lv_style_set_shadow_width(&mbox_bg, LV_STATE_DEFAULT, LV_DPI / 4); lv_style_set_shadow_color(&mbox_bg, LV_STATE_DEFAULT, LV_COLOR_SILVER); @@ -629,7 +630,7 @@ static void msgbox_init(void) static void page_init(void) { #if LV_USE_PAGE - lv_style_init(&sb); + style_init_reset(&sb); lv_style_set_bg_opa(&sb, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&sb, LV_STATE_DEFAULT, (IS_LIGHT ? lv_color_hex(0xcccfd1) : lv_color_hex(0x505559))); lv_style_set_radius(&sb, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); @@ -643,13 +644,13 @@ static void page_init(void) static void textarea_init(void) { #if LV_USE_TEXTAREA - lv_style_init(&ta_cursor); + style_init_reset(&ta_cursor); lv_style_set_border_color(&ta_cursor, LV_STATE_DEFAULT, COLOR_BG_SEC_TEXT); lv_style_set_border_width(&ta_cursor, LV_STATE_DEFAULT, 2); lv_style_set_pad_left(&ta_cursor, LV_STATE_DEFAULT, 1); lv_style_set_border_side(&ta_cursor, LV_STATE_DEFAULT, LV_BORDER_SIDE_LEFT); - lv_style_init(&ta_placeholder); + style_init_reset(&ta_placeholder); lv_style_set_text_color(&ta_placeholder, LV_STATE_DEFAULT, COLOR_BG_TEXT_DIS); #endif } @@ -658,7 +659,7 @@ static void spinbox_init(void) { #if LV_USE_SPINBOX - lv_style_init(&spinbox_cursor); + style_init_reset(&spinbox_cursor); lv_style_set_bg_opa(&spinbox_cursor, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&spinbox_cursor, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&spinbox_cursor, LV_STATE_DEFAULT, LV_COLOR_WHITE); @@ -671,7 +672,7 @@ static void spinbox_init(void) static void list_init(void) { #if LV_USE_LIST != 0 - lv_style_init(&list_bg); + style_init_reset(&list_bg); lv_style_set_clip_corner(&list_bg, LV_STATE_DEFAULT, true); lv_style_set_pad_left(&list_bg, LV_STATE_DEFAULT, 0); lv_style_set_pad_right(&list_bg, LV_STATE_DEFAULT, 0); @@ -679,7 +680,7 @@ static void list_init(void) lv_style_set_pad_bottom(&list_bg, LV_STATE_DEFAULT, 0); lv_style_set_pad_inner(&list_bg, LV_STATE_DEFAULT, 0); - lv_style_init(&list_btn); + style_init_reset(&list_btn); lv_style_set_bg_opa(&list_btn, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&list_btn, LV_STATE_DEFAULT, COLOR_BG); lv_style_set_bg_color(&list_btn, LV_STATE_PRESSED, COLOR_BG_PR); @@ -706,9 +707,6 @@ static void list_init(void) lv_style_set_pad_bottom(&list_btn, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_inner(&list_btn, LV_STATE_DEFAULT, LV_DPI / 10); - lv_style_set_margin_top(&list_btn, LV_STATE_CHECKED, LV_DPI / 10); - lv_style_set_margin_bottom(&list_btn, LV_STATE_CHECKED, LV_DPI / 10); - lv_style_set_transform_width(&list_btn, LV_STATE_DEFAULT, - LV_DPI / 10); lv_style_set_transform_width(&list_btn, LV_STATE_PRESSED, 0); lv_style_set_transform_width(&list_btn, LV_STATE_CHECKED, 0); @@ -717,8 +715,6 @@ static void list_init(void) lv_style_set_transition_time(&list_btn, LV_STATE_DEFAULT, TRANSITION_TIME); lv_style_set_transition_prop_6(&list_btn, LV_STATE_DEFAULT, LV_STYLE_BG_COLOR); lv_style_set_transition_prop_5(&list_btn, LV_STATE_DEFAULT, LV_STYLE_TRANSFORM_WIDTH); - lv_style_set_transition_prop_4(&list_btn, LV_STATE_DEFAULT, LV_STYLE_MARGIN_TOP); - lv_style_set_transition_prop_3(&list_btn, LV_STATE_DEFAULT, LV_STYLE_MARGIN_BOTTOM); #endif } @@ -726,10 +722,10 @@ static void ddlist_init(void) { #if LV_USE_DROPDOWN != 0 - lv_style_init(&ddlist_page); + style_init_reset(&ddlist_page); lv_style_set_text_line_space(&ddlist_page, LV_STATE_DEFAULT, LV_DPI / 5); - lv_style_init(&ddlist_sel); + style_init_reset(&ddlist_sel); lv_style_set_bg_opa(&ddlist_sel, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&ddlist_sel, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&ddlist_sel, LV_STATE_DEFAULT, IS_LIGHT ? lv_color_hex3(0xfff) : lv_color_hex3(0xfff)); @@ -741,10 +737,10 @@ static void ddlist_init(void) static void roller_init(void) { #if LV_USE_ROLLER != 0 - lv_style_init(&roller_bg); + style_init_reset(&roller_bg); lv_style_set_text_line_space(&roller_bg, LV_STATE_DEFAULT, LV_DPI / 8); - lv_style_init(&roller_sel); + style_init_reset(&roller_sel); lv_style_set_bg_opa(&roller_sel, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&roller_sel, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_text_color(&roller_sel, LV_STATE_DEFAULT, LV_COLOR_WHITE); @@ -754,7 +750,7 @@ static void roller_init(void) static void tabview_init(void) { #if LV_USE_TABVIEW != 0 - lv_style_init(&tabview_btns_bg); + style_init_reset(&tabview_btns_bg); lv_style_set_bg_opa(&tabview_btns_bg, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&tabview_btns_bg, LV_STATE_DEFAULT, COLOR_BG); lv_style_set_border_color(&tabview_btns_bg, LV_STATE_DEFAULT, @@ -768,7 +764,7 @@ static void tabview_init(void) lv_style_set_pad_left(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30); lv_style_set_pad_right(&tabview_btns_bg, LV_STATE_DEFAULT, LV_DPI / 30); - lv_style_init(&tabview_btns); + style_init_reset(&tabview_btns); lv_style_set_bg_opa(&tabview_btns, LV_STATE_PRESSED, LV_OPA_50); lv_style_set_bg_color(&tabview_btns, LV_STATE_PRESSED, lv_color_hex3(0x888)); lv_style_set_text_color(&tabview_btns, LV_STATE_CHECKED, COLOR_SCR_TEXT); @@ -776,13 +772,13 @@ static void tabview_init(void) lv_style_set_pad_bottom(&tabview_btns, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_text_color(&tabview_btns, LV_STATE_FOCUSED, theme.color_primary); - lv_style_init(&tabview_indic); + style_init_reset(&tabview_indic); lv_style_set_bg_opa(&tabview_indic, LV_STATE_DEFAULT, LV_OPA_COVER); lv_style_set_bg_color(&tabview_indic, LV_STATE_DEFAULT, theme.color_primary); lv_style_set_size(&tabview_indic, LV_STATE_DEFAULT, LV_DPI / 40 > 0 ? LV_DPI / 40 : 1); lv_style_set_radius(&tabview_indic, LV_STATE_DEFAULT, LV_RADIUS_CIRCLE); - lv_style_init(&tabview_page_scrl); + style_init_reset(&tabview_page_scrl); lv_style_set_pad_top(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_bottom(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); lv_style_set_pad_left(&tabview_page_scrl, LV_STATE_DEFAULT, LV_DPI / 10); @@ -800,7 +796,7 @@ static void tileview_init(void) static void table_init(void) { #if LV_USE_TABLE != 0 - lv_style_init(&table_cell); + style_init_reset(&table_cell); lv_style_set_border_color(&table_cell, LV_STATE_DEFAULT, COLOR_BG_BORDER); lv_style_set_border_width(&table_cell, LV_STATE_DEFAULT, 1); lv_style_set_border_side(&table_cell, LV_STATE_DEFAULT, LV_BORDER_SIDE_TOP | LV_BORDER_SIDE_BOTTOM); @@ -881,6 +877,8 @@ lv_theme_t * lv_theme_material_init(lv_color_t color_primary, lv_color_t color_s theme.apply_cb = lv_theme_material_apply; + inited = true; + lv_obj_report_style_mod(NULL); return &theme; @@ -1388,13 +1386,16 @@ void lv_theme_material_apply(lv_obj_t * obj, lv_theme_style_t name) lv_obj_refresh_style(obj, LV_STYLE_PROP_ALL); - - } /********************** * STATIC FUNCTIONS **********************/ +static void style_init_reset(lv_style_t * style) +{ + if(inited) lv_style_reset(style); + else lv_style_init(style); +} #endif diff --git a/src/lv_widgets/lv_gauge.c b/src/lv_widgets/lv_gauge.c index 98822e5f5..5fee44476 100644 --- a/src/lv_widgets/lv_gauge.c +++ b/src/lv_widgets/lv_gauge.c @@ -194,9 +194,58 @@ void lv_gauge_set_value(lv_obj_t * gauge, uint8_t needle_id, int32_t value) else if(value < min) value = min; + int32_t old_value = ext->values[needle_id]; ext->values[needle_id] = value; - lv_obj_invalidate(gauge); +// lv_obj_invalidate(gauge); + + lv_style_int_t pad = lv_obj_get_style_pad_inner(gauge, LV_GAUGE_PART_NEEDLE); + lv_style_int_t left = lv_obj_get_style_pad_left(gauge, LV_GAUGE_PART_MAIN); + lv_style_int_t right = lv_obj_get_style_pad_right(gauge, LV_GAUGE_PART_MAIN); + lv_style_int_t top = lv_obj_get_style_pad_top(gauge, LV_GAUGE_PART_MAIN); + lv_coord_t r = (lv_obj_get_width(gauge) - left - right) / 2 - pad; + lv_coord_t x_ofs = gauge->coords.x1 + r + left + pad; + lv_coord_t y_ofs = gauge->coords.y1 + r + top + pad; + uint16_t angle = lv_linemeter_get_scale_angle(gauge); + int16_t angle_ofs = 90 + (360 - angle) / 2; + lv_point_t p_mid; + lv_point_t p_end; + lv_coord_t needle_w; + + if(ext->needle_img) { + lv_img_header_t info; + lv_img_decoder_get_info(ext->needle_img, &info); + needle_w = info.h; + } else { + needle_w = lv_obj_get_style_line_width(gauge, LV_GAUGE_PART_NEEDLE); + } + + p_mid.x = x_ofs; + p_mid.y = y_ofs; + /*Calculate the end point of a needle*/ + int16_t needle_angle = (old_value - min) * angle / (max - min) + angle_ofs; + + p_end.y = (lv_trigo_sin(needle_angle) * r) / LV_TRIGO_SIN_MAX + y_ofs; + p_end.x = (lv_trigo_sin(needle_angle + 90) * r) / LV_TRIGO_SIN_MAX + x_ofs; + + lv_area_t a; + a.x1 = LV_MATH_MIN(p_mid.x, p_end.x) - needle_w; + a.y1 = LV_MATH_MIN(p_mid.y, p_end.y) - needle_w; + a.x2 = LV_MATH_MAX(p_mid.x, p_end.x) + needle_w; + a.y2 = LV_MATH_MAX(p_mid.y, p_end.y) + needle_w; + lv_obj_invalidate_area(gauge, &a); + + needle_angle = (value - min) * angle / (max - min) + angle_ofs; + p_end.y = (lv_trigo_sin(needle_angle) * r) / LV_TRIGO_SIN_MAX + y_ofs; + p_end.x = (lv_trigo_sin(needle_angle + 90) * r) / LV_TRIGO_SIN_MAX + x_ofs; + + a.x1 = LV_MATH_MIN(p_mid.x, p_end.x); + a.y1 = LV_MATH_MIN(p_mid.y, p_end.y); + a.x2 = LV_MATH_MAX(p_mid.x, p_end.x); + a.y2 = LV_MATH_MAX(p_mid.y, p_end.y); + lv_obj_invalidate_area(gauge, &a); + + } /** @@ -552,7 +601,6 @@ static void lv_gauge_draw_needle(lv_obj_t * gauge, const lv_area_t * clip_area) p_mid.y = y_ofs; for(i = 0; i < ext->needle_count; i++) { /*Calculate the end point of a needle*/ - int16_t needle_angle = (ext->values[i] - min) * angle / (max - min) + angle_ofs; diff --git a/src/lv_widgets/lv_linemeter.c b/src/lv_widgets/lv_linemeter.c index 779e157bb..487f45666 100644 --- a/src/lv_widgets/lv_linemeter.c +++ b/src/lv_widgets/lv_linemeter.c @@ -120,9 +120,93 @@ void lv_linemeter_set_value(lv_obj_t * lmeter, int32_t value) lv_linemeter_ext_t * ext = lv_obj_get_ext_attr(lmeter); if(ext->cur_value == value) return; + int32_t old_value = ext->cur_value; + ext->cur_value = value > ext->max_value ? ext->max_value : value; ext->cur_value = ext->cur_value < ext->min_value ? ext->min_value : ext->cur_value; - lv_obj_invalidate(lmeter); + + int16_t level_old = + (int32_t)((int32_t)(old_value - ext->min_value) * ext->line_cnt) / (ext->max_value - ext->min_value); + int16_t level_new = + (int32_t)((int32_t)(ext->cur_value - ext->min_value) * ext->line_cnt) / (ext->max_value - ext->min_value); + + if(level_new == level_old) { + return; + } + + lv_style_int_t left = lv_obj_get_style_pad_left(lmeter, LV_LINEMETER_PART_MAIN); + lv_style_int_t right = lv_obj_get_style_pad_right(lmeter, LV_LINEMETER_PART_MAIN); + lv_style_int_t top = lv_obj_get_style_pad_top(lmeter, LV_LINEMETER_PART_MAIN); + lv_style_int_t bottom = lv_obj_get_style_pad_bottom(lmeter, LV_LINEMETER_PART_MAIN); + + lv_coord_t r_out = (lv_obj_get_width(lmeter) - left - right) / 2 ; + lv_coord_t r_in = r_out - lv_obj_get_style_scale_width(lmeter, LV_LINEMETER_PART_MAIN); + if(r_in < 1) r_in = 1; + + lv_coord_t x_ofs = lmeter->coords.x1 + r_out + left; + lv_coord_t y_ofs = lmeter->coords.y1 + r_out + top; + int16_t angle_ofs = ext->angle_ofs + 90 + (360 - ext->scale_angle) / 2; + + lv_style_int_t line_width = lv_obj_get_style_scale_end_line_width(lmeter, LV_LINEMETER_PART_MAIN); + lv_style_int_t end_line_width = lv_obj_get_style_scale_end_line_width(lmeter, LV_LINEMETER_PART_MAIN); + line_width = LV_MATH_MAX(line_width, end_line_width); + + int32_t angle_old = (level_old * ext->scale_angle) / (ext->line_cnt - 1); + + /*Use smaller clip area only around the visible line*/ + int32_t y_in_old = (int32_t)((int32_t)lv_trigo_sin(angle_old + angle_ofs) * r_in) >> LV_TRIGO_SHIFT; + int32_t x_in_old = (int32_t)((int32_t)lv_trigo_sin(angle_old + 90 + angle_ofs) * r_in) >> LV_TRIGO_SHIFT; + + + int32_t y_out_old = (int32_t)((int32_t)lv_trigo_sin(angle_old + angle_ofs) * r_out) >> LV_TRIGO_SHIFT; + int32_t x_out_old = (int32_t)((int32_t)lv_trigo_sin(angle_old + 90 + angle_ofs) * r_out) >> LV_TRIGO_SHIFT; + + + + int32_t angle_new = (level_new * ext->scale_angle) / (ext->line_cnt - 1); + + /*Use smaller clip area only around the visible line*/ + int32_t y_in_new = (int32_t)((int32_t)lv_trigo_sin(angle_new + angle_ofs) * r_in) >> LV_TRIGO_SHIFT; + int32_t x_in_new = (int32_t)((int32_t)lv_trigo_sin(angle_new + 90 + angle_ofs) * r_in) >> LV_TRIGO_SHIFT; + + + int32_t y_out_new = (int32_t)((int32_t)lv_trigo_sin(angle_new + angle_ofs) * r_out) >> LV_TRIGO_SHIFT; + int32_t x_out_new = (int32_t)((int32_t)lv_trigo_sin(angle_new + 90 + angle_ofs) * r_out) >> LV_TRIGO_SHIFT; + + lv_area_t a; + if(x_out_old < 0 && x_out_new < 0) { + a.x1 = lmeter->coords.x1 + left - line_width; + a.y1 = LV_MATH_MIN4(y_out_old, y_out_new, y_in_old, y_in_new) + y_ofs - line_width; + a.x2 = LV_MATH_MAX(x_in_old, x_in_new) + x_ofs + line_width; + a.y2 = LV_MATH_MAX4(y_out_old, y_out_new, y_in_old, y_in_new) + y_ofs + line_width; + } + else if(x_out_old > 0 && x_out_new > 0) { + a.x1 = LV_MATH_MIN(x_in_old, x_in_new) + x_ofs - line_width; + a.y1 = LV_MATH_MIN4(y_out_old, y_out_new, y_in_old, y_in_new) + y_ofs - line_width; + a.x2 = lmeter->coords.x2 - right + line_width; + a.y2 = LV_MATH_MAX4(y_out_old, y_out_new, y_in_old, y_in_new) + y_ofs + line_width; + } + else if(y_out_old < 0 && y_out_new < 0) { + a.x1 = LV_MATH_MIN4(x_out_old, x_out_new, x_in_old, x_in_new) + x_ofs - line_width; + a.y1 = lmeter->coords.y1 + top - line_width; + a.x2 = LV_MATH_MAX4(x_out_old, x_out_new, x_in_old, x_in_new) + x_ofs + line_width; + a.y2 = LV_MATH_MAX(y_in_old, y_in_new) + y_ofs + line_width; + } + else if(y_out_old > 0 && y_out_new > 0) { + a.x1 = LV_MATH_MIN4(x_out_old, x_out_new, x_in_old, x_in_new) + x_ofs - line_width; + a.y1 = LV_MATH_MIN(y_in_old, y_in_new) + y_ofs - line_width; + a.x2 = LV_MATH_MAX4(x_out_old, x_out_new, x_in_old, x_in_new) + x_ofs + line_width; + a.y2 = lmeter->coords.y2 - bottom + line_width; + } + else { + a.x1 = lmeter->coords.x1 + left - line_width; + a.y1 = lmeter->coords.y1 + top - line_width; + a.x2 = lmeter->coords.x2 - right + line_width; + a.y2 = lmeter->coords.y2 - bottom + line_width; + } + + lv_obj_invalidate_area(lmeter, &a); + } /** diff --git a/src/lv_widgets/lv_page.c b/src/lv_widgets/lv_page.c index 7b6e85a1a..deb23ea07 100644 --- a/src/lv_widgets/lv_page.c +++ b/src/lv_widgets/lv_page.c @@ -867,7 +867,6 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param) /*Refresh the scrollbar and notify the scrl if the size is changed*/ if(ext->scrl != NULL && (lv_obj_get_width(page) != lv_area_get_width(param) || lv_obj_get_height(page) != lv_area_get_height(param))) { - /*If no hor_fit enabled set the scrollable's width to the page's width*/ ext->scrl->signal_cb(ext->scrl, LV_SIGNAL_COORD_CHG, &ext->scrl->coords); /*The scrollbars are important only if they are visible now*/ diff --git a/src/lv_widgets/lv_roller.c b/src/lv_widgets/lv_roller.c index 9588a50e7..ecd7ce80c 100644 --- a/src/lv_widgets/lv_roller.c +++ b/src/lv_widgets/lv_roller.c @@ -90,6 +90,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) ext->option_cnt = 0; ext->sel_opt_id = 0; ext->sel_opt_id_ori = 0; + ext->auto_fit = 1; lv_style_list_init(&ext->style_sel); /*The signal and design functions are not copied so set them here*/ @@ -120,7 +121,7 @@ lv_obj_t * lv_roller_create(lv_obj_t * par, const lv_obj_t * copy) else { lv_roller_ext_t * copy_ext = lv_obj_get_ext_attr(copy); lv_roller_set_options(roller, lv_roller_get_options(copy), copy_ext->mode); - + ext->auto_fit = copy_ext->auto_fit; lv_obj_t * scrl = lv_page_get_scrl(roller); lv_obj_set_signal_cb(scrl, lv_roller_scrl_signal); } @@ -186,8 +187,8 @@ void lv_roller_set_options(lv_obj_t * roller, const char * options, lv_roller_mo ext->sel_opt_id_ori = ext->sel_opt_id; - refr_width(roller); - refr_height(roller); +// refr_width(roller); +// refr_height(roller); refr_position(roller, LV_ANIM_OFF); } @@ -204,6 +205,7 @@ void lv_roller_set_align(lv_obj_t * roller, lv_label_align_t align) if(label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/ lv_label_set_align(label, align); + refr_width(roller); /*To set the correct label position*/ } /** @@ -255,6 +257,19 @@ void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt) refr_position(roller, LV_ANIM_OFF); } +/** + * Allow automatically setting the width of roller according to it's content. + * @param roller pointer to a roller object + * @param auto_fit true: enable auto fit + */ +void lv_roller_set_auto_fit(lv_obj_t * roller, bool auto_fit) +{ + LV_ASSERT_OBJ(roller, LV_OBJX_NAME); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + ext->auto_fit = auto_fit; + refr_width(roller); +} + /*===================== * Getter functions *====================*/ @@ -342,6 +357,17 @@ lv_label_align_t lv_roller_get_align(const lv_obj_t * roller) return lv_label_get_align(get_label(roller)); } +/** + * Get whether the auto fit option is enabled or not. + * @param roller pointer to a roller object + * @return true: auto fit is enabled + */ +bool lv_roller_get_auto_fit(lv_obj_t * roller) +{ + LV_ASSERT_OBJ(roller, LV_OBJX_NAME); + lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller); + return ext->auto_fit ? true : false; +} /** * Get the options of a roller @@ -473,6 +499,7 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_xcb_t)lv_obj_set_y); #endif refr_position(roller, false); + refr_width(roller); } } else if(sign == LV_SIGNAL_RELEASED) { @@ -617,6 +644,14 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign, lv_anim_del(roller_scrl, (lv_anim_exec_xcb_t)lv_obj_set_y); #endif } + else if(sign == LV_SIGNAL_PARENT_SIZE_CHG) { +#if LV_USE_ANIMATION + lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_xcb_t)lv_obj_set_y); +#endif + refr_position(roller, false); + refr_width(roller); + + } /*Position the scrollable according to the new selected option*/ if(id != -1) { @@ -800,6 +835,21 @@ static void refr_width(lv_obj_t * roller) lv_obj_t * label = get_label(roller); if(label == NULL) return; + switch(lv_label_get_align(label)) { + case LV_LABEL_ALIGN_LEFT: + lv_obj_align(label, NULL, LV_ALIGN_IN_LEFT_MID, 0, 0); + break; + case LV_LABEL_ALIGN_CENTER: + lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + break; + case LV_LABEL_ALIGN_RIGHT: + lv_obj_align(label, NULL, LV_ALIGN_IN_RIGHT_MID, 0, 0); + break; + } + + + if(lv_roller_get_auto_fit(roller) == false) return; + lv_coord_t label_w = lv_obj_get_width(label); lv_style_int_t left = lv_obj_get_style_pad_left(roller, LV_ROLLER_PART_BG); @@ -818,7 +868,7 @@ static void refr_height(lv_obj_t * roller) if(label == NULL) return; lv_obj_set_height(lv_page_get_scrl(roller), lv_obj_get_height(label) + lv_obj_get_height(roller)); - lv_obj_align(label, NULL, LV_ALIGN_CENTER, 0, 0); + #if LV_USE_ANIMATION lv_anim_del(lv_page_get_scrl(roller), (lv_anim_exec_xcb_t)lv_obj_set_y); #endif diff --git a/src/lv_widgets/lv_roller.h b/src/lv_widgets/lv_roller.h index fd7f9366d..18afff73e 100644 --- a/src/lv_widgets/lv_roller.h +++ b/src/lv_widgets/lv_roller.h @@ -54,6 +54,7 @@ typedef struct { uint16_t sel_opt_id; /*Index of the current option*/ uint16_t sel_opt_id_ori; /*Store the original index on focus*/ lv_roller_mode_t mode : 1; + uint8_t auto_fit : 1; /*1: Automatically set the width*/ } lv_roller_ext_t; enum { @@ -109,6 +110,13 @@ void lv_roller_set_selected(lv_obj_t * roller, uint16_t sel_opt, lv_anim_enable_ */ void lv_roller_set_visible_row_count(lv_obj_t * roller, uint8_t row_cnt); +/** + * Allow automatically setting the width of roller according to it's content. + * @param roller pointer to a roller object + * @param auto_fit true: enable auto fit + */ +void lv_roller_set_auto_fit(lv_obj_t * roller, bool auto_fit); + /** * Set the open/close animation time. * @param roller pointer to a roller object @@ -151,6 +159,13 @@ void lv_roller_get_selected_str(const lv_obj_t * roller, char * buf, uint16_t bu */ lv_label_align_t lv_roller_get_align(const lv_obj_t * roller); +/** + * Get whether the auto fit option is enabled or not. + * @param roller pointer to a roller object + * @return true: auto fit is enabled + */ +bool lv_roller_get_auto_fit(lv_obj_t * roller); + /** * Get the options of a roller * @param roller pointer to roller object diff --git a/src/lv_widgets/lv_spinbox.c b/src/lv_widgets/lv_spinbox.c index e9b0e81f4..b09467dcb 100644 --- a/src/lv_widgets/lv_spinbox.c +++ b/src/lv_widgets/lv_spinbox.c @@ -84,7 +84,7 @@ lv_obj_t * lv_spinbox_create(lv_obj_t * par, const lv_obj_t * copy) lv_obj_set_signal_cb(spinbox, lv_spinbox_signal); lv_obj_set_design_cb(spinbox, ancestor_design); /*Leave the Text area's design function*/ - /*Init the new spinbox spinbox*/ + /*Init the new spinbox*/ if(copy == NULL) { /* No scrolling will happen here so make the scrollable non-clickable * It allows to handle input events in the bg object only.*/