zavovi
August 31, 2019, 9:25am
#1
Hi,
please, is it possible move with button when I click on it?
My example:
wifi_screen = lv_cont_create(body, NULL);
lv_cont_set_fit(wifi_screen, false, true);
lv_cont_set_layout(wifi_screen, LV_LAYOUT_COL_M);
lv_obj_t * wifi_button1 = lv_btn_create(wifi_screen, NULL);
lv_btn_set_layout(wifi_button1 , LV_LAYOUT_ROW_M);
lv_obj_set_width(wifi_button1 , APP_SCREEN_WIDTH-40);
lv_obj_set_free_ptr(wifi_button1 , (void*)wifi);
lv_btn_set_action(wifi_button1 , LV_BTN_ACTION_CLICK, _app_screen_ctrl_wifi_btn_click);
lv_obj_t * wifi_button1 = lv_btn_create(wifi_screen, NULL);
lv_btn_set_layout(wifi_button1 , LV_LAYOUT_ROW_M);
lv_obj_set_width(wifi_button1 , APP_SCREEN_WIDTH-40);
lv_obj_set_free_ptr(wifi_button1 , (void*)wifi);
lv_btn_set_action(wifi_button1 , LV_BTN_ACTION_CLICK, _app_screen_ctrl_wifi_btn_click);
Now, I have lot of buttons and I want move clicked button to top. Is it possible?
I tried this:
lv_obj_set_pos(obj, 0, 0);
lv_obj_invalidate(obj);
lv_obj_invalidate(lv_obj_get_parent(obj));
Not working.
Please, could you help me?
I don’t quite understand. Are you trying to move the button to the foreground (i.e. Z-axis) or to the top of the screen (i.e. Y-axis)?
zavovi
August 31, 2019, 1:52pm
#3
I want move to top of the screen (y-axis). I thought order of the buttons. When clicked one of these buttons, it should be first.
If you have a reference to the button, one of these two APIs should work (not sure which one): lv_obj_move_foreground
or lv_obj_move_background
. They adjust whether the button is at the beginning or end of the list of children.
zavovi
August 31, 2019, 4:50pm
#5
Thank you, but I am still using v5.3, is it possible move it in this version? I still have some issues when migrating to v6.0.
These functions are not in the version 5.3
I’m not sure about 5.3. That version is getting old at this point.
zavovi
September 1, 2019, 3:50pm
#7
OK, I understand. I solved with new function.
bool lv_obj_move(lv_obj_t * obj, lv_obj_t * obj_after)
{
lv_obj_t * parent = lv_obj_get_parent(obj);
lv_obj_t * parent_after = NULL;
/* Object must exists and must have parent */
if(obj == NULL || parent == NULL)
return false;
if(obj_after)
parent_after = lv_obj_get_parent(obj_after);
/* Both object must have same parent */
if(obj_after != NULL && parent != parent_after)
return false;
/* Move object in parent list */
lv_ll_move_before(&parent->child_ll, obj, obj_after);
/* Move object in the group list */
lv_group_t * group = obj->group_p;
if(group)
{
lv_obj_t ** obj_pp = NULL;
LL_READ(group->obj_ll, obj_pp)
{
if(*obj_pp == obj)
break;
}
lv_obj_t ** obj_next_pp = NULL;
lv_obj_t * next = lv_ll_get_prev(&parent->child_ll, obj);
if(next)
{
LL_READ(group->obj_ll, obj_next_pp)
{
if(*obj_next_pp == next)
break;
}
}
if(obj_pp)
lv_ll_move_before(&group->obj_ll, obj_pp, obj_next_pp);
}
lv_obj_invalidate(obj);
/*Send a signal to the parent to notify it about the child delete*/
if(parent != NULL)
parent->signal_func(parent, LV_SIGNAL_CHILD_CHG, NULL);
return true;
}
Send a PR to dev-6.1
if you wish; I think that function could be useful in upstream LittlevGL as it gives more flexibility than just moving to the front or back.
I agree with @embeddedt , it would be useful feature in v6.1 too. So please send a PR. (Let us know if you need help with that.)