make static not focusable to fix most of the focus issues. change scroll handingine in event callback to make it more robust. see comments

This commit is contained in:
kevin koenig
2022-06-11 15:13:11 +02:00
committed by Raphael Coeffic
parent 17910bc48c
commit bf27d7d512
2 changed files with 18 additions and 9 deletions
+2
View File
@@ -31,6 +31,8 @@ class StaticText: public Window
{
label = lv_label_create(lvobj);
lv_label_set_text(label, this->text.c_str());
lv_obj_clear_flag(label, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_clear_flag(lvobj, LV_OBJ_FLAG_CLICK_FOCUSABLE);
lv_obj_set_style_text_font(lvobj, &lv_font_roboto_13, LV_PART_MAIN);
lv_obj_set_style_text_color(label, makeLvColor(textFlags), LV_PART_MAIN);
+16 -9
View File
@@ -35,11 +35,22 @@ static void window_event_cb(lv_event_t * e)
lv_obj_t *target = lv_event_get_target(e);
lv_event_code_t code = lv_event_get_code(e);
// we do this before looking for user data (libopenui ptr) for this, and in
// fact during delete operations the window will be deleted and you need
// to reset scrolling if you get a pressing as when you are deleting controls
// you get scroll begin events and no scroll end
if (code == LV_EVENT_SCROLL_BEGIN) {
TRACE("SCROLL_BEGIN");
is_scrolling = true;
} else if (code == LV_EVENT_SCROLL_END || code == LV_EVENT_PRESSING) {
TRACE("SCROLL_END");
is_scrolling = false;
}
Window* window = (Window *)lv_obj_get_user_data(target);
if (!window) return;
if(code == LV_EVENT_DELETE ||
window->deleted()) return;
if(code == LV_EVENT_DELETE || window->deleted()) return;
if (code == LV_EVENT_GET_SELF_SIZE) {
@@ -126,12 +137,6 @@ static void window_event_cb(lv_event_t * e)
window->setScrollPositionY(scroll_y);
window->setScrollPositionX(scroll_x);
} else if (code == LV_EVENT_SCROLL_BEGIN) {
TRACE("SCROLL_BEGIN");
is_scrolling = true;
} else if (code == LV_EVENT_SCROLL_END) {
TRACE("SCROLL_END");
is_scrolling = false;
} else if (code == LV_EVENT_FOCUSED) {
bool lvgl_focused = lv_obj_has_state(target, LV_STATE_FOCUSED);
bool loiu_focused = ((Window *)target->user_data)->hasFocus();
@@ -298,7 +303,9 @@ void Window::setFocus(uint8_t flag, Window * from)
if (lvobj != nullptr && !lv_obj_has_state(lvobj, LV_STATE_FOCUSED)) {
lv_obj_add_state(lvobj, LV_STATE_FOCUSED);
if (focusWindow != nullptr) {
lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED | LV_STATE_EDITED);
lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED);
lv_obj_clear_state(focusWindow->lvobj, LV_STATE_EDITED);
// lv_obj_clear_state(focusWindow->lvobj, LV_STATE_FOCUSED | LV_STATE_EDITED);
}
}