is there any simple method to unfocus every object on release?
ive faced problem with touchscreen:
when i press button that creates non modal messagebox - it appears and then closes by autoclose function.
then button that called message box stays focused and if i touch the pad anywhere - button presses again. maybe there is some unfocus method on button release event can be added?
This sounds like a possible bug; can you provide a code sample to reproduce?
Does this happen if you create the messagebox in LV_EVENT_CLICKED
instead of LV_EVENT_PRESSED
?
i think i am using message box another way than youve mentioned(i am using code below as notification message)
so for example i am pressing some button - for example button called “Save”, then there is some saving mechanism that calls messagebox. Sometimes “Save” button stays focused (20%) and other (80%) its ok.
void ShowMessage(lv_obj_t* parent,char msg[],int closedelay)
{
//static const char * btns[] ={"Apply", "Close", ""};
lv_obj_t * mbox1 = lv_msgbox_create(parent, NULL);
lv_msgbox_set_text(mbox1, msg);
//lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 500);
//lv_obj_set_event_cb(mbox1, event_handler);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
//lv_msgbox_style_t
lv_obj_add_style(mbox1, LV_OBJ_PART_MAIN, labelbtnstyle_pointer);
lv_msgbox_start_auto_close(mbox1, closedelay);
}
also i have problems with modal window
here`s code almost from example
lv_obj_t *modal_screen;
void ShowModalMessage(lv_obj_t* parent,byte messagetype,const char message[])
{
modal_screen = lv_obj_create(parent, NULL);
lv_obj_reset_style_list(modal_screen, LV_OBJ_PART_MAIN);
lv_obj_add_style(modal_screen, LV_OBJ_PART_MAIN, &style_modal);
lv_obj_set_pos(modal_screen, 0, 0);
lv_obj_set_size(modal_screen, LV_HOR_RES, LV_VER_RES);
static const char * btns[] ={"ok", ""};
msg_box=lv_msgbox_create(modal_screen,NULL);
lv_msgbox_set_text(msg_box, message);
lv_msgbox_add_btns(msg_box,btns);
lv_obj_align(msg_box, NULL, LV_ALIGN_CENTER, 0, 0);
lv_obj_set_event_cb(msg_box, mbox_event_cb);
}
and callback
static void mbox_event_cb(lv_obj_t *obj, lv_event_t evt)
{
if(evt == LV_EVENT_DELETE && obj == msg_box) {
/* Delete the parent modal background */
lv_obj_del_async(lv_obj_get_parent(msg_box));
msg_box = NULL; /* happens before object is actually deleted! */
// lv_label_set_text(info, welcome_info);
} else if(evt == LV_EVENT_VALUE_CHANGED) {
/* A button was clicked */
lv_msgbox_start_auto_close(msg_box, 0);
}
}
this causes errors in console and program freezes
Blockquote
Error: lv_msgbox_start_auto_close (lv_msgbox.c #259 lv_msgbox_start_auto_close())
Error: NULL pointer (0x00000000) (lv_debug.c #127 lv_debug_log_error())
about first problem - i think it happends because there is no focus on message box when it appears,
if i press on message box before it dissapears by autoclose (700ms) , message box closes and focus is turning off. - all works fine.
i think lvgl needs some implementation of unfocus method. i would call it before messagebox create.
Same here.
I have a Button Matrix: after having clicked a button, the whole Button Matrix appears in focus, which is not so nice from a UI standpoint (it also gets a red outline, so aesthetically not pleasing).
Using LVGL 7.9.
Would be nice to have an “unfocus” method
(cc @kisvegabor)
It seems like an issue with your input device driver. Regardless of the button is focused or not it shouldn’t be clicked if you click somewhere else.
Maybe somehow you pass the previously measured coordinate when the TP is pressed again. Please print the X, Y, and “state” data from your driver to see they are really correct.
If possible, please also attach your driver’s code. Maybe we can spot the issue.
@kisvegabor What are your thoughts on having an unfocus method?
You can simple unfocus something with lv_obj_clear_state(obj, LV_STATE_FOCUS)
.
Or to completely prevent focusing by click
lv_obj_add_protect(obj, LV_PROTECT_CLICK_FOCUS)
.
Is there something we can’t easily achive with these?
i am using fb example, with evdev init (usb)
lcd that ive using is waveshare 7" 1024x600 with capacitive touch
issue seems comes when button creates messagebox. if i press to messagebox after it appear, button that called this messagebox change its state to unfocused and all works fine. if i didnt click on messagebox - button stays focused
heres video that demonstrates issue.dropbox
lv_obj_add_protect(btn, LV_PROTECT_CLICK_FOCUS); worked for me!
and `lv_obj_clear_state(obj, LV_STATE_FOCUS) NOT.
actually there is no definition for LV_STATE_FOCUS , but ive changed it to LV_STATE_FOCUSED.
button became unfocused but same glitch happened.
BTW it would be good to add LV_PROTECT_CLICK option. to block button for example.
I still believe it’s a TP driver issue. It seems like you accidentally use the previous pressed coordinate.
I’m not 100% sure, but I have never seen something similar in LVGL so it should be something specific to your system.
Oh, sorry.
lv_obj_set_click(btn, false)
is used for this purpose.
thanks for reply.
the reason that i am thinking that its not touchscreen issue, because if i am not calling messagebox - all works fine. so this happends only when i create messagebox in button callback.
in callback{
if (event==LV_EVENT_RELEASED){ CreateMessageBoxMethod();}
}
works too.
Is it the same with LV_EVENT_CLICKED
?
LV_EVENT_CLICKED seems workis fine too.