Skip to content

Commit

Permalink
fix: widget event does not dispatch
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Sep 7, 2024
1 parent 1d43bd5 commit ecc9f13
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/ui-server/src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -721,12 +721,14 @@ void ui_server_update(void)
float dpi = 1.f * ui_metrics.dpi;

if (ui_server.connections.length > 0) {
logger_error("[ui-server] update all connected widgets\n");
for (list_each(node, &ui_server.connections)) {
conn = node->data;
ui_metrics.dpi = 1.f * app_window_get_dpi(conn->window);
ui_updater_update(conn->updater, conn->widget);
}
} else {
logger_error("[ui-server] update\n");
ui_update();
}
ui_metrics.dpi = dpi;
Expand Down
5 changes: 5 additions & 0 deletions lib/ui/src/ui_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,8 @@ static int ui_on_mouse_event(ui_event_t *origin_event)
switch (e.type) {
case UI_EVENT_MOUSEDOWN:
e.target = ui_resolve_event_target(e.mouse.x, e.mouse.y);
logger_error("UI_EVENT_MOUSEDOWN: %s, xy: %f, %f\n", e.target->type, e.mouse.x, e.mouse.y);
ui_print_tree(NULL);
if (!e.target) {
return -1;
}
Expand All @@ -871,6 +873,8 @@ static int ui_on_mouse_event(ui_event_t *origin_event)
break;
case UI_EVENT_MOUSEUP:
e.target = ui_resolve_event_target(e.mouse.x, e.mouse.y);
logger_error("UI_EVENT_MOUSEUP: %s, xy: %f, %f\n", e.target->type, e.mouse.x, e.mouse.y);
ui_print_tree(NULL);
if (!e.target) {
return -1;
}
Expand Down Expand Up @@ -1151,6 +1155,7 @@ int ui_dispatch_event(ui_event_t *e)
case UI_EVENT_MOUSEDOWN:
case UI_EVENT_MOUSEMOVE:
case UI_EVENT_MOUSEUP:
logger_error("mouse ui_on_mouse_event\n");
return ui_on_mouse_event(e);
case UI_EVENT_KEYPRESS:
case UI_EVENT_KEYDOWN:
Expand Down
2 changes: 2 additions & 0 deletions src/lcui_ui.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,11 @@ void lcui_dispatch_ui_event(app_event_t *app_event)
lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYPRESS, app_event);
break;
case APP_EVENT_MOUSEDOWN:
logger_error("lcui_dispatch_ui_mouse_event: UI_EVENT_MOUSEDOWN\n");
lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEDOWN, app_event);
break;
case APP_EVENT_MOUSEUP:
logger_error("lcui_dispatch_ui_mouse_event: UI_EVENT_MOUSEUP\n");
lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEUP, app_event);
break;
case APP_EVENT_MOUSEMOVE:
Expand Down
6 changes: 4 additions & 2 deletions tests/cases/test_mainloop.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@

static void handle_refresh(void *arg)
{
logger_error("OnRefreshScreen\n");
logger_error("handle_refresh\n");
ui_refresh_style();
}

static void handle_quit(void *arg)
{
logger_error("OnQuit\n");
logger_error("handle_refresh\n");
lcui_quit();
}

Expand All @@ -46,6 +46,7 @@ static void handle_trigger_btn_click(void *arg)
e.type = APP_EVENT_MOUSEUP;
app_post_event(&e);
logger_error("handle_trigger_btn_click\n");
ui_print_tree(NULL);
}

static void observer_thread(void *arg)
Expand Down Expand Up @@ -79,6 +80,7 @@ void test_mainloop(void)
thread_create(&tid, observer_thread, &exited);
/* Trigger the click event after the first frame is updated */
lcui_set_timeout(50, handle_trigger_btn_click, btn);
ui_print_tree(NULL);
lcui_main();
exited = true;
thread_join(tid, NULL);
Expand Down

0 comments on commit ecc9f13

Please sign in to comment.