Skip to content

Commit 933db95

Browse files
authored
feat: add config set LV_WIDGETS_HAS_DEAFULT_VALUE (lvgl#4371)
Signed-off-by: yushuailong1 <[email protected]> Co-authored-by: yushuailong1 <[email protected]>
1 parent 2cdd413 commit 933db95

File tree

11 files changed

+41
-2
lines changed

11 files changed

+41
-2
lines changed

Kconfig

+3
Original file line numberDiff line numberDiff line change
@@ -775,6 +775,9 @@ menu "LVGL configuration"
775775
endmenu
776776

777777
menu "Widget usage"
778+
config LV_WIDGETS_HAS_DEFAULT_VALUE
779+
bool "Widgets has default value."
780+
default y if !LV_CONF_MINIMAL
778781
config LV_USE_ARC
779782
bool "Arc."
780783
default y if !LV_CONF_MINIMAL

lv_conf_template.h

+2
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,8 @@
409409

410410
/*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/
411411

412+
#define LV_WIDGETS_HAS_DEFAULT_VALUE 1
413+
412414
#define LV_USE_ANIMIMG 1
413415

414416
#define LV_USE_ARC 1

src/lv_conf_internal.h

+12
Original file line numberDiff line numberDiff line change
@@ -1167,6 +1167,18 @@
11671167

11681168
/*Documentation of the widgets: https://docs.lvgl.io/latest/en/html/widgets/index.html*/
11691169

1170+
#ifndef LV_WIDGETS_HAS_DEFAULT_VALUE
1171+
#ifdef _LV_KCONFIG_PRESENT
1172+
#ifdef CONFIG_LV_WIDGETS_HAS_DEFAULT_VALUE
1173+
#define LV_WIDGETS_HAS_DEFAULT_VALUE CONFIG_LV_WIDGETS_HAS_DEFAULT_VALUE
1174+
#else
1175+
#define LV_WIDGETS_HAS_DEFAULT_VALUE 0
1176+
#endif
1177+
#else
1178+
#define LV_WIDGETS_HAS_DEFAULT_VALUE 1
1179+
#endif
1180+
#endif
1181+
11701182
#ifndef LV_USE_ANIMIMG
11711183
#ifdef _LV_KCONFIG_PRESENT
11721184
#ifdef CONFIG_LV_USE_ANIMIMG

src/widgets/btnmatrix/lv_btnmatrix.c

+4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ static bool has_popovers_in_top_row(lv_obj_t * obj);
5757
/**********************
5858
* STATIC VARIABLES
5959
**********************/
60+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
6061
static const char * lv_btnmatrix_def_map[] = {"Btn1", "Btn2", "Btn3", "\n", "Btn4", "Btn5", ""};
62+
#endif
6163

6264
const lv_obj_class_t lv_btnmatrix_class = {
6365
.constructor_cb = lv_btnmatrix_constructor,
@@ -367,7 +369,9 @@ static void lv_btnmatrix_constructor(const lv_obj_class_t * class_p, lv_obj_t *
367369
btnm->map_p = NULL;
368370
btnm->one_check = 0;
369371

372+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
370373
lv_btnmatrix_set_map(obj, lv_btnmatrix_def_map);
374+
#endif
371375

372376
LV_TRACE_OBJ_CREATE("finished");
373377
}

src/widgets/calendar/lv_calendar.c

+5
Original file line numberDiff line numberDiff line change
@@ -243,13 +243,16 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
243243
lv_calendar_t * calendar = (lv_calendar_t *)obj;
244244

245245
/*Initialize the allocated 'ext'*/
246+
247+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
246248
calendar->today.year = 2020;
247249
calendar->today.month = 1;
248250
calendar->today.day = 1;
249251

250252
calendar->showed_date.year = 2020;
251253
calendar->showed_date.month = 1;
252254
calendar->showed_date.day = 1;
255+
#endif
253256

254257
calendar->highlighted_dates = NULL;
255258
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
282285
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
283286
lv_obj_set_flex_grow(calendar->btnm, 1);
284287

288+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
285289
lv_calendar_set_showed_date(obj, calendar->showed_date.year, calendar->showed_date.month);
286290
lv_calendar_set_today_date(obj, calendar->today.year, calendar->today.month, calendar->today.day);
291+
#endif
287292

288293
lv_obj_add_flag(calendar->btnm, LV_OBJ_FLAG_EVENT_BUBBLE);
289294
}

src/widgets/checkbox/lv_checkbox.c

+6
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,14 @@ static void lv_checkbox_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
132132

133133
lv_checkbox_t * cb = (lv_checkbox_t *)obj;
134134

135+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
135136
cb->txt = (char *)"Check box";
136137
cb->static_txt = 1;
138+
#else
139+
cb->txt = (char *)"";
140+
cb->static_txt = 1;
141+
#endif
142+
137143
lv_obj_add_flag(obj, LV_OBJ_FLAG_CLICKABLE);
138144
lv_obj_add_flag(obj, LV_OBJ_FLAG_CHECKABLE);
139145
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);

