mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
Merge pull request #1509 from fhorinek/master
Added focus parent for v7
This commit is contained in:
commit
2739753f20
@ -1092,8 +1092,9 @@ lv_obj_t * lv_indev_search_obj(lv_obj_t * obj, lv_point_t * point)
|
|||||||
static void indev_click_focus(lv_indev_proc_t * proc)
|
static void indev_click_focus(lv_indev_proc_t * proc)
|
||||||
{
|
{
|
||||||
/*Handle click focus*/
|
/*Handle click focus*/
|
||||||
|
lv_obj_t * obj_to_focus = lv_obj_get_focused_obj(indev_obj_act);
|
||||||
if(lv_obj_is_protected(indev_obj_act, LV_PROTECT_CLICK_FOCUS) == false &&
|
if(lv_obj_is_protected(indev_obj_act, LV_PROTECT_CLICK_FOCUS) == false &&
|
||||||
proc->types.pointer.last_pressed != indev_obj_act) {
|
proc->types.pointer.last_pressed != obj_to_focus) {
|
||||||
#if LV_USE_GROUP
|
#if LV_USE_GROUP
|
||||||
lv_group_t * g_act = lv_obj_get_group(indev_obj_act);
|
lv_group_t * g_act = lv_obj_get_group(indev_obj_act);
|
||||||
lv_group_t * g_prev = proc->types.pointer.last_pressed ? lv_obj_get_group(proc->types.pointer.last_pressed) : NULL;
|
lv_group_t * g_prev = proc->types.pointer.last_pressed ? lv_obj_get_group(proc->types.pointer.last_pressed) : NULL;
|
||||||
@ -1172,7 +1173,7 @@ static void indev_click_focus(lv_indev_proc_t * proc)
|
|||||||
lv_event_send(indev_obj_act, LV_EVENT_FOCUSED, NULL);
|
lv_event_send(indev_obj_act, LV_EVENT_FOCUSED, NULL);
|
||||||
if(indev_reset_check(proc)) return;
|
if(indev_reset_check(proc)) return;
|
||||||
#endif
|
#endif
|
||||||
proc->types.pointer.last_pressed = indev_obj_act;
|
proc->types.pointer.last_pressed = obj_to_focus;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -298,6 +298,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
|
|||||||
|
|
||||||
#if LV_USE_GROUP
|
#if LV_USE_GROUP
|
||||||
new_obj->group_p = NULL;
|
new_obj->group_p = NULL;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*Set attributes*/
|
/*Set attributes*/
|
||||||
@ -312,6 +313,7 @@ lv_obj_t * lv_obj_create(lv_obj_t * parent, const lv_obj_t * copy)
|
|||||||
new_obj->protect = LV_PROTECT_NONE;
|
new_obj->protect = LV_PROTECT_NONE;
|
||||||
new_obj->parent_event = 0;
|
new_obj->parent_event = 0;
|
||||||
new_obj->gesture_parent = parent ? 1 : 0;
|
new_obj->gesture_parent = parent ? 1 : 0;
|
||||||
|
new_obj->focus_parent = 0;
|
||||||
new_obj->state = LV_STATE_DEFAULT;
|
new_obj->state = LV_STATE_DEFAULT;
|
||||||
|
|
||||||
new_obj->ext_attr = NULL;
|
new_obj->ext_attr = NULL;
|
||||||
@ -1543,6 +1545,31 @@ void lv_obj_set_gesture_parent(lv_obj_t * obj, bool en)
|
|||||||
obj->gesture_parent = (en == true ? 1 : 0);
|
obj->gesture_parent = (en == true ? 1 : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable to use parent for focus state.
|
||||||
|
* When object is focused the parent will get the state instead (visual only)
|
||||||
|
* @param obj pointer to an object
|
||||||
|
* @param en true: enable the 'focus parent' for the object
|
||||||
|
*/
|
||||||
|
void lv_obj_set_focus_parent(lv_obj_t * obj, bool en)
|
||||||
|
{
|
||||||
|
if (lv_obj_is_focused(obj)) {
|
||||||
|
if (en) {
|
||||||
|
obj->focus_parent = 1;
|
||||||
|
lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||||
|
lv_obj_set_state(lv_obj_get_focused_obj(obj), LV_STATE_FOCUSED);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
lv_obj_clear_state(lv_obj_get_focused_obj(obj), LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||||
|
lv_obj_set_state(obj, LV_STATE_FOCUSED);
|
||||||
|
obj->focus_parent = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
obj->focus_parent = (en == true ? 1 : 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Propagate the events to the parent too
|
* Propagate the events to the parent too
|
||||||
* @param obj pointer to an object
|
* @param obj pointer to an object
|
||||||
@ -2744,6 +2771,16 @@ bool lv_obj_get_gesture_parent(const lv_obj_t * obj)
|
|||||||
return obj->gesture_parent == 0 ? false : true;
|
return obj->gesture_parent == 0 ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the focus parent attribute of an object
|
||||||
|
* @param obj pointer to an object
|
||||||
|
* @return true: focus parent is enabled
|
||||||
|
*/
|
||||||
|
bool lv_obj_get_focus_parent(const lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
return obj->focus_parent == 0 ? false : true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the drag parent attribute of an object
|
* Get the drag parent attribute of an object
|
||||||
* @param obj pointer to an object
|
* @param obj pointer to an object
|
||||||
@ -3638,6 +3675,23 @@ static lv_design_res_t lv_obj_design(lv_obj_t * obj, const lv_area_t * clip_area
|
|||||||
return LV_DESIGN_RES_OK;
|
return LV_DESIGN_RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the really focused object by taking `focus_parent` into account.
|
||||||
|
* @param obj the start object
|
||||||
|
* @return the object to really focus
|
||||||
|
*/
|
||||||
|
lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj)
|
||||||
|
{
|
||||||
|
if(obj == NULL) return NULL;
|
||||||
|
const lv_obj_t * focus_obj = obj;
|
||||||
|
while(lv_obj_get_focus_parent(focus_obj) != false && focus_obj != NULL) {
|
||||||
|
focus_obj = lv_obj_get_parent(focus_obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (lv_obj_t*)focus_obj;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Signal function of the basic object
|
* Signal function of the basic object
|
||||||
* @param obj pointer to an object
|
* @param obj pointer to an object
|
||||||
@ -3686,14 +3740,26 @@ static lv_res_t lv_obj_signal(lv_obj_t * obj, lv_signal_t sign, void * param)
|
|||||||
if(lv_group_get_editing(lv_obj_get_group(obj))) {
|
if(lv_group_get_editing(lv_obj_get_group(obj))) {
|
||||||
uint8_t state = LV_STATE_FOCUSED;
|
uint8_t state = LV_STATE_FOCUSED;
|
||||||
state |= LV_STATE_EDITED;
|
state |= LV_STATE_EDITED;
|
||||||
|
|
||||||
|
/*if using focus mode, change target to parent*/
|
||||||
|
obj = lv_obj_get_focused_obj(obj);
|
||||||
|
|
||||||
lv_obj_add_state(obj, state);
|
lv_obj_add_state(obj, state);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
|
/*if using focus mode, change target to parent*/
|
||||||
|
obj = lv_obj_get_focused_obj(obj);
|
||||||
|
|
||||||
lv_obj_add_state(obj, LV_STATE_FOCUSED);
|
lv_obj_add_state(obj, LV_STATE_FOCUSED);
|
||||||
lv_obj_clear_state(obj, LV_STATE_EDITED);
|
lv_obj_clear_state(obj, LV_STATE_EDITED);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(sign == LV_SIGNAL_DEFOCUS) {
|
else if(sign == LV_SIGNAL_DEFOCUS) {
|
||||||
|
|
||||||
|
/*if using focus mode, change target to parent*/
|
||||||
|
obj = lv_obj_get_focused_obj(obj);
|
||||||
|
|
||||||
lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED);
|
lv_obj_clear_state(obj, LV_STATE_FOCUSED | LV_STATE_EDITED);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@ -4063,4 +4129,3 @@ static bool obj_valid_child(const lv_obj_t * parent, const lv_obj_t * obj_to_fin
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -221,7 +221,8 @@ typedef struct _lv_obj_t {
|
|||||||
uint8_t top : 1; /**< 1: If the object or its children is clicked it goes to the foreground*/
|
uint8_t top : 1; /**< 1: If the object or its children is clicked it goes to the foreground*/
|
||||||
uint8_t parent_event : 1; /**< 1: Send the object's events to the parent too. */
|
uint8_t parent_event : 1; /**< 1: Send the object's events to the parent too. */
|
||||||
uint8_t adv_hittest : 1; /**< 1: Use advanced hit-testing (slower) */
|
uint8_t adv_hittest : 1; /**< 1: Use advanced hit-testing (slower) */
|
||||||
uint8_t gesture_parent : 1; /**< 1: Parent will be gesture instead*/
|
uint8_t gesture_parent : 1; /**< 1: Parent will be gesture instead*/
|
||||||
|
uint8_t focus_parent : 1; /**< 1: Parent will be focused instead*/
|
||||||
|
|
||||||
lv_drag_dir_t drag_dir : 3; /**< Which directions the object can be dragged in */
|
lv_drag_dir_t drag_dir : 3; /**< Which directions the object can be dragged in */
|
||||||
lv_bidi_dir_t base_dir : 2; /**< Base direction of texts related to this object */
|
lv_bidi_dir_t base_dir : 2; /**< Base direction of texts related to this object */
|
||||||
@ -685,6 +686,14 @@ void lv_obj_set_drag_throw(lv_obj_t * obj, bool en);
|
|||||||
*/
|
*/
|
||||||
void lv_obj_set_drag_parent(lv_obj_t * obj, bool en);
|
void lv_obj_set_drag_parent(lv_obj_t * obj, bool en);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enable to use parent for focus state.
|
||||||
|
* When object is focused the parent will get the state instead (visual only)
|
||||||
|
* @param obj pointer to an object
|
||||||
|
* @param en true: enable the 'focus parent' for the object
|
||||||
|
*/
|
||||||
|
void lv_obj_set_focus_parent(lv_obj_t * obj, bool en);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable to use parent for gesture related operations.
|
* Enable to use parent for gesture related operations.
|
||||||
* If trying to gesture the object the parent will be moved instead
|
* If trying to gesture the object the parent will be moved instead
|
||||||
@ -1188,6 +1197,15 @@ bool lv_obj_get_drag_throw(const lv_obj_t * obj);
|
|||||||
*/
|
*/
|
||||||
bool lv_obj_get_drag_parent(const lv_obj_t * obj);
|
bool lv_obj_get_drag_parent(const lv_obj_t * obj);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the focus parent attribute of an object
|
||||||
|
* @param obj pointer to an object
|
||||||
|
* @return true: focus parent is enabled
|
||||||
|
*/
|
||||||
|
bool lv_obj_get_focus_parent(const lv_obj_t * obj);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the drag parent attribute of an object
|
* Get the drag parent attribute of an object
|
||||||
* @param obj pointer to an object
|
* @param obj pointer to an object
|
||||||
@ -1319,6 +1337,13 @@ void * lv_obj_get_group(const lv_obj_t * obj);
|
|||||||
*/
|
*/
|
||||||
bool lv_obj_is_focused(const lv_obj_t * obj);
|
bool lv_obj_is_focused(const lv_obj_t * obj);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the really focused object by taking `focus_parent` into account.
|
||||||
|
* @param obj the start object
|
||||||
|
* @return the object to really focus
|
||||||
|
*/
|
||||||
|
lv_obj_t * lv_obj_get_focused_obj(const lv_obj_t * obj);
|
||||||
|
|
||||||
/*-------------------
|
/*-------------------
|
||||||
* OTHER FUNCTIONS
|
* OTHER FUNCTIONS
|
||||||
*------------------*/
|
*------------------*/
|
||||||
|
@ -485,6 +485,9 @@ void lv_page_focus(lv_obj_t * page, const lv_obj_t * obj, lv_anim_enable_t anim_
|
|||||||
lv_anim_del(ext->scrl, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
lv_anim_del(ext->scrl, (lv_anim_exec_xcb_t)lv_obj_set_y);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/*if using focus mode, change target to parent*/
|
||||||
|
obj = lv_obj_get_focused_obj(obj);
|
||||||
|
|
||||||
|
|
||||||
/*If obj is higher then the page focus where the "error" is smaller*/
|
/*If obj is higher then the page focus where the "error" is smaller*/
|
||||||
lv_coord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1;
|
lv_coord_t obj_y = obj->coords.y1 - ext->scrl->coords.y1;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user