Merge pull request #460 from ali-rostami/master
action functions for calendar object
This commit is contained in:
@@ -138,6 +138,7 @@ void lv_group_remove_obj(lv_obj_t * obj)
|
||||
lv_ll_rem(&g->obj_ll, i);
|
||||
lv_mem_free(i);
|
||||
obj->group_p = NULL;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,6 +154,9 @@ void lv_group_focus_obj(lv_obj_t * obj)
|
||||
|
||||
if(g->frozen != 0) return;
|
||||
|
||||
/*On defocus edit mode must be leaved*/
|
||||
lv_group_set_editing(g, false);
|
||||
|
||||
lv_obj_t ** i;
|
||||
LL_READ(g->obj_ll, i) {
|
||||
if(*i == obj) {
|
||||
@@ -294,8 +298,15 @@ void lv_group_set_focus_cb(lv_group_t * group, lv_group_focus_cb_t focus_cb)
|
||||
*/
|
||||
void lv_group_set_editing(lv_group_t * group, bool edit)
|
||||
{
|
||||
group->editing = edit ? 1 : 0;
|
||||
uint8_t en_val = edit ? 1 : 0;
|
||||
|
||||
if(en_val == group->editing) return; /*Do not set the same mode again*/
|
||||
|
||||
group->editing = en_val;
|
||||
lv_obj_t * focused = lv_group_get_focused(group);
|
||||
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave edit mode*/
|
||||
|
||||
lv_obj_invalidate(focused);
|
||||
}
|
||||
|
||||
|
||||
@@ -384,11 +384,7 @@ static void indev_keypad_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
/* Edit mode is not used by KEYPAD devices.
|
||||
* So leave edit mode if we are in it before focusing on the next/prev object*/
|
||||
if(data->key == LV_GROUP_KEY_NEXT || data->key == LV_GROUP_KEY_PREV) {
|
||||
if(lv_group_get_editing(i->group)) {
|
||||
lv_group_set_editing(i->group, false);
|
||||
lv_obj_t * focused = lv_group_get_focused(i->group);
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave edit mode*/
|
||||
}
|
||||
lv_group_set_editing(i->group, false);
|
||||
}
|
||||
|
||||
if(data->key == LV_GROUP_KEY_NEXT) {
|
||||
@@ -465,10 +461,7 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_GET_EDITABLE, &editable);
|
||||
|
||||
if(editable) {
|
||||
i->group->editing = i->group->editing ? 0 : 1;
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again. Some object do something on navigate->edit change*/
|
||||
LV_LOG_INFO("Edit mode changed");
|
||||
if(focused) lv_obj_invalidate(focused);
|
||||
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
|
||||
}
|
||||
/*If not editable then just send a long press signal*/
|
||||
else {
|
||||
@@ -493,10 +486,7 @@ static void indev_encoder_proc(lv_indev_t * i, lv_indev_data_t * data)
|
||||
}
|
||||
/*If the focused object is editable and now in navigate mode then enter edit mode*/
|
||||
else if(editable && !i->group->editing && !i->proc.long_pr_sent) {
|
||||
i->group->editing = i->group->editing ? 0 : 1;
|
||||
if(focused) focused->signal_func(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again. Some object do something on navigate->edit change*/
|
||||
LV_LOG_INFO("Edit mode changed (edit)");
|
||||
if(focused) lv_obj_invalidate(focused);
|
||||
lv_group_set_editing(i->group, lv_group_get_editing(i->group) ? false : true); /*Toggle edit mode on long press*/
|
||||
}
|
||||
|
||||
if(i->proc.reset_query) return; /*The object might be deleted in `focus_cb` or due to any other user event*/
|
||||
@@ -690,13 +680,15 @@ static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
else {
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_RELEASED, indev_act);
|
||||
}
|
||||
|
||||
if(proc->reset_query != 0) return;
|
||||
|
||||
/*Handle click focus*/
|
||||
#if USE_LV_GROUP
|
||||
/*Edit mode is not used by POINTER devices. So leave edit mode if we are in it*/
|
||||
lv_group_t * act_g = lv_obj_get_group(proc->act_obj);
|
||||
if(lv_group_get_editing(act_g)) {
|
||||
lv_group_set_editing(act_g, false);
|
||||
proc->act_obj->signal_func(proc->act_obj, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave edit mode*/
|
||||
}
|
||||
|
||||
/*Check, if the parent is in a group focus on it.*/
|
||||
|
||||
@@ -266,6 +266,7 @@ static bool anim_ready_handler(lv_anim_t * a)
|
||||
void * p = a->var;
|
||||
lv_ll_rem(&anim_ll, a);
|
||||
lv_mem_free(a);
|
||||
anim_list_changed = true;
|
||||
|
||||
/* Call the callback function at the end*/
|
||||
/* Check if an animation is deleted in the cb function
|
||||
|
||||
@@ -31,6 +31,7 @@ static bool lv_task_exec(lv_task_t * lv_task_p);
|
||||
static lv_ll_t lv_task_ll; /*Linked list to store the lv_tasks*/
|
||||
static bool lv_task_run = false;
|
||||
static uint8_t idle_last = 0;
|
||||
static bool task_deleted;
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -197,6 +198,8 @@ void lv_task_del(lv_task_t * lv_task_p)
|
||||
lv_ll_rem(&lv_task_ll, lv_task_p);
|
||||
|
||||
lv_mem_free(lv_task_p);
|
||||
|
||||
task_deleted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -298,11 +301,13 @@ static bool lv_task_exec(lv_task_t * lv_task_p)
|
||||
uint32_t elp = lv_tick_elaps(lv_task_p->last_run);
|
||||
if(elp >= lv_task_p->period) {
|
||||
lv_task_p->last_run = lv_tick_get();
|
||||
task_deleted = false;
|
||||
lv_task_p->task(lv_task_p->param);
|
||||
|
||||
/*Delete if it was a one shot lv_task*/
|
||||
if(lv_task_p->once != 0) lv_task_del(lv_task_p);
|
||||
|
||||
if(task_deleted == false) { /*The task might be deleted by itself as well*/
|
||||
if(lv_task_p->once != 0) lv_task_del(lv_task_p);
|
||||
}
|
||||
exec = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -541,7 +541,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
if(txt_i != LV_BTNM_PR_NONE) {
|
||||
if(button_is_repeat_disabled(ext->map_p[txt_i]) == false &&
|
||||
button_is_inactive(ext->map_p[txt_i]) == false) {
|
||||
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -549,39 +549,41 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
if(ext->btn_id_pr != LV_BTNM_PR_NONE) {
|
||||
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
|
||||
if(button_is_inactive(ext->map_p[txt_i]) == false && txt_i != LV_BTNM_PR_NONE) { /*Ignore the inactive buttons anf click between the buttons*/
|
||||
if(ext->action)ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
if(ext->action) res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
if(res == LV_RES_OK) {
|
||||
|
||||
/*Invalidate to old pressed area*/;
|
||||
lv_obj_get_coords(btnm, &btnm_area);
|
||||
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]);
|
||||
btn_area.x1 += btnm_area.x1;
|
||||
btn_area.y1 += btnm_area.y1;
|
||||
btn_area.x2 += btnm_area.x1;
|
||||
btn_area.y2 += btnm_area.y1;
|
||||
lv_inv_area(&btn_area);
|
||||
/*Invalidate to old pressed area*/;
|
||||
lv_obj_get_coords(btnm, &btnm_area);
|
||||
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_pr]);
|
||||
btn_area.x1 += btnm_area.x1;
|
||||
btn_area.y1 += btnm_area.y1;
|
||||
btn_area.x2 += btnm_area.x1;
|
||||
btn_area.y2 += btnm_area.y1;
|
||||
lv_inv_area(&btn_area);
|
||||
|
||||
if(ext->toggle != 0) {
|
||||
/*Invalidate to old toggled area*/;
|
||||
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]);
|
||||
btn_area.x1 += btnm_area.x1;
|
||||
btn_area.y1 += btnm_area.y1;
|
||||
btn_area.x2 += btnm_area.x1;
|
||||
btn_area.y2 += btnm_area.y1;
|
||||
lv_inv_area(&btn_area);
|
||||
ext->btn_id_tgl = ext->btn_id_pr;
|
||||
if(ext->toggle != 0) {
|
||||
/*Invalidate to old toggled area*/;
|
||||
lv_area_copy(&btn_area, &ext->button_areas[ext->btn_id_tgl]);
|
||||
btn_area.x1 += btnm_area.x1;
|
||||
btn_area.y1 += btnm_area.y1;
|
||||
btn_area.x2 += btnm_area.x1;
|
||||
btn_area.y2 += btnm_area.y1;
|
||||
lv_inv_area(&btn_area);
|
||||
ext->btn_id_tgl = ext->btn_id_pr;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#if USE_LV_GROUP
|
||||
/*Leave the clicked button as pressed if this the focused object in a group*/
|
||||
lv_group_t * g = lv_obj_get_group(btnm);
|
||||
if(lv_group_get_focused(g) != btnm) {
|
||||
ext->btn_id_pr = LV_BTNM_PR_NONE;
|
||||
}
|
||||
#else
|
||||
ext->btn_id_pr = LV_BTNM_PR_NONE;
|
||||
#endif
|
||||
#if USE_LV_GROUP
|
||||
/*Leave the clicked button as pressed if this the focused object in a group*/
|
||||
lv_group_t * g = lv_obj_get_group(btnm);
|
||||
if(lv_group_get_focused(g) != btnm) {
|
||||
ext->btn_id_pr = LV_BTNM_PR_NONE;
|
||||
}
|
||||
#else
|
||||
ext->btn_id_pr = LV_BTNM_PR_NONE;
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESS_LOST || sign == LV_SIGNAL_DEFOCUS) {
|
||||
@@ -663,7 +665,7 @@ static lv_res_t lv_btnm_signal(lv_obj_t * btnm, lv_signal_t sign, void * param)
|
||||
if(ext->action != NULL) {
|
||||
uint16_t txt_i = get_button_text(btnm, ext->btn_id_pr);
|
||||
if(txt_i != LV_BTNM_PR_NONE) {
|
||||
ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
res = ext->action(btnm, cut_ctrl_byte(ext->map_p[txt_i]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,9 @@ typedef uint8_t day_draw_state_t;
|
||||
**********************/
|
||||
static bool lv_calendar_design(lv_obj_t * calendar, const lv_area_t * mask, lv_design_mode_t mode);
|
||||
static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void * param);
|
||||
static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touched_point);
|
||||
static lv_coord_t get_header_height(lv_obj_t * calendar);
|
||||
static lv_coord_t get_day_names_height(lv_obj_t * calendar);
|
||||
static void draw_header(lv_obj_t * calendar, const lv_area_t * mask);
|
||||
static void draw_day_names(lv_obj_t * calendar, const lv_area_t * mask);
|
||||
static void draw_days(lv_obj_t * calendar, const lv_area_t * mask);
|
||||
@@ -45,6 +47,7 @@ static const char * get_month_name(lv_obj_t * calendar, int32_t month);
|
||||
static uint8_t get_month_length(int32_t year, int32_t month);
|
||||
static uint8_t is_leap_year(uint32_t year);
|
||||
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
@@ -52,9 +55,9 @@ static lv_signal_func_t ancestor_signal;
|
||||
static lv_design_func_t ancestor_design;
|
||||
static const char * day_name[7] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa"};
|
||||
static const char * month_name[12] = {"January", "February", "March", "April",
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December"
|
||||
};
|
||||
"May", "June", "July", "August",
|
||||
"September", "October", "November", "December"
|
||||
};
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
@@ -95,10 +98,18 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->showed_date.month = 1;
|
||||
ext->showed_date.day = 1;
|
||||
|
||||
ext->pressed_date.year = 0;
|
||||
ext->pressed_date.month = 0;
|
||||
ext->pressed_date.day = 0;
|
||||
|
||||
ext->highlighted_dates = NULL;
|
||||
ext->highlighted_dates_num = 0;
|
||||
ext->day_names = NULL;
|
||||
ext->month_names = NULL;
|
||||
ext->actions[LV_CALENDAR_ACTION_PR] = NULL;
|
||||
ext->actions[LV_CALENDAR_ACTION_CLICK] = NULL;
|
||||
ext->actions[LV_CALENDAR_ACTION_LONG_PR] = NULL;
|
||||
ext->actions[LV_CALENDAR_ACTION_LONG_PR_REPEAT] = NULL;
|
||||
ext->style_header = &lv_style_plain_color;
|
||||
ext->style_header_pr = &lv_style_pretty_color;
|
||||
ext->style_highlighted_days = &lv_style_plain_color;
|
||||
@@ -153,6 +164,9 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
ext->highlighted_dates = copy_ext->highlighted_dates;
|
||||
ext->highlighted_dates_num = copy_ext->highlighted_dates_num;
|
||||
ext->day_names = copy_ext->day_names;
|
||||
|
||||
memcpy(ext->actions, copy_ext->actions, sizeof(ext->actions));
|
||||
|
||||
ext->month_names = copy_ext->month_names;
|
||||
ext->style_header = copy_ext->style_header;
|
||||
ext->style_header_pr = copy_ext->style_header_pr;
|
||||
@@ -183,6 +197,19 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
* Setter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Set a function to call when a calendar event happens
|
||||
* @param calendar pointer to a calendar object
|
||||
* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)
|
||||
*/
|
||||
void lv_calendar_set_action(lv_obj_t * calendar, lv_calendar_action_t type, lv_action_t action)
|
||||
{
|
||||
if(type >= LV_CALENDAR_ACTION_NUM) return;
|
||||
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
ext->actions[type] = action;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the today's date
|
||||
* @param calendar pointer to a calendar object
|
||||
@@ -266,30 +293,30 @@ void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_sty
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
|
||||
switch(type) {
|
||||
case LV_CALENDAR_STYLE_BG:
|
||||
lv_obj_set_style(calendar, style);
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_DAY_NAMES:
|
||||
ext->style_day_names = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_HEADER:
|
||||
ext->style_header = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_HEADER_PR:
|
||||
ext->style_header_pr = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS:
|
||||
ext->style_highlighted_days = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_INACTIVE_DAYS:
|
||||
ext->style_inactive_days = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_TODAY_BOX:
|
||||
ext->style_today_box = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_WEEK_BOX:
|
||||
ext->style_week_box = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_BG:
|
||||
lv_obj_set_style(calendar, style);
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_DAY_NAMES:
|
||||
ext->style_day_names = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_HEADER:
|
||||
ext->style_header = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_HEADER_PR:
|
||||
ext->style_header_pr = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS:
|
||||
ext->style_highlighted_days = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_INACTIVE_DAYS:
|
||||
ext->style_inactive_days = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_TODAY_BOX:
|
||||
ext->style_today_box = style;
|
||||
break;
|
||||
case LV_CALENDAR_STYLE_WEEK_BOX:
|
||||
ext->style_week_box = style;
|
||||
break;
|
||||
}
|
||||
|
||||
lv_obj_invalidate(calendar);
|
||||
@@ -299,6 +326,18 @@ void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_sty
|
||||
* Getter functions
|
||||
*====================*/
|
||||
|
||||
/**
|
||||
* Get the action of a calendar
|
||||
* @param calendar pointer to a calendar object
|
||||
* @return pointer to the action function
|
||||
*/
|
||||
lv_action_t lv_calendar_get_action(const lv_obj_t * calendar, lv_calendar_action_t type)
|
||||
{
|
||||
if(type >= LV_CALENDAR_ACTION_NUM) return NULL;
|
||||
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
return ext->actions[type];
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the today's date
|
||||
@@ -322,6 +361,17 @@ lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar)
|
||||
return &ext->showed_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the the pressed date.
|
||||
* @param calendar pointer to a calendar object
|
||||
* @return pointer to an `lv_calendar_date_t` variable containing the pressed date.
|
||||
*/
|
||||
lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar)
|
||||
{
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
return &ext->pressed_date;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the the highlighted dates
|
||||
* @param calendar pointer to a calendar object
|
||||
@@ -377,24 +427,24 @@ lv_style_t * lv_calendar_get_style(const lv_obj_t * calendar, lv_calendar_style_
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
|
||||
switch(type) {
|
||||
case LV_CALENDAR_STYLE_BG:
|
||||
return lv_obj_get_style(calendar);
|
||||
case LV_CALENDAR_STYLE_HEADER:
|
||||
return ext->style_header;
|
||||
case LV_CALENDAR_STYLE_HEADER_PR:
|
||||
return ext->style_header_pr;
|
||||
case LV_CALENDAR_STYLE_DAY_NAMES:
|
||||
return ext->style_day_names;
|
||||
case LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS:
|
||||
return ext->style_highlighted_days;
|
||||
case LV_CALENDAR_STYLE_INACTIVE_DAYS:
|
||||
return ext->style_inactive_days;
|
||||
case LV_CALENDAR_STYLE_WEEK_BOX:
|
||||
return ext->style_week_box;
|
||||
case LV_CALENDAR_STYLE_TODAY_BOX:
|
||||
return ext->style_today_box;
|
||||
default:
|
||||
return NULL;
|
||||
case LV_CALENDAR_STYLE_BG:
|
||||
return lv_obj_get_style(calendar);
|
||||
case LV_CALENDAR_STYLE_HEADER:
|
||||
return ext->style_header;
|
||||
case LV_CALENDAR_STYLE_HEADER_PR:
|
||||
return ext->style_header_pr;
|
||||
case LV_CALENDAR_STYLE_DAY_NAMES:
|
||||
return ext->style_day_names;
|
||||
case LV_CALENDAR_STYLE_HIGHLIGHTED_DAYS:
|
||||
return ext->style_highlighted_days;
|
||||
case LV_CALENDAR_STYLE_INACTIVE_DAYS:
|
||||
return ext->style_inactive_days;
|
||||
case LV_CALENDAR_STYLE_WEEK_BOX:
|
||||
return ext->style_week_box;
|
||||
case LV_CALENDAR_STYLE_TODAY_BOX:
|
||||
return ext->style_today_box;
|
||||
default:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*To avoid warning*/
|
||||
@@ -465,11 +515,26 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
|
||||
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
/*Nothing to cleanup. (No dynamically allocated memory in 'ext')*/
|
||||
} else if(sign == LV_SIGNAL_PRESSED) {
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
/*Call the press action, 'param' is the caller indev_proc*/
|
||||
if(ext->actions[LV_CALENDAR_ACTION_PR]) {
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
lv_point_t p;
|
||||
lv_indev_get_point(indev, &p);
|
||||
|
||||
if(calculate_touched_day(calendar, &p)){
|
||||
if(ext->btn_pressing != 0) lv_obj_invalidate(calendar);
|
||||
ext->btn_pressing = 0;
|
||||
res = ext->actions[LV_CALENDAR_ACTION_PR](calendar);
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESSING) {
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
lv_area_t header_area;
|
||||
lv_area_copy(&header_area, &calendar->coords);
|
||||
header_area.y2 = header_area.y1 + get_header_height(calendar);
|
||||
|
||||
lv_indev_t * indev = lv_indev_get_act();
|
||||
lv_point_t p;
|
||||
lv_indev_get_point(indev, &p);
|
||||
@@ -482,14 +547,22 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
|
||||
if(ext->btn_pressing != 1) lv_obj_invalidate(calendar);
|
||||
ext->btn_pressing = 1;
|
||||
}
|
||||
|
||||
ext->pressed_date.year = 0;
|
||||
} else if(calculate_touched_day(calendar, &p)) {
|
||||
if(ext->btn_pressing != 0) lv_obj_invalidate(calendar);
|
||||
ext->btn_pressing = 0;
|
||||
} else {
|
||||
if(ext->btn_pressing != 0) lv_obj_invalidate(calendar);
|
||||
ext->btn_pressing = 0;
|
||||
ext->pressed_date.year = 0;
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESS_LOST) {
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
ext->pressed_date.year = 0;
|
||||
ext->btn_pressing = 0;
|
||||
lv_obj_invalidate(calendar);
|
||||
|
||||
} else if(sign == LV_SIGNAL_RELEASED) {
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
if(ext->btn_pressing < 0) {
|
||||
@@ -507,10 +580,28 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
|
||||
ext->showed_date.month ++;
|
||||
}
|
||||
}
|
||||
else if(ext->pressed_date.year != 0)
|
||||
{
|
||||
if(ext->actions[LV_CALENDAR_ACTION_CLICK]) {
|
||||
res = ext->actions[LV_CALENDAR_ACTION_CLICK](calendar);
|
||||
}
|
||||
}
|
||||
|
||||
ext->pressed_date.year = 0;
|
||||
ext->btn_pressing = 0;
|
||||
lv_obj_invalidate(calendar);
|
||||
|
||||
|
||||
} else if(sign == LV_SIGNAL_LONG_PRESS) {
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
if(ext->actions[LV_CALENDAR_ACTION_LONG_PR] && (ext->pressed_date.year != 0)) {
|
||||
res = ext->actions[LV_CALENDAR_ACTION_LONG_PR](calendar);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_LONG_PRESS_REP) {
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
if(ext->actions[LV_CALENDAR_ACTION_LONG_PR_REPEAT] && (ext->pressed_date.year != 0)) {
|
||||
res = ext->actions[LV_CALENDAR_ACTION_LONG_PR_REPEAT](calendar);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
uint8_t c = *((uint8_t *) param);
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
@@ -543,6 +634,60 @@ static lv_res_t lv_calendar_signal(lv_obj_t * calendar, lv_signal_t sign, void *
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* It will check if the days part of calendar is touched
|
||||
* and if it is, it will calculate the day and put it in pressed_date of calendar object.
|
||||
* @param calendar pointer to a calendar object
|
||||
* @param pointer to a point
|
||||
* @return true: days part of calendar is touched and its related date is put in pressed date
|
||||
* false: the point is out of days part area.
|
||||
*/
|
||||
static bool calculate_touched_day(lv_obj_t * calendar, const lv_point_t * touched_point)
|
||||
{
|
||||
lv_area_t days_area;
|
||||
lv_area_copy(&days_area, &calendar->coords);
|
||||
lv_style_t * style_bg = lv_calendar_get_style(calendar, LV_CALENDAR_STYLE_BG);
|
||||
days_area.x1 += style_bg->body.padding.hor;
|
||||
days_area.x2 -= style_bg->body.padding.hor;
|
||||
days_area.y1 = calendar->coords.y1 + get_header_height(calendar) + get_day_names_height(calendar) - style_bg->body.padding.ver;
|
||||
|
||||
if(lv_area_is_point_on(&days_area, touched_point)) {
|
||||
lv_coord_t w = (days_area.x2 - days_area.x1 + 1) / 7;
|
||||
lv_coord_t h = (days_area.y2 - days_area.y1 + 1) / 6;
|
||||
uint8_t x_pos = 0;
|
||||
x_pos = (touched_point->x - days_area.x1) / w;
|
||||
if(x_pos > 6) x_pos = 6;
|
||||
uint8_t y_pos = 0;
|
||||
y_pos = (touched_point->y - days_area.y1) / h;
|
||||
if(y_pos > 5) y_pos = 5;
|
||||
|
||||
uint8_t i_pos = 0;
|
||||
i_pos = (y_pos * 7) + x_pos;
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
if(i_pos < get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) ) {
|
||||
ext->pressed_date.year = ext->showed_date.year - (ext->showed_date.month == 1 ? 1 : 0);
|
||||
ext->pressed_date.month = ext->showed_date.month == 1 ? 12 : (ext->showed_date.month - 1);
|
||||
ext->pressed_date.day = get_month_length(ext->pressed_date.year, ext->pressed_date.month) -
|
||||
get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) + 1 + i_pos;
|
||||
}
|
||||
else if(i_pos < (get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1) +
|
||||
get_month_length(ext->showed_date.year, ext->showed_date.month))) {
|
||||
ext->pressed_date.year = ext->showed_date.year;
|
||||
ext->pressed_date.month = ext->showed_date.month;
|
||||
ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1);
|
||||
}
|
||||
else if(i_pos < 42) {
|
||||
ext->pressed_date.year = ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0);
|
||||
ext->pressed_date.month = ext->showed_date.month == 12 ? 1 : (ext->showed_date.month + 1);
|
||||
ext->pressed_date.day = i_pos + 1 - get_day_of_week(ext->showed_date.year, ext->showed_date.month, 1)
|
||||
- get_month_length(ext->showed_date.year, ext->showed_date.month);
|
||||
}
|
||||
return true;
|
||||
}else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of a calendar's header based on it's style
|
||||
* @param calendar point to a calendar
|
||||
@@ -555,6 +700,18 @@ static lv_coord_t get_header_height(lv_obj_t * calendar)
|
||||
return lv_font_get_height(ext->style_header->text.font) + ext->style_header->body.padding.ver * 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the height of a calendar's day_names based on it's style
|
||||
* @param calendar point to a calendar
|
||||
* @return the day_names's height
|
||||
*/
|
||||
static lv_coord_t get_day_names_height(lv_obj_t * calendar)
|
||||
{
|
||||
lv_calendar_ext_t * ext = lv_obj_get_ext_attr(calendar);
|
||||
|
||||
return lv_font_get_height(ext->style_day_names->text.font) + ext->style_day_names->body.padding.ver * 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the calendar header with month name and arrows
|
||||
* @param calendar point to a calendar
|
||||
@@ -590,8 +747,8 @@ static void draw_header(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
/*Add the right arrow*/
|
||||
arrow_style = ext->btn_pressing > 0 ? ext->style_header_pr : ext->style_header;
|
||||
header_area.x1 = header_area.x2 - ext->style_header->body.padding.hor -
|
||||
lv_txt_get_width(SYMBOL_RIGHT, 1, arrow_style->text.font,
|
||||
arrow_style->text.line_space, LV_TXT_FLAG_NONE);
|
||||
lv_txt_get_width(SYMBOL_RIGHT, 1, arrow_style->text.font,
|
||||
arrow_style->text.line_space, LV_TXT_FLAG_NONE);
|
||||
lv_draw_label(&header_area, mask, arrow_style, opa_scale, SYMBOL_RIGHT, LV_TXT_FLAG_NONE, NULL);
|
||||
|
||||
}
|
||||
@@ -634,8 +791,8 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_area_t label_area;
|
||||
lv_opa_t opa_scale = lv_obj_get_opa_scale(calendar);
|
||||
label_area.y1 = calendar->coords.y1 + get_header_height(calendar) +
|
||||
ext->style_day_names->body.padding.ver + lv_font_get_height(ext->style_day_names->text.font) +
|
||||
style_bg->body.padding.inner;
|
||||
ext->style_day_names->body.padding.ver + lv_font_get_height(ext->style_day_names->text.font) +
|
||||
style_bg->body.padding.inner;
|
||||
label_area.y2 = label_area.y1 + lv_font_get_height(style_bg->text.font);
|
||||
|
||||
lv_coord_t w = lv_obj_get_width(calendar) - 2 * hpad;
|
||||
@@ -677,7 +834,7 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
/*Draw the "week box"*/
|
||||
if(month_of_today_shown &&
|
||||
((draw_state == DAY_DRAW_ACT_MONTH && ext->today.day >= day_cnt && ext->today.day < day_cnt + 7) ||
|
||||
(draw_state == DAY_DRAW_PREV_MONTH && ext->today.day <= 7 - month_start_day && week == 0))) {
|
||||
(draw_state == DAY_DRAW_PREV_MONTH && ext->today.day <= 7 - month_start_day && week == 0))) {
|
||||
lv_area_t week_box_area;
|
||||
lv_area_copy(&week_box_area, &label_area); /*'label_area' is already set for this row*/
|
||||
week_box_area.x1 = calendar->coords.x1 + style_bg->body.padding.hor - ext->style_week_box->body.padding.hor;
|
||||
@@ -728,18 +885,18 @@ static void draw_days(lv_obj_t * calendar, const lv_area_t * mask)
|
||||
lv_style_t * final_style;
|
||||
if(draw_state == DAY_DRAW_PREV_MONTH &&
|
||||
is_highlighted(calendar, ext->showed_date.year - (ext->showed_date.month == 1 ? 1 : 0),
|
||||
ext->showed_date.month == 1 ? 12 : ext->showed_date.month - 1,
|
||||
day_cnt)) {
|
||||
ext->showed_date.month == 1 ? 12 : ext->showed_date.month - 1,
|
||||
day_cnt)) {
|
||||
final_style = ext->style_highlighted_days;
|
||||
} else if(draw_state == DAY_DRAW_ACT_MONTH &&
|
||||
is_highlighted(calendar, ext->showed_date.year,
|
||||
ext->showed_date.month,
|
||||
day_cnt)) {
|
||||
is_highlighted(calendar, ext->showed_date.year,
|
||||
ext->showed_date.month,
|
||||
day_cnt)) {
|
||||
final_style = ext->style_highlighted_days;
|
||||
} else if(draw_state == DAY_DRAW_NEXT_MONTH &&
|
||||
is_highlighted(calendar, ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0),
|
||||
ext->showed_date.month == 12 ? 1 : ext->showed_date.month + 1,
|
||||
day_cnt)) {
|
||||
is_highlighted(calendar, ext->showed_date.year + (ext->showed_date.month == 12 ? 1 : 0),
|
||||
ext->showed_date.month == 12 ? 1 : ext->showed_date.month + 1,
|
||||
day_cnt)) {
|
||||
final_style = ext->style_highlighted_days;
|
||||
} else if(month_of_today_shown && day_cnt == ext->today.day && draw_state == DAY_DRAW_ACT_MONTH) final_style = ext->style_today_box;
|
||||
else if(in_week_box && draw_state == DAY_DRAW_ACT_MONTH) final_style = ext->style_week_box;
|
||||
@@ -863,7 +1020,7 @@ static uint8_t get_day_of_week(uint32_t year, uint32_t month, uint32_t day)
|
||||
uint32_t b = year - a;
|
||||
|
||||
uint32_t day_of_week = (day + (31 * (month - 2 + 12 * a) / 12) +
|
||||
b + (b / 4) - (b / 100) + (b / 400)) % 7;
|
||||
b + (b / 4) - (b / 100) + (b / 400)) % 7;
|
||||
|
||||
return day_of_week;
|
||||
}
|
||||
|
||||
@@ -37,6 +37,16 @@ typedef struct {
|
||||
int8_t day;
|
||||
} lv_calendar_date_t;
|
||||
|
||||
enum
|
||||
{
|
||||
LV_CALENDAR_ACTION_CLICK,
|
||||
LV_CALENDAR_ACTION_PR,
|
||||
LV_CALENDAR_ACTION_LONG_PR,
|
||||
LV_CALENDAR_ACTION_LONG_PR_REPEAT,
|
||||
LV_CALENDAR_ACTION_NUM,
|
||||
};
|
||||
typedef uint8_t lv_calendar_action_t;
|
||||
|
||||
/*Data of calendar*/
|
||||
typedef struct {
|
||||
/*None*/ /*Ext. of ancestor*/
|
||||
@@ -46,8 +56,10 @@ typedef struct {
|
||||
lv_calendar_date_t * highlighted_dates; /*Apply different style on these days (pointer to an array defined by the user)*/
|
||||
uint8_t highlighted_dates_num; /*Number of elements in `highlighted_days`*/
|
||||
int8_t btn_pressing; /*-1: prev month pressing, +1 next month pressing on the header*/
|
||||
lv_calendar_date_t pressed_date;
|
||||
const char ** day_names; /*Pointer to an array with the name of the days (NULL: use default names)*/
|
||||
const char ** month_names; /*Pointer to an array with the name of the month (NULL. use default names)*/
|
||||
lv_action_t actions[LV_CALENDAR_ACTION_NUM];
|
||||
|
||||
/*Styles*/
|
||||
lv_style_t * style_header;
|
||||
@@ -74,6 +86,7 @@ typedef uint8_t lv_calendar_style_t;
|
||||
|
||||
|
||||
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
@@ -94,6 +107,12 @@ lv_obj_t * lv_calendar_create(lv_obj_t * par, const lv_obj_t * copy);
|
||||
/*=====================
|
||||
* Setter functions
|
||||
*====================*/
|
||||
/**
|
||||
* Set a function to call when a calendar event happens
|
||||
* @param calendar pointer to a calendar object
|
||||
* @param action type of event form 'lv_action_t' (press, release, long press, long press repeat)
|
||||
*/
|
||||
void lv_calendar_set_action(lv_obj_t * calendar, lv_calendar_action_t type, lv_action_t action);
|
||||
|
||||
/**
|
||||
* Set the today's date
|
||||
@@ -145,6 +164,12 @@ void lv_calendar_set_style(lv_obj_t * calendar, lv_calendar_style_t type, lv_sty
|
||||
/*=====================
|
||||
* Getter functions
|
||||
*====================*/
|
||||
/**
|
||||
* Get the action of a calendar
|
||||
* @param calendar pointer to a calendar object
|
||||
* @return pointer to the action function
|
||||
*/
|
||||
lv_action_t lv_calendar_get_action(const lv_obj_t * calendar, lv_calendar_action_t type);
|
||||
|
||||
/**
|
||||
* Get the today's date
|
||||
@@ -160,6 +185,13 @@ lv_calendar_date_t * lv_calendar_get_today_date(const lv_obj_t * calendar);
|
||||
*/
|
||||
lv_calendar_date_t * lv_calendar_get_showed_date(const lv_obj_t * calendar);
|
||||
|
||||
/**
|
||||
* Get the the pressed date.
|
||||
* @param calendar pointer to a calendar object
|
||||
* @return pointer to an `lv_calendar_date_t` variable containing the pressed date.
|
||||
*/
|
||||
lv_calendar_date_t * lv_calendar_get_pressed_date(const lv_obj_t * calendar);
|
||||
|
||||
/**
|
||||
* Get the the highlighted dates
|
||||
* @param calendar pointer to a calendar object
|
||||
|
||||
@@ -588,17 +588,19 @@ static lv_res_t lv_ddlist_signal(lv_obj_t * ddlist, lv_signal_t sign, void * par
|
||||
if(ext->opened) {
|
||||
ext->sel_opt_id_ori = ext->sel_opt_id;
|
||||
ext->opened = 0;
|
||||
if(ext->action) ext->action(ddlist);
|
||||
if(ext->action) res = ext->action(ddlist);
|
||||
#if USE_LV_GROUP
|
||||
lv_group_t * g = lv_obj_get_group(ddlist);
|
||||
bool editing = lv_group_get_editing(g);
|
||||
if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/
|
||||
if(res == LV_RES_OK) {
|
||||
lv_group_t * g = lv_obj_get_group(ddlist);
|
||||
bool editing = lv_group_get_editing(g);
|
||||
if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
ext->opened = 1;
|
||||
}
|
||||
|
||||
lv_ddlist_refr_size(ddlist, true);
|
||||
if(res == LV_RES_OK) lv_ddlist_refr_size(ddlist, true);
|
||||
} else if(c == LV_GROUP_KEY_ESC) {
|
||||
if(ext->opened) {
|
||||
ext->opened = 0;
|
||||
@@ -658,6 +660,7 @@ static lv_res_t lv_ddlist_scrl_signal(lv_obj_t * scrl, lv_signal_t sign, void *
|
||||
static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
lv_res_t res = LV_RES_OK;
|
||||
|
||||
if(ext->opened == 0) { /*Open the list*/
|
||||
ext->opened = 1;
|
||||
@@ -688,12 +691,13 @@ static lv_res_t lv_ddlist_release_action(lv_obj_t * ddlist)
|
||||
ext->sel_opt_id = new_opt;
|
||||
|
||||
if(ext->action != NULL) {
|
||||
ext->action(ddlist);
|
||||
res = ext->action(ddlist);
|
||||
}
|
||||
}
|
||||
lv_ddlist_refr_size(ddlist, true);
|
||||
|
||||
return LV_RES_OK;
|
||||
if(res == LV_RES_OK) lv_ddlist_refr_size(ddlist, true);
|
||||
|
||||
return res;
|
||||
|
||||
}
|
||||
|
||||
@@ -708,6 +712,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
|
||||
anim_en = false;
|
||||
#endif
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
if(ext->label == NULL) return; /*Probably the ddlist is being deleted if the label is NULL.*/
|
||||
|
||||
lv_style_t * style = lv_obj_get_style(ddlist);
|
||||
lv_coord_t new_height;
|
||||
if(ext->opened) { /*Open the list*/
|
||||
@@ -756,6 +763,9 @@ static void lv_ddlist_refr_size(lv_obj_t * ddlist, bool anim_en)
|
||||
static void lv_ddlist_pos_current_option(lv_obj_t * ddlist)
|
||||
{
|
||||
lv_ddlist_ext_t * ext = lv_obj_get_ext_attr(ddlist);
|
||||
|
||||
if(ext->label == NULL) return; /*Probably the ddlist is being deleted if the label is NULL.*/
|
||||
|
||||
lv_style_t * style = lv_obj_get_style(ddlist);
|
||||
const lv_font_t * font = style->text.font;
|
||||
lv_coord_t font_h = lv_font_get_height(font);
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param);
|
||||
static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt);
|
||||
static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
@@ -104,7 +104,7 @@ lv_obj_t * lv_kb_create(lv_obj_t * par, const lv_obj_t * copy)
|
||||
if(copy == NULL) {
|
||||
lv_obj_set_size(new_kb, LV_HOR_RES, LV_VER_RES / 2);
|
||||
lv_obj_align(new_kb, NULL, LV_ALIGN_IN_BOTTOM_MID, 0, 0);
|
||||
lv_btnm_set_action(new_kb, lv_app_kb_action);
|
||||
lv_btnm_set_action(new_kb, lv_kb_def_action);
|
||||
lv_btnm_set_map(new_kb, kb_map_lc);
|
||||
|
||||
/*Set the default styles*/
|
||||
@@ -390,9 +390,10 @@ static lv_res_t lv_kb_signal(lv_obj_t * kb, lv_signal_t sign, void * param)
|
||||
* @param i the index of the released button from the current btnm map
|
||||
* @return LV_ACTION_RES_INV if the btnm is deleted else LV_ACTION_RES_OK
|
||||
*/
|
||||
static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
|
||||
static lv_res_t lv_kb_def_action(lv_obj_t * kb, const char * txt)
|
||||
{
|
||||
lv_kb_ext_t * ext = lv_obj_get_ext_attr(kb);
|
||||
lv_res_t res = LV_RES_OK;
|
||||
|
||||
/*Do the corresponding action according to the text of the button*/
|
||||
if(strcmp(txt, "abc") == 0) {
|
||||
@@ -405,22 +406,24 @@ static lv_res_t lv_app_kb_action(lv_obj_t * kb, const char * txt)
|
||||
lv_btnm_set_map(kb, kb_map_spec);
|
||||
return LV_RES_OK;
|
||||
} else if(strcmp(txt, SYMBOL_CLOSE) == 0) {
|
||||
if(ext->hide_action) ext->hide_action(kb);
|
||||
if(ext->hide_action) res = ext->hide_action(kb);
|
||||
else {
|
||||
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
|
||||
lv_obj_del(kb);
|
||||
}
|
||||
return LV_RES_INV;
|
||||
} else if(strcmp(txt, SYMBOL_OK) == 0) {
|
||||
if(ext->ok_action) ext->ok_action(kb);
|
||||
if(ext->ok_action) res = ext->ok_action(kb);
|
||||
else {
|
||||
lv_kb_set_ta(kb, NULL); /*De-assign the text area to hide it cursor if needed*/
|
||||
lv_obj_del(kb);
|
||||
res = lv_obj_del(kb);
|
||||
}
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
if(ext->ta == NULL) return LV_RES_OK;
|
||||
if(res != LV_RES_OK) return res; /*The keyboard might be deleted in the actions*/
|
||||
|
||||
/*Add the characters to the text area if set*/
|
||||
if(ext->ta == NULL) return res;
|
||||
|
||||
if(strcmp(txt, "Enter") == 0)lv_ta_add_char(ext->ta, '\n');
|
||||
else if(strcmp(txt, SYMBOL_LEFT) == 0) lv_ta_cursor_left(ext->ta);
|
||||
|
||||
@@ -767,8 +767,14 @@ static lv_res_t lv_list_btn_signal(lv_obj_t * btn, lv_signal_t sign, void * para
|
||||
last_clicked_btn = btn;
|
||||
|
||||
}
|
||||
#endif
|
||||
if(sign == LV_SIGNAL_CLEANUP) {
|
||||
|
||||
lv_obj_t * list = lv_obj_get_parent(lv_obj_get_parent(btn));
|
||||
lv_obj_t * sel = lv_list_get_btn_selected(list);
|
||||
if(sel == btn) lv_list_set_btn_selected(list, lv_list_get_next_btn(list, btn));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -381,6 +381,8 @@ void lv_page_glue_obj(lv_obj_t * obj, bool glue)
|
||||
void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time)
|
||||
{
|
||||
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
|
||||
#if USE_LV_ANIMATION == 0
|
||||
anim_time = 0;
|
||||
#else
|
||||
@@ -388,9 +390,10 @@ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, uint16_t anim_time)
|
||||
* because it can overide the current changes*/
|
||||
lv_anim_del(page, (lv_anim_fp_t)lv_obj_set_y);
|
||||
lv_anim_del(page, (lv_anim_fp_t)lv_obj_set_pos);
|
||||
lv_anim_del(ext->scrl, (lv_anim_fp_t)lv_obj_set_y);
|
||||
lv_anim_del(ext->scrl, (lv_anim_fp_t)lv_obj_set_pos);
|
||||
#endif
|
||||
|
||||
lv_page_ext_t * ext = lv_obj_get_ext_attr(page);
|
||||
lv_style_t * style = lv_page_get_style(page, LV_PAGE_STYLE_BG);
|
||||
lv_style_t * style_scrl = lv_page_get_style(page, LV_PAGE_STYLE_SCRL);
|
||||
|
||||
@@ -673,12 +676,12 @@ static lv_res_t lv_page_signal(lv_obj_t * page, lv_signal_t sign, void * param)
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESSED) {
|
||||
if(ext->pr_action != NULL) {
|
||||
ext->pr_action(page);
|
||||
res = ext->pr_action(page);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_RELEASED) {
|
||||
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
||||
if(ext->rel_action != NULL) {
|
||||
ext->rel_action(page);
|
||||
res = ext->rel_action(page);
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_REFR_EXT_SIZE) {
|
||||
@@ -817,12 +820,12 @@ static lv_res_t lv_page_scrollable_signal(lv_obj_t * scrl, lv_signal_t sign, voi
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_PRESSED) {
|
||||
if(page_ext->pr_action != NULL) {
|
||||
page_ext->pr_action(page);
|
||||
res = page_ext->pr_action(page);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_RELEASED) {
|
||||
if(lv_indev_is_dragging(lv_indev_get_act()) == false) {
|
||||
if(page_ext->rel_action != NULL) {
|
||||
page_ext->rel_action(page);
|
||||
res = page_ext->rel_action(page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -359,12 +359,14 @@ static lv_res_t lv_roller_signal(lv_obj_t * roller, lv_signal_t sign, void * par
|
||||
}
|
||||
} else if(c == LV_GROUP_KEY_ENTER) {
|
||||
ext->ddlist.sel_opt_id_ori = ext->ddlist.sel_opt_id; /*Set the entered value as default*/
|
||||
if(ext->ddlist.action) ext->ddlist.action(roller);
|
||||
if(ext->ddlist.action) res = ext->ddlist.action(roller);
|
||||
#if USE_LV_GROUP
|
||||
lv_group_t * g = lv_obj_get_group(roller);
|
||||
bool editing = lv_group_get_editing(g);
|
||||
if(res == LV_RES_OK) {
|
||||
lv_group_t * g = lv_obj_get_group(roller);
|
||||
bool editing = lv_group_get_editing(g);
|
||||
|
||||
if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/
|
||||
if(editing) lv_group_set_editing(g, false); /*In edit mode go to navigate mode if an option is selected*/
|
||||
}
|
||||
#endif
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_TYPE) {
|
||||
@@ -414,7 +416,7 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign,
|
||||
if(id < 0) id = 0;
|
||||
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
|
||||
ext->ddlist.sel_opt_id = id;
|
||||
if(ext->ddlist.action) ext->ddlist.action(roller);
|
||||
if(ext->ddlist.action) res = ext->ddlist.action(roller);
|
||||
} else if(sign == LV_SIGNAL_RELEASED) {
|
||||
/*If picked an option by clicking then set it*/
|
||||
if(!lv_indev_is_dragging(indev)) {
|
||||
@@ -425,12 +427,12 @@ static lv_res_t lv_roller_scrl_signal(lv_obj_t * roller_scrl, lv_signal_t sign,
|
||||
if(id < 0) id = 0;
|
||||
if(id >= ext->ddlist.option_cnt) id = ext->ddlist.option_cnt - 1;
|
||||
ext->ddlist.sel_opt_id = id;
|
||||
if(ext->ddlist.action) ext->ddlist.action(roller);
|
||||
if(ext->ddlist.action) res = ext->ddlist.action(roller);
|
||||
}
|
||||
}
|
||||
|
||||
/*Position the scrollable according to the new selected option*/
|
||||
if(id != -1) {
|
||||
if(id != -1 && res == LV_RES_OK) {
|
||||
refr_position(roller, true);
|
||||
}
|
||||
|
||||
@@ -503,8 +505,10 @@ static void refr_position(lv_obj_t * roller, bool anim_en)
|
||||
#if USE_LV_ANIMATION == 0
|
||||
anim_en = false;
|
||||
#endif
|
||||
lv_obj_t * roller_scrl = lv_page_get_scrl(roller);
|
||||
lv_roller_ext_t * ext = lv_obj_get_ext_attr(roller);
|
||||
if(ext->ddlist.label == NULL) return; /*Probably the roller is being deleted if the label is NULL.*/
|
||||
|
||||
lv_obj_t * roller_scrl = lv_page_get_scrl(roller);
|
||||
lv_style_t * style_label = lv_obj_get_style(ext->ddlist.label);
|
||||
const lv_font_t * font = style_label->text.font;
|
||||
lv_coord_t font_h = lv_font_get_height(font);
|
||||
|
||||
@@ -455,13 +455,13 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
|
||||
|
||||
if(tmp != ext->drag_value) {
|
||||
ext->drag_value = tmp;
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
lv_obj_invalidate(slider);
|
||||
if(ext->action != NULL) res = ext->action(slider);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_RELEASED || sign == LV_SIGNAL_PRESS_LOST) {
|
||||
lv_slider_set_value(slider, ext->drag_value);
|
||||
ext->drag_value = LV_SLIDER_NOT_PRESSED;
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
if(ext->action != NULL) res = ext->action(slider);
|
||||
} else if(sign == LV_SIGNAL_CORD_CHG) {
|
||||
/* The knob size depends on slider size.
|
||||
* During the drawing method the ext. size is used by the knob so refresh the ext. size.*/
|
||||
@@ -498,10 +498,10 @@ static lv_res_t lv_slider_signal(lv_obj_t * slider, lv_signal_t sign, void * par
|
||||
#endif
|
||||
if(c == LV_GROUP_KEY_RIGHT || c == LV_GROUP_KEY_UP) {
|
||||
lv_slider_set_value(slider, lv_slider_get_value(slider) + 1);
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
if(ext->action != NULL) res = ext->action(slider);
|
||||
} else if(c == LV_GROUP_KEY_LEFT || c == LV_GROUP_KEY_DOWN) {
|
||||
lv_slider_set_value(slider, lv_slider_get_value(slider) - 1);
|
||||
if(ext->action != NULL) ext->action(slider);
|
||||
if(ext->action != NULL) res = ext->action(slider);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
||||
bool * editable = (bool *)param;
|
||||
|
||||
@@ -243,9 +243,10 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
if(lv_sw_get_state(sw)) lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_on);
|
||||
else lv_slider_set_style(sw, LV_SLIDER_STYLE_KNOB, ext->style_knob_off);
|
||||
|
||||
if(slider_action != NULL) slider_action(sw);
|
||||
|
||||
ext->changed = 0;
|
||||
|
||||
if(slider_action != NULL) res = slider_action(sw);
|
||||
|
||||
} else if(sign == LV_SIGNAL_CONTROLL) {
|
||||
|
||||
char c = *((char *)param);
|
||||
@@ -253,13 +254,13 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
if(old_val) lv_sw_off(sw);
|
||||
else lv_sw_on(sw);
|
||||
|
||||
if(slider_action) slider_action(sw);
|
||||
if(slider_action) res = slider_action(sw);
|
||||
} else if(c == LV_GROUP_KEY_UP || c == LV_GROUP_KEY_RIGHT) {
|
||||
lv_sw_on(sw);
|
||||
if(slider_action) slider_action(sw);
|
||||
if(slider_action) res = slider_action(sw);
|
||||
} else if(c == LV_GROUP_KEY_DOWN || c == LV_GROUP_KEY_LEFT) {
|
||||
lv_sw_off(sw);
|
||||
if(slider_action) slider_action(sw);
|
||||
if(slider_action) res = slider_action(sw);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
||||
bool * editable = (bool *)param;
|
||||
@@ -274,7 +275,7 @@ static lv_res_t lv_sw_signal(lv_obj_t * sw, lv_signal_t sign, void * param)
|
||||
}
|
||||
|
||||
/*Restore the callback*/
|
||||
ext->slider.action = slider_action;
|
||||
if(res == LV_RES_OK) ext->slider.action = slider_action;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -577,9 +577,27 @@ static lv_res_t lv_tabview_signal(lv_obj_t * tabview, lv_signal_t sign, void * p
|
||||
tabview_realign(tabview);
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_FOCUS || sign == LV_SIGNAL_DEFOCUS || sign == LV_SIGNAL_CONTROLL) {
|
||||
/* The button matrix is not in a group (the tab view is in it) but it should handle the group signals.
|
||||
* So propagate the related signals to the button matrix manually*/
|
||||
if(ext->btns) {
|
||||
ext->btns->signal_func(ext->btns, sign, param);
|
||||
}
|
||||
if(sign == LV_SIGNAL_FOCUS) {
|
||||
lv_hal_indev_type_t indev_type = lv_indev_get_type(lv_indev_get_act());
|
||||
/*With ENCODER select the first button only in edit mode*/
|
||||
if(indev_type == LV_INDEV_TYPE_ENCODER) {
|
||||
lv_group_t * g = lv_obj_get_group(tabview);
|
||||
if(lv_group_get_editing(g)) {
|
||||
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
|
||||
btnm_ext->btn_id_pr = 0;
|
||||
lv_obj_invalidate(ext->btns);
|
||||
}
|
||||
} else {
|
||||
lv_btnm_ext_t * btnm_ext = lv_obj_get_ext_attr(ext->btns);
|
||||
btnm_ext->btn_id_pr = 0;
|
||||
lv_obj_invalidate(ext->btns);
|
||||
}
|
||||
}
|
||||
} else if(sign == LV_SIGNAL_GET_EDITABLE) {
|
||||
bool * editable = (bool *)param;
|
||||
*editable = true;
|
||||
|
||||
Reference in New Issue
Block a user