mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
focus/defocus event updates
This commit is contained in:
parent
c713c4135b
commit
9d72ced2b6
@ -195,8 +195,6 @@
|
||||
#endif
|
||||
#endif /*LV_TICK_CUSTOM*/
|
||||
|
||||
typedef void * lv_disp_drv_user_data_t; /*Type of user data in the display driver*/
|
||||
typedef void * lv_indev_drv_user_data_t; /*Type of user data in the display driver*/
|
||||
|
||||
/*Log settings*/
|
||||
#ifndef USE_LV_LOG
|
||||
@ -332,12 +330,6 @@ typedef void * lv_indev_drv_user_data_t; /*Type of user data in t
|
||||
/*===================
|
||||
* LV_OBJ SETTINGS
|
||||
*==================*/
|
||||
#ifndef LV_OBJ_FREE_NUM_TYPE
|
||||
#define LV_OBJ_FREE_NUM_TYPE uint32_t /*Type of free number attribute (comment out disable free number)*/
|
||||
#endif
|
||||
#ifndef LV_OBJ_FREE_PTR
|
||||
#define LV_OBJ_FREE_PTR 1 /*Enable the free pointer attribute*/
|
||||
#endif
|
||||
#ifndef LV_OBJ_REALIGN
|
||||
#define LV_OBJ_REALIGN 1 /*Enable `lv_obj_realaign()` based on `lv_obj_align()` parameters*/
|
||||
#endif
|
||||
|
@ -42,6 +42,8 @@ for i in inlines:
|
||||
fout.write('#ifndef ' + splitted[1] + '\n')
|
||||
fout.write(i + '\n')
|
||||
fout.write('#endif\n')
|
||||
elif(re.search('^ *typedef .*;.*$', i)):
|
||||
continue; #igonre typedefs to avoide redeclaration
|
||||
else:
|
||||
fout.write(i + '\n')
|
||||
|
||||
|
@ -23,8 +23,8 @@
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static void style_mod_def(lv_style_t * style);
|
||||
static void style_mod_edit_def(lv_style_t * style);
|
||||
static void style_mod_def(lv_group_t * group, lv_style_t * style);
|
||||
static void style_mod_edit_def(lv_group_t * group, lv_style_t * style);
|
||||
static void refresh_theme(lv_group_t * g, lv_theme_t * th);
|
||||
static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *), void * (*move)(const lv_ll_t *, const void *));
|
||||
static void lv_group_refocus(lv_group_t * g);
|
||||
@ -68,6 +68,9 @@ lv_group_t * lv_group_create(void)
|
||||
group->refocus_policy = LV_GROUP_REFOCUS_POLICY_PREV;
|
||||
group->wrap = 1;
|
||||
|
||||
|
||||
|
||||
|
||||
/*Initialize style modification callbacks from current theme*/
|
||||
refresh_theme(group, lv_theme_get_current());
|
||||
|
||||
@ -187,6 +190,7 @@ void lv_group_focus_obj(lv_obj_t * obj)
|
||||
if(g->obj_focus == i) return; /*Don't focus the already focused object again*/
|
||||
if(g->obj_focus != NULL) {
|
||||
(*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
lv_obj_send_event(*g->obj_focus, LV_EVENT_DEFOCUSED);
|
||||
lv_obj_invalidate(*g->obj_focus);
|
||||
}
|
||||
|
||||
@ -195,6 +199,7 @@ void lv_group_focus_obj(lv_obj_t * obj)
|
||||
if(g->obj_focus != NULL) {
|
||||
(*g->obj_focus)->signal_cb(*g->obj_focus, LV_SIGNAL_FOCUS, NULL);
|
||||
if(g->focus_cb) g->focus_cb(g);
|
||||
lv_obj_send_event(*g->obj_focus, LV_EVENT_FOCUSED);
|
||||
lv_obj_invalidate(*g->obj_focus);
|
||||
}
|
||||
break;
|
||||
@ -291,7 +296,10 @@ void lv_group_set_editing(lv_group_t * group, bool edit)
|
||||
group->editing = en_val;
|
||||
lv_obj_t * focused = lv_group_get_focused(group);
|
||||
|
||||
if(focused) focused->signal_cb(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave edit mode*/
|
||||
if(focused) {
|
||||
focused->signal_cb(focused, LV_SIGNAL_FOCUS, NULL); /*Focus again to properly leave/open edit/navigate mode*/
|
||||
lv_obj_send_event(*group->obj_focus, LV_EVENT_FOCUSED);
|
||||
}
|
||||
|
||||
lv_obj_invalidate(focused);
|
||||
}
|
||||
@ -341,12 +349,13 @@ void lv_group_set_wrap(lv_group_t * group, bool en)
|
||||
*/
|
||||
lv_style_t * lv_group_mod_style(lv_group_t * group, const lv_style_t * style)
|
||||
{
|
||||
/*Load the current style. It will be modified by the callback*/
|
||||
lv_style_copy(&group->style_tmp, style);
|
||||
|
||||
if(group->editing) {
|
||||
if(group->style_mod_edit) group->style_mod_edit(&group->style_tmp);
|
||||
if(group->style_mod_edit) group->style_mod_edit(group, &group->style_tmp);
|
||||
} else {
|
||||
if(group->style_mod) group->style_mod(&group->style_tmp);
|
||||
if(group->style_mod) group->style_mod(group, &group->style_tmp);
|
||||
}
|
||||
return &group->style_tmp;
|
||||
}
|
||||
@ -455,10 +464,12 @@ void lv_group_report_style_mod(lv_group_t * group)
|
||||
|
||||
/**
|
||||
* Default style modifier function
|
||||
* @param group pointer to the caller group
|
||||
* @param style pointer to a style to modify. (Typically group.style_tmp) It will be OVERWRITTEN.
|
||||
*/
|
||||
static void style_mod_def(lv_style_t * style)
|
||||
static void style_mod_def(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void)group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
|
||||
/*Make the style to be a little bit orange*/
|
||||
@ -484,10 +495,12 @@ static void style_mod_def(lv_style_t * style)
|
||||
|
||||
/**
|
||||
* Default style modifier function
|
||||
* @param group pointer to the caller group
|
||||
* @param style pointer to a style to modify. (Typically group.style_tmp) It will be OVERWRITTEN.
|
||||
*/
|
||||
static void style_mod_edit_def(lv_style_t * style)
|
||||
static void style_mod_edit_def(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void)group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
|
||||
/*Make the style to be a little bit orange*/
|
||||
@ -569,12 +582,14 @@ static void focus_next_core(lv_group_t * group, void * (*begin)(const lv_ll_t *)
|
||||
|
||||
if(group->obj_focus) {
|
||||
(*group->obj_focus)->signal_cb(*group->obj_focus, LV_SIGNAL_DEFOCUS, NULL);
|
||||
lv_obj_send_event(*group->obj_focus, LV_EVENT_DEFOCUSED);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
}
|
||||
|
||||
group->obj_focus = obj_next;
|
||||
|
||||
(*group->obj_focus)->signal_cb(*group->obj_focus, LV_SIGNAL_FOCUS, NULL);
|
||||
lv_obj_send_event(*group->obj_focus, LV_EVENT_FOCUSED);
|
||||
lv_obj_invalidate(*group->obj_focus);
|
||||
|
||||
if(group->focus_cb) group->focus_cb(group);
|
||||
|
@ -45,7 +45,7 @@ extern "C" {
|
||||
**********************/
|
||||
struct _lv_group_t;
|
||||
|
||||
typedef void (*lv_group_style_mod_func_t)(lv_style_t *);
|
||||
typedef void (*lv_group_style_mod_func_t)(struct _lv_group_t *, lv_style_t *);
|
||||
typedef void (*lv_group_focus_cb_t)(struct _lv_group_t *);
|
||||
|
||||
typedef struct _lv_group_t
|
||||
@ -56,6 +56,16 @@ typedef struct _lv_group_t
|
||||
lv_group_style_mod_func_t style_mod_edit;/*A function which modifies the style of the focused object*/
|
||||
lv_group_focus_cb_t focus_cb; /*A function to call when a new object is focused (optional)*/
|
||||
lv_style_t style_tmp; /*Stores the modified style of the focused object */
|
||||
#if USE_LV_USER_DATA_SINGLE
|
||||
lv_group_user_data_t user_data;
|
||||
#endif
|
||||
|
||||
#if USE_LV_USER_DATA_MULTI
|
||||
lv_group_user_data_t focus_user_data;
|
||||
lv_group_user_data_t style_mod_user_data;
|
||||
lv_group_user_data_t style_mod_edit_user_data;
|
||||
#endif
|
||||
|
||||
uint8_t frozen :1; /*1: can't focus to new object*/
|
||||
uint8_t editing :1; /*1: Edit mode, 0: Navigate mode*/
|
||||
uint8_t click_focus :1; /*1: If an object in a group is clicked by an indev then it will be focused */
|
||||
|
@ -661,6 +661,7 @@ static void indev_proc_press(lv_indev_proc_t * proc)
|
||||
if(proc->types.pointer.act_obj != NULL) {
|
||||
proc->types.pointer.act_obj->signal_cb(proc->types.pointer.act_obj, LV_SIGNAL_PRESS_LOST, indev_act);
|
||||
lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_PRESS_LOST);
|
||||
|
||||
if(proc->reset_query != 0) return;
|
||||
}
|
||||
|
||||
@ -770,8 +771,8 @@ static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
proc->types.pointer.wait_unil_release = 0;
|
||||
}
|
||||
|
||||
/*Forgot the act obj and send a released signal */
|
||||
if(proc->types.pointer.act_obj != NULL) {
|
||||
/*Forget the act obj and send a released signal */
|
||||
if(proc->types.pointer.act_obj) {
|
||||
/* If the object was protected against press lost then it possible that
|
||||
* the object is already not pressed but still it is the `act_obj`.
|
||||
* In this case send the `LV_SIGNAL_RELEASED/CLICKED` of `LV_SIGNAL_PRESS_LOST` if the indev is ON the `types.pointer.act_obj` */
|
||||
@ -800,14 +801,11 @@ static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
/*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->types.pointer.act_obj);
|
||||
if(lv_group_get_editing(act_g)) {
|
||||
lv_group_set_editing(act_g, false);
|
||||
}
|
||||
lv_group_t * g = lv_obj_get_group(proc->types.pointer.act_obj);
|
||||
if(lv_group_get_editing(g)) lv_group_set_editing(g, false);
|
||||
|
||||
/*Check, if the parent is in a group focus on it.*/
|
||||
if(lv_obj_is_protected(proc->types.pointer.act_obj, LV_PROTECT_CLICK_FOCUS) == false) { /*Respect the click protection*/
|
||||
lv_group_t * g = lv_obj_get_group(proc->types.pointer.act_obj);
|
||||
if(lv_obj_is_protected(proc->types.pointer.act_obj, LV_PROTECT_CLICK_FOCUS) == false) { /*Respect the click focus protection*/
|
||||
lv_obj_t * parent = proc->types.pointer.act_obj;
|
||||
|
||||
while(g == NULL) {
|
||||
@ -820,13 +818,25 @@ static void indev_proc_release(lv_indev_proc_t * proc)
|
||||
g = lv_obj_get_group(parent);
|
||||
}
|
||||
|
||||
if(g != NULL && parent != NULL)
|
||||
/* If a pareit is in a group make it focused.
|
||||
* `LV_EVENT_FOCUSED/DEFOCUSED` will be sent by `lv_group_focus_obj`*/
|
||||
if(g && parent) {
|
||||
if(lv_group_get_click_focus(g)) {
|
||||
lv_group_focus_obj(parent);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Send defocus to the lastly "active" object and foucus to the new one.
|
||||
* If the one of them is in group then it possible that `lv_group_focus_obj` alraedy sent
|
||||
* a focus/defucus signal because of `click focus`*/
|
||||
if(proc->types.pointer.last_pressed != proc->types.pointer.act_obj) {
|
||||
lv_obj_send_event(proc->types.pointer.last_pressed, LV_EVENT_DEFOCUSED);
|
||||
lv_obj_send_event(proc->types.pointer.act_obj, LV_EVENT_FOCUSED);
|
||||
proc->types.pointer.last_pressed = proc->types.pointer.act_obj;
|
||||
}
|
||||
|
||||
if(proc->reset_query != 0) return;
|
||||
proc->types.pointer.act_obj = NULL;
|
||||
proc->pr_timestamp = 0;
|
||||
@ -853,6 +863,7 @@ static void indev_proc_reset_query_handler(lv_indev_t * indev)
|
||||
if(indev->proc.reset_query) {
|
||||
indev->proc.types.pointer.act_obj = NULL;
|
||||
indev->proc.types.pointer.last_obj = NULL;
|
||||
indev->proc.types.pointer.last_pressed = NULL;
|
||||
indev->proc.types.pointer.drag_limit_out = 0;
|
||||
indev->proc.types.pointer.drag_in_prog = 0;
|
||||
indev->proc.long_pr_sent = 0;
|
||||
|
@ -1161,6 +1161,8 @@ void lv_obj_set_event_cb(lv_obj_t * obj, lv_event_cb_t cb)
|
||||
*/
|
||||
void lv_obj_send_event(lv_obj_t * obj, lv_event_t event)
|
||||
{
|
||||
if(obj == NULL) return;
|
||||
|
||||
if(obj->event_cb) obj->event_cb(obj, event);
|
||||
|
||||
if(obj->event_parent && obj->par) {
|
||||
|
@ -92,8 +92,9 @@ typedef struct _lv_indev_proc_t {
|
||||
lv_point_t vect;
|
||||
lv_point_t drag_sum; /*Count the dragged pixels to check LV_INDEV_DRAG_LIMIT*/
|
||||
lv_point_t drag_throw_vect;
|
||||
struct _lv_obj_t * act_obj;
|
||||
struct _lv_obj_t * last_obj;
|
||||
struct _lv_obj_t * act_obj; /*The object being pressed*/
|
||||
struct _lv_obj_t * last_obj; /*The last obejct which was pressed (used by dragthrow and other post-release event)*/
|
||||
struct _lv_obj_t * last_pressed; /*The lastly pressed object*/
|
||||
|
||||
/*Flags*/
|
||||
uint8_t drag_limit_out :1;
|
||||
|
@ -1024,7 +1024,9 @@ static void scrl_def_event_cb(lv_obj_t * scrl, lv_event_t event)
|
||||
event == LV_EVENT_LONG_PRESSED ||
|
||||
event == LV_EVENT_LONG_PRESSED_REPEAT ||
|
||||
event == LV_EVENT_LONG_HOVER_IN ||
|
||||
event == LV_EVENT_LONG_HOVER_OUT)
|
||||
event == LV_EVENT_LONG_HOVER_OUT ||
|
||||
event == LV_EVENT_FOCUSED ||
|
||||
event == LV_EVENT_DEFOCUSED)
|
||||
{
|
||||
lv_obj_send_event(page, event);
|
||||
}
|
||||
|
@ -803,8 +803,9 @@ static void win_init(void)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
|
||||
static void style_mod(lv_style_t * style)
|
||||
static void style_mod(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
@ -816,8 +817,9 @@ static void style_mod(lv_style_t * style)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void style_mod_edit(lv_style_t * style)
|
||||
static void style_mod_edit(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
|
@ -357,8 +357,9 @@ static void win_init(void)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
|
||||
static void style_mod(lv_style_t * style)
|
||||
static void style_mod(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void)group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
@ -379,8 +380,9 @@ static void style_mod(lv_style_t * style)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void style_mod_edit(lv_style_t * style)
|
||||
static void style_mod_edit(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void)group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
|
@ -786,8 +786,9 @@ static void win_init(void)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
|
||||
static void style_mod(lv_style_t * style)
|
||||
static void style_mod(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
@ -808,8 +809,9 @@ static void style_mod(lv_style_t * style)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void style_mod_edit(lv_style_t * style)
|
||||
static void style_mod_edit(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
|
@ -414,8 +414,9 @@ static void win_init(void)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
|
||||
static void style_mod(lv_style_t * style)
|
||||
static void style_mod(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
@ -430,8 +431,9 @@ static void style_mod(lv_style_t * style)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void style_mod_edit(lv_style_t * style)
|
||||
static void style_mod_edit(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
|
@ -777,8 +777,9 @@ static void win_init(void)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
|
||||
static void style_mod(lv_style_t * style)
|
||||
static void style_mod(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
style->body.border.width = 2;
|
||||
style->body.border.color = LV_COLOR_SILVER;
|
||||
@ -796,6 +797,29 @@ static void style_mod(lv_style_t * style)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void style_mod_edit(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void) group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
style->body.border.color = LV_COLOR_GREEN;
|
||||
|
||||
/*If not empty or has border then emphasis the border*/
|
||||
if (style->body.opa != LV_OPA_TRANSP || style->body.border.width != 0) style->body.border.width = LV_DPI / 20;
|
||||
|
||||
style->body.main_color = lv_color_mix(style->body.main_color, LV_COLOR_GREEN, LV_OPA_70);
|
||||
style->body.grad_color = lv_color_mix(style->body.grad_color, LV_COLOR_GREEN, LV_OPA_70);
|
||||
style->body.shadow.color = lv_color_mix(style->body.shadow.color, LV_COLOR_GREEN, LV_OPA_60);
|
||||
|
||||
style->text.color = lv_color_mix(style->text.color, LV_COLOR_GREEN, LV_OPA_70);
|
||||
#else
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
style->body.border.color = LV_COLOR_BLACK;
|
||||
style->body.border.width = 3;
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif /*USE_LV_GROUP*/
|
||||
|
||||
/**********************
|
||||
@ -855,7 +879,7 @@ lv_theme_t * lv_theme_nemo_init(uint16_t hue, lv_font_t * font)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
theme.group.style_mod = style_mod;
|
||||
theme.group.style_mod_edit = style_mod;
|
||||
theme.group.style_mod_edit = style_mod_edit;
|
||||
#endif
|
||||
|
||||
return &theme;
|
||||
|
@ -697,8 +697,9 @@ static void win_init(void)
|
||||
|
||||
#if USE_LV_GROUP
|
||||
|
||||
static void style_mod(lv_style_t * style)
|
||||
static void style_mod(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void)group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
@ -713,8 +714,9 @@ static void style_mod(lv_style_t * style)
|
||||
#endif
|
||||
}
|
||||
|
||||
static void style_mod_edit(lv_style_t * style)
|
||||
static void style_mod_edit(lv_group_t * group, lv_style_t * style)
|
||||
{
|
||||
(void)group; /*Unused*/
|
||||
#if LV_COLOR_DEPTH != 1
|
||||
/*Make the style to be a little bit orange*/
|
||||
style->body.border.opa = LV_OPA_COVER;
|
||||
|
Loading…
x
Reference in New Issue
Block a user