mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
- charset module renamed to encoding (decode/encode kept)
- time: get_time_ms → y_gettime, sleep_ms → y_sleep
- time: delete get_time_us, get_time_delta, sleep_s
- string: strdup2 → y_strdup, wcsdup2 → y_wcsdup
- string: strtolower → y_strlower, strtrim → y_strtrim
- string: wcstrim → y_wcstrim, strhash → y_strhash
- string: strreplace → y_strreplace, strsplit → y_strsplit
- string: delete wcsreplace, cmdsplit
- math: delete y_iround, y_pow2
- timer module migrated from yutil to ptk as internal timer_scheduler
- WinMain simplified to use __argc/__argv instead of cmdsplit
BREAKING CHANGE: all renamed yutil public APIs require downstream
to update function names. Deleted APIs require code changes:
- get_time_us: use y_gettime() for ms timestamps
- get_time_delta: use y_gettime() - start instead
- sleep_s: use y_sleep(ms) with millisecond argument
- wcsreplace: no replacement, had zero callers
- cmdsplit: WinMain now uses __argc/__argv from CRT
- timer_list_*: migrated to ptk timer_scheduler_*;
ptk_reset_timer still available for external use
82 lines
2.0 KiB
C
82 lines
2.0 KiB
C
/*
|
|
* tests/cases/test_mainloop.c
|
|
*
|
|
* Copyright (c) 2023, Liu Chao <hello@lcui.dev> All rights reserved.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*
|
|
* This file is part of LCUI, distributed under the MIT License found in the
|
|
* LICENSE.TXT file in the root directory of this source tree.
|
|
*/
|
|
|
|
#include <stdlib.h>
|
|
#include <LCUI.h>
|
|
#include <ctest-custom.h>
|
|
|
|
static void handle_refresh(void *arg)
|
|
{
|
|
ui_refresh_style();
|
|
}
|
|
|
|
static void handle_quit(void *arg)
|
|
{
|
|
lcui_quit();
|
|
}
|
|
|
|
static void handle_btn_click(ui_widget_t *w, ui_event_t *ui_event, void *arg)
|
|
{
|
|
ptk_set_timeout(0, handle_refresh, NULL);
|
|
ptk_set_timeout(1, handle_quit, NULL);
|
|
ptk_process_native_events(PTK_PROCESS_EVENTS_UNTIL_QUIT);
|
|
lcui_quit();
|
|
}
|
|
|
|
static void handle_trigger_btn_click(void *arg)
|
|
{
|
|
ptk_event_t e = { 0 };
|
|
|
|
e.type = PTK_EVENT_MOUSEDOWN;
|
|
e.mouse.button = MOUSE_BUTTON_LEFT;
|
|
e.mouse.x = 5;
|
|
e.mouse.y = 5;
|
|
ptk_post_event(&e);
|
|
e.type = PTK_EVENT_MOUSEUP;
|
|
ptk_post_event(&e);
|
|
}
|
|
|
|
static void observer_thread(void *arg)
|
|
{
|
|
int i;
|
|
bool *exited = arg;
|
|
|
|
for (i = 0; i < 10 && !*exited; ++i) {
|
|
y_sleep(100);
|
|
}
|
|
ctest_equal_bool("should exit main loop within 1000ms", *exited, true);
|
|
if (!*exited) {
|
|
exit(-ctest_finish());
|
|
return;
|
|
}
|
|
thread_exit(NULL);
|
|
}
|
|
|
|
void test_mainloop(void)
|
|
{
|
|
thread_t tid;
|
|
ui_widget_t *btn;
|
|
bool exited = false;
|
|
|
|
lcui_init();
|
|
btn = ui_create_widget("button");
|
|
ui_button_set_text(btn, "button");
|
|
ui_widget_on(btn, "click", handle_btn_click, NULL);
|
|
ui_root_append(btn);
|
|
/* Observe whether the main loop has exited in a new thread */
|
|
thread_create(&tid, observer_thread, &exited);
|
|
/* Trigger the click event after the first frame is updated */
|
|
ptk_set_timeout(50, handle_trigger_btn_click, btn);
|
|
lcui_main();
|
|
exited = true;
|
|
thread_join(tid, NULL);
|
|
}
|