src/widgets/dropdown/lv_dropdown.c

+2
Original file line numberDiff line numberDiff line change
@@ -598,7 +598,9 @@ static void lv_dropdown_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
598598
dropdown->dir = LV_DIR_BOTTOM;
599599

600600
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
601+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
601602
lv_dropdown_set_options_static(obj, "Option 1\nOption 2\nOption 3");
603+
#endif
602604

603605
dropdown->list = lv_dropdown_list_create(lv_obj_get_screen(obj));
604606
lv_dropdown_list_t * list = (lv_dropdown_list_t *)dropdown->list;

src/widgets/label/lv_label.c

-1
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,6 @@ static void lv_label_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj)
663663
lv_label_set_long_mode(obj, LV_LABEL_LONG_WRAP);
664664
lv_label_set_text(obj, LV_LABEL_DEFAULT_TEXT);
665665

666-
667666
LV_TRACE_OBJ_CREATE("finished");
668667
}
669668

src/widgets/label/lv_label.h

+4
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,11 @@ extern "C" {
3131
#define LV_LABEL_DOT_NUM 3
3232
#define LV_LABEL_POS_LAST 0xFFFF
3333
#define LV_LABEL_TEXT_SELECTION_OFF LV_DRAW_LABEL_NO_TXT_SEL
34+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
3435
#define LV_LABEL_DEFAULT_TEXT "Text"
36+
#else
37+
#define LV_LABEL_DEFAULT_TEXT ""
38+
#endif
3539

3640
LV_EXPORT_CONST_INT(LV_LABEL_DOT_NUM);
3741
LV_EXPORT_CONST_INT(LV_LABEL_POS_LAST);

src/widgets/roller/lv_roller.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,9 @@ static void lv_roller_constructor(const lv_obj_class_t * class_p, lv_obj_t * obj
317317
LV_LOG_INFO("begin");
318318
lv_obj_t * label = lv_obj_class_create_obj(&lv_roller_label_class, obj);
319319
lv_obj_class_init_obj(label);
320+
#if LV_WIDGETS_HAS_DEFAULT_VALUE
320321
lv_roller_set_options(obj, "Option 1\nOption 2\nOption 3\nOption 4\nOption 5", LV_ROLLER_MODE_NORMAL);
321-
322+
#endif
322323
LV_LOG_TRACE("finshed");
323324
}
324325

src/widgets/textarea/lv_textarea.c

+1
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,7 @@ static void lv_textarea_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
848848
lv_obj_add_event(ta->label, label_event_cb, LV_EVENT_ALL, NULL);
849849
lv_obj_add_flag(obj, LV_OBJ_FLAG_SCROLL_ON_FOCUS);
850850
lv_obj_clear_flag(obj, LV_OBJ_FLAG_SCROLL_WITH_ARROW);
851+
851852
lv_textarea_set_cursor_pos(obj, 0);
852853

853854
start_cursor_blink(obj);

0 commit comments

Comments
 (0)