1
0
mirror of https://github.com/lvgl/lvgl.git synced 2025-01-28 07:03:00 +08:00

fix(calendar): fix crash when no default is set (#5621)

This commit is contained in:
PGNetHun 2024-02-12 19:14:43 +01:00 committed by GitHub
parent a3624f6e32
commit 3f3066ee2c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 11 additions and 9 deletions

View File

@ -245,15 +245,13 @@ static void lv_calendar_constructor(const lv_obj_class_t * class_p, lv_obj_t * o
/*Initialize the allocated 'ext'*/
#if LV_WIDGETS_HAS_DEFAULT_VALUE
calendar->today.year = 2020;
calendar->today.year = 2024;
calendar->today.month = 1;
calendar->today.day = 1;
calendar->showed_date.year = 2020;
calendar->showed_date.year = 2024;
calendar->showed_date.month = 1;
calendar->showed_date.day = 1;
#endif
calendar->highlighted_dates = NULL;
calendar->highlighted_dates_num = 0;
@ -287,11 +285,8 @@ 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
}
static void draw_task_added_event_cb(lv_event_t * e)

View File

@ -13,6 +13,7 @@
#include "../button/lv_button.h"
#include "../label/lv_label.h"
#include "../../layouts/flex/lv_flex.h"
#include "../../misc/lv_assert.h"
/*********************
* DEFINES
@ -111,6 +112,9 @@ static void month_event_cb(lv_event_t * e)
d = lv_calendar_get_showed_date(calendar);
lv_calendar_date_t newd = *d;
LV_ASSERT_FORMAT_MSG(newd.year >= 0 && newd.month >= 1 && newd.month <= 12,
"Invalid date: %d-%d", newd.year, newd.month);
/*The last child is the right button*/
if(lv_obj_get_child(header, 0) == btn) {
if(newd.month == 1) {
@ -142,9 +146,12 @@ static void value_changed_event_cb(lv_event_t * e)
lv_obj_t * header = lv_event_get_current_target(e);
lv_obj_t * calendar = lv_obj_get_parent(header);
const lv_calendar_date_t * cur_date = lv_calendar_get_showed_date(calendar);
const lv_calendar_date_t * date = lv_calendar_get_showed_date(calendar);
LV_ASSERT_FORMAT_MSG(date->year >= 0 && date->month >= 1 && date->month <= 12,
"Invalid date: %d-%d", date->year, date->month);
lv_obj_t * label = lv_obj_get_child(header, 1);
lv_label_set_text_fmt(label, "%d %s", cur_date->year, month_names_def[cur_date->month - 1]);
lv_label_set_text_fmt(label, "%d %s", date->year, month_names_def[date->month - 1]);
}
#endif /*LV_USE_CALENDAR_HEADER_ARROW*/

Binary file not shown.

Before

Width:  |  Height:  |  Size: 13 KiB

After

Width:  |  Height:  |  Size: 13 KiB