diff --git a/Kconfig b/Kconfig index 703013c95..d7ab3beba 100644 --- a/Kconfig +++ b/Kconfig @@ -775,6 +775,9 @@ menu "LVGL configuration" endmenu menu "Widget usage" + config LV_WIDGETS_HAS_DEFAULT_VALUE + bool "Widgets has default value." + default y if !LV_CONF_MINIMAL config LV_USE_ARC bool "Arc." default y if !LV_CONF_MINIMAL diff --git a/lv_conf_template.h b/lv_conf_template.h index 5be703abe..167309893 100644 --- a/lv_conf_template.h +++ b/lv_conf_template.h @@ -409,6 +409,8 @@ /*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/ +#define LV_WIDGETS_HAS_DEFAULT_VALUE 1 + #define LV_USE_ANIMIMG 1 #define LV_USE_ARC 1 diff --git a/src/lv_conf_internal.h b/src/lv_conf_internal.h index cfc3b6eed..c79526a76 100644 --- a/src/lv_conf_internal.h +++ b/src/lv_conf_internal.h @@ -1167,6 +1167,18 @@ /*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/ +#ifndef LV_WIDGETS_HAS_DEFAULT_VALUE + #ifdef _LV_KCONFIG_PRESENT + #ifdef CONFIG_LV_WIDGETS_HAS_DEFAULT_VALUE + #define LV_WIDGETS_HAS_DEFAULT_VALUE CONFIG_LV_WIDGETS_HAS_DEFAULT_VALUE + #else + #define LV_WIDGETS_HAS_DEFAULT_VALUE 0 + #endif + #else + #define LV_WIDGETS_HAS_DEFAULT_VALUE 1 + #endif +#endif + #ifndef LV_USE_ANIMIMG #ifdef _LV_KCONFIG_PRESENT #ifdef CONFIG_LV_USE_ANIMIMG diff --git a/src/widgets/btnmatrix/lv_btnmatrix.c b/src/widgets/btnmatrix/lv_btnmatrix.c index a788edd86..773ceeec5 100644 --- a/src/widgets/btnmatrix/lv_btnmatrix.c +++ b/src/widgets/btnmatrix/lv_btnmatrix.c @@ -57,7 +57,9 @@ static bool has_popovers_in_top_row(lv_obj_t * obj); /********************** * STATIC VARIABLES **********************/ +#if LV_WIDGETS_HAS_DEFAULT_VALUE static const char * lv_btnmatrix_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", "Btn4", "Btn5", ""}; +#endif const lv_obj_class_t lv_btnmatrix_class = { .constructor_cb = lv_btnmatrix_constructor, @@ -367,7 +369,9 @@ static void lv_btnmatrix_constructor(const lv_obj_class_t * class_p, lv_obj_t * btnm->map_p = NULL; btnm->one_check = 0; +#if LV_WIDGETS_HAS_DEFAULT_VALUE lv_btnmatrix_set_map(obj, lv_btnmatrix_def_map); +#endif LV_TRACE_OBJ_CREATE("finished"); } diff --git a/src/widgets/calendar/lv_calendar.c b/src/widgets/calendar/lv_calendar.c index 2bab34b64..96c9439c6 100644 --- a/src/widgets/calendar/lv_calendar.c +++ b/src/widgets/calendar/lv_calendar.c @@ -243,6 +243,8 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o lv_calendar_t * calendar = (lv_calendar_t *)obj; /*Initialize the allocated 'ext'*/ + +#if LV_WIDGETS_HAS_DEFAULT_VALUE calendar->today.year = 2020; calendar->today.month = 1; calendar->today.day = 1; @@ -250,6 +252,7 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o calendar->showed_date.year = 2020; calendar->showed_date.month = 1; calendar->showed_date.day = 1; +#endif calendar->highlighted_dates = NULL; calendar->highlighted_dates_num = 0; @@ -282,8 +285,10 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN); lv_obj_set_flex_grow(calendar->btnm, 1); +#if LV_WIDGETS_HAS_DEFAULT_VALUE lv_calendar_set_showed_date(obj, calendar->showed_date.year, calendar->showed_date.month); lv_calendar_set_today_date(obj, calendar->today.year, calendar->today.month, calendar->today.day); +#endif lv_obj_add_flag(calendar->btnm, LV_OBJ_FLAG_EVENT_BUBBLE); } diff --git a/src/widgets/checkbox/lv_checkbox.c b/src/widgets/checkbox/lv_checkbox.c index 5d2b71daa..e5eed9b8d 100644 --- a/src/widgets/checkbox/lv_checkbox.c +++ b/src/widgets/checkbox/lv_checkbox.c @@ -132,8 +132,14 @@ static void lv_checkbox_constructor(const lv_obj_class_t * class_p, lv_obj_t * o lv_checkbox_t * cb = (lv_checkbox_t *)obj; +#if LV_WIDGETS_HAS_DEFAULT_VALUE cb->txt = (char *)"Check box"; cb->static_txt = 1; +#else + cb->txt = (char *)""; + cb->static_txt = 1; +#endif + lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE); lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE); lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); diff --git a/src/widgets/dropdown/lv_dropdown.c b/src/widgets/dropdown/lv_dropdown.c index e065becb3..4506883fa 100644 --- a/src/widgets/dropdown/lv_dropdown.c +++ b/src/widgets/dropdown/lv_dropdown.c @@ -598,7 +598,9 @@ static void lv_dropdown_constructor(const lv_obj_class_t * class_p, lv_obj_t * o dropdown->dir = LV_DIR_BOTTOM; lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); +#if LV_WIDGETS_HAS_DEFAULT_VALUE lv_dropdown_set_options_static(obj, "Option 1\nOption 2\nOption 3"); +#endif dropdown->list = lv_dropdown_list_create(lv_obj_get_screen(obj)); lv_dropdown_list_t * list = (lv_dropdown_list_t *)dropdown->list; diff --git a/src/widgets/label/lv_label.c b/src/widgets/label/lv_label.c index e881a080f..6fc8cd89f 100644 --- a/src/widgets/label/lv_label.c +++ b/src/widgets/label/lv_label.c @@ -663,7 +663,6 @@ static void lv_label_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj) lv_label_set_long_mode(obj, LV_LABEL_LONG_WRAP); lv_label_set_text(obj, LV_LABEL_DEFAULT_TEXT); - LV_TRACE_OBJ_CREATE("finished"); } diff --git a/src/widgets/label/lv_label.h b/src/widgets/label/lv_label.h index fde4c1611..897c352cf 100644 --- a/src/widgets/label/lv_label.h +++ b/src/widgets/label/lv_label.h @@ -31,7 +31,11 @@ extern "C" { #define LV_LABEL_DOT_NUM 3 #define LV_LABEL_POS_LAST 0xFFFF #define LV_LABEL_TEXT_SELECTION_OFF LV_DRAW_LABEL_NO_TXT_SEL +#if LV_WIDGETS_HAS_DEFAULT_VALUE #define LV_LABEL_DEFAULT_TEXT "Text" +#else +#define LV_LABEL_DEFAULT_TEXT "" +#endif LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM); LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST); diff --git a/src/widgets/roller/lv_roller.c b/src/widgets/roller/lv_roller.c index 38dd9d3af..99619362b 100644 --- a/src/widgets/roller/lv_roller.c +++ b/src/widgets/roller/lv_roller.c @@ -317,8 +317,9 @@ static void lv_roller_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj LV_LOG_INFO("begin"); lv_obj_t * label = lv_obj_class_create_obj(&lv_roller_label_class, obj); lv_obj_class_init_obj(label); +#if LV_WIDGETS_HAS_DEFAULT_VALUE lv_roller_set_options(obj, "Option 1\nOption 2\nOption 3\nOption 4\nOption 5", LV_ROLLER_MODE_NORMAL); - +#endif LV_LOG_TRACE("finshed"); } diff --git a/src/widgets/textarea/lv_textarea.c b/src/widgets/textarea/lv_textarea.c index e7c8792a0..73f6bd8da 100644 --- a/src/widgets/textarea/lv_textarea.c +++ b/src/widgets/textarea/lv_textarea.c @@ -848,6 +848,7 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o lv_obj_add_event(ta->label, label_event_cb, LV_EVENT_ALL, NULL); lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS); lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_WITH_ARROW); + lv_textarea_set_cursor_pos(obj, 0); start_cursor_blink(obj);