From bfb81d8563f528e76a48228dffb68864873fac2b Mon Sep 17 00:00:00 2001 From: Liu Date: Sat, 28 Dec 2024 00:41:02 +0800 Subject: [PATCH] refactor: update LCUI's dependencies on ui-widgets and ui-router --- .github/workflows/ccpp.yml | 12 +- .gitignore | 3 - include/LCUI.h | 6 +- include/LCUI/app.h | 93 +----- include/LCUI/base.h | 35 ++ include/LCUI/common.h | 1 + include/LCUI/settings.h | 37 +++ include/LCUI/ui.h | 38 +++ include/LCUI/widgets.h | 21 ++ include/LCUI/widgets/anchor.h | 28 ++ include/LCUI/widgets/button.h | 28 ++ .../LCUI/widgets}/canvas.h | 16 +- include/LCUI/widgets/router_link.h | 30 ++ include/LCUI/widgets/router_view.h | 27 ++ include/LCUI/widgets/scrollarea.h | 53 +++ include/LCUI/widgets/scrollbar.h | 36 +++ include/LCUI/widgets/text.h | 37 +++ include/LCUI/widgets/textcaret.h | 27 ++ include/LCUI/widgets/textinput.h | 63 ++++ include/LCUI/worker.h | 44 +++ lib/css/src/keywords.c | 2 +- lib/i18n/xmake.lua | 2 +- lib/ptk/include/ptk/app.h | 2 +- lib/ptk/src/linux/app.c | 2 +- lib/ptk/src/windows/win32_app.c | 2 +- lib/router/.gitignore | 1 + lib/{ui-router => router}/README.md | 0 lib/{ui-router => router}/README.zh-cn.md | 0 lib/router/include/router.h | 20 ++ lib/router/include/router/common.h | 33 ++ lib/router/include/router/config.h | 36 +++ lib/router/include/router/history.h | 47 +++ .../include/router}/location.h | 36 +-- lib/router/include/router/matcher.h | 34 ++ lib/router/include/router/route.h | 45 +++ lib/router/include/router/route_record.h | 33 ++ lib/router/include/router/router.h | 76 +++++ lib/router/include/router/strmap.h | 47 +++ .../include/router}/types.h | 6 +- lib/router/include/router/utils.h | 50 +++ .../include/router}/version.h | 12 +- lib/{ui-router => router}/src/config.c | 4 +- lib/{ui-router => router}/src/history.c | 6 +- lib/{ui-router => router}/src/location.c | 4 +- lib/{ui-router => router}/src/matcher.c | 10 +- lib/router/src/private.h | 98 ++++++ lib/{ui-router => router}/src/route.c | 6 +- lib/{ui-router => router}/src/route_record.c | 4 +- lib/{ui-router => router}/src/router.c | 6 +- lib/{ui-router => router}/src/strmap.c | 2 +- lib/{ui-router => router}/src/utils.c | 2 +- lib/router/src/version.h.in | 16 + lib/{ui-router => router}/tests/test.c | 106 +----- lib/{ui-router => router}/xmake.lua | 18 +- lib/ui-router/include/ui_router.h | 22 -- lib/ui-router/include/ui_router/common.h | 33 -- lib/ui-router/include/ui_router/config.h | 36 --- lib/ui-router/include/ui_router/history.h | 47 --- lib/ui-router/include/ui_router/link.h | 30 -- lib/ui-router/include/ui_router/matcher.h | 34 -- lib/ui-router/include/ui_router/route.h | 45 --- .../include/ui_router/route_record.h | 33 -- lib/ui-router/include/ui_router/router.h | 76 ----- lib/ui-router/include/ui_router/strmap.h | 47 --- lib/ui-router/include/ui_router/utils.h | 50 --- lib/ui-router/include/ui_router/view.h | 28 -- lib/ui-router/src/private.h | 98 ------ lib/ui-router/src/version.h.in | 16 - lib/ui-server/src/server.c | 4 + lib/ui-widgets/include/ui_widgets.h | 20 -- lib/ui-widgets/include/ui_widgets/anchor.h | 28 -- lib/ui-widgets/include/ui_widgets/button.h | 28 -- lib/ui-widgets/include/ui_widgets/common.h | 33 -- .../include/ui_widgets/scrollarea.h | 53 --- lib/ui-widgets/include/ui_widgets/scrollbar.h | 36 --- lib/ui-widgets/include/ui_widgets/text.h | 38 --- lib/ui-widgets/include/ui_widgets/textcaret.h | 27 -- lib/ui-widgets/include/ui_widgets/textinput.h | 63 ---- lib/ui-widgets/src/config.h.in | 5 - lib/ui-widgets/xmake.lua | 15 - lib/ui/src/ui_resizer.c | 11 + lib/ui/src/ui_resizer.h | 11 + lib/ui/src/ui_widget_layout.h | 11 + src/lcui.c | 124 +------ src/lcui_app.c | 193 +++++++++++ src/lcui_fonts.c | 124 +++++++ src/lcui_settings.c | 3 +- src/lcui_ui.c | 306 ++---------------- src/lcui_widgets.c | 32 ++ src/lcui_worker.c | 67 ++++ {lib/ui-widgets/src => src/widgets}/anchor.c | 4 +- {lib/ui-widgets/src => src/widgets}/button.c | 6 +- {lib/ui-widgets/src => src/widgets}/canvas.c | 4 +- src/widgets/config.h.in | 5 + .../src/link.c => src/widgets/router_link.c | 21 +- .../src/view.c => src/widgets/router_view.c | 7 +- .../src => src/widgets}/scrollarea.c | 4 +- .../src => src/widgets}/scrollbar.c | 6 +- {lib/ui-widgets/src => src/widgets}/text.c | 4 +- .../src => src/widgets}/textcaret.c | 6 +- .../src => src/widgets}/textinput.c | 7 +- .../src => src/widgets}/textstyle.c | 2 +- .../src => src/widgets}/textstyle.h | 2 +- tests/cases/test_mainloop.c | 2 +- tests/cases/test_router.c | 103 ++++++ tests/cases/test_scrollbar.c | 18 +- tests/cases/test_settings.c | 2 +- tests/helloworld_uwp/App.cpp | 4 +- tests/run_tests.c | 1 + tests/run_tests.h | 1 + tests/test_render.c | 4 +- tests/test_widget.c | 2 +- xmake.lua | 8 +- 113 files changed, 1798 insertions(+), 1655 deletions(-) create mode 100644 include/LCUI/base.h create mode 100644 include/LCUI/settings.h create mode 100644 include/LCUI/ui.h create mode 100644 include/LCUI/widgets.h create mode 100644 include/LCUI/widgets/anchor.h create mode 100644 include/LCUI/widgets/button.h rename {lib/ui-widgets/include/ui_widgets => include/LCUI/widgets}/canvas.h (78%) create mode 100644 include/LCUI/widgets/router_link.h create mode 100644 include/LCUI/widgets/router_view.h create mode 100644 include/LCUI/widgets/scrollarea.h create mode 100644 include/LCUI/widgets/scrollbar.h create mode 100644 include/LCUI/widgets/text.h create mode 100644 include/LCUI/widgets/textcaret.h create mode 100644 include/LCUI/widgets/textinput.h create mode 100644 include/LCUI/worker.h create mode 100644 lib/router/.gitignore rename lib/{ui-router => router}/README.md (100%) rename lib/{ui-router => router}/README.zh-cn.md (100%) create mode 100644 lib/router/include/router.h create mode 100644 lib/router/include/router/common.h create mode 100644 lib/router/include/router/config.h create mode 100644 lib/router/include/router/history.h rename lib/{ui-router/include/ui_router => router/include/router}/location.h (50%) create mode 100644 lib/router/include/router/matcher.h create mode 100644 lib/router/include/router/route.h create mode 100644 lib/router/include/router/route_record.h create mode 100644 lib/router/include/router/router.h create mode 100644 lib/router/include/router/strmap.h rename lib/{ui-router/include/ui_router => router/include/router}/types.h (89%) create mode 100644 lib/router/include/router/utils.h rename lib/{ui-router/include/ui_router => router/include/router}/version.h (53%) rename lib/{ui-router => router}/src/config.c (95%) rename lib/{ui-router => router}/src/history.c (97%) rename lib/{ui-router => router}/src/location.c (99%) rename lib/{ui-router => router}/src/matcher.c (98%) create mode 100644 lib/router/src/private.h rename lib/{ui-router => router}/src/route.c (96%) rename lib/{ui-router => router}/src/route_record.c (94%) rename lib/{ui-router => router}/src/router.c (98%) rename lib/{ui-router => router}/src/strmap.c (99%) rename lib/{ui-router => router}/src/utils.c (99%) create mode 100644 lib/router/src/version.h.in rename lib/{ui-router => router}/tests/test.c (84%) rename lib/{ui-router => router}/xmake.lua (74%) delete mode 100644 lib/ui-router/include/ui_router.h delete mode 100644 lib/ui-router/include/ui_router/common.h delete mode 100644 lib/ui-router/include/ui_router/config.h delete mode 100644 lib/ui-router/include/ui_router/history.h delete mode 100644 lib/ui-router/include/ui_router/link.h delete mode 100644 lib/ui-router/include/ui_router/matcher.h delete mode 100644 lib/ui-router/include/ui_router/route.h delete mode 100644 lib/ui-router/include/ui_router/route_record.h delete mode 100644 lib/ui-router/include/ui_router/router.h delete mode 100644 lib/ui-router/include/ui_router/strmap.h delete mode 100644 lib/ui-router/include/ui_router/utils.h delete mode 100644 lib/ui-router/include/ui_router/view.h delete mode 100644 lib/ui-router/src/private.h delete mode 100644 lib/ui-router/src/version.h.in delete mode 100644 lib/ui-widgets/include/ui_widgets.h delete mode 100644 lib/ui-widgets/include/ui_widgets/anchor.h delete mode 100644 lib/ui-widgets/include/ui_widgets/button.h delete mode 100644 lib/ui-widgets/include/ui_widgets/common.h delete mode 100644 lib/ui-widgets/include/ui_widgets/scrollarea.h delete mode 100644 lib/ui-widgets/include/ui_widgets/scrollbar.h delete mode 100644 lib/ui-widgets/include/ui_widgets/text.h delete mode 100644 lib/ui-widgets/include/ui_widgets/textcaret.h delete mode 100644 lib/ui-widgets/include/ui_widgets/textinput.h delete mode 100644 lib/ui-widgets/src/config.h.in delete mode 100644 lib/ui-widgets/xmake.lua create mode 100644 src/lcui_app.c create mode 100644 src/lcui_fonts.c create mode 100644 src/lcui_widgets.c create mode 100644 src/lcui_worker.c rename {lib/ui-widgets/src => src/widgets}/anchor.c (98%) rename {lib/ui-widgets/src => src/widgets}/button.c (91%) rename {lib/ui-widgets/src => src/widgets}/canvas.c (97%) create mode 100644 src/widgets/config.h.in rename lib/ui-router/src/link.c => src/widgets/router_link.c (92%) rename lib/ui-router/src/view.c => src/widgets/router_view.c (97%) rename {lib/ui-widgets/src => src/widgets}/scrollarea.c (99%) rename {lib/ui-widgets/src => src/widgets}/scrollbar.c (99%) rename {lib/ui-widgets/src => src/widgets}/text.c (99%) rename {lib/ui-widgets/src => src/widgets}/textcaret.c (96%) rename {lib/ui-widgets/src => src/widgets}/textinput.c (99%) rename {lib/ui-widgets/src => src/widgets}/textstyle.c (96%) rename {lib/ui-widgets/src => src/widgets}/textstyle.h (91%) create mode 100644 tests/cases/test_router.c diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index f87a5452e..0b4a0f135 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -57,8 +57,8 @@ jobs: xmake build yutil_test xmake build pandagl_tests xmake build libcss_tests - xmake build libui-router-tests - xmake build libi18n-tests + xmake build librouter_tests + xmake build libi18n_tests xmake build lcui_tests - name: Run tests for libraries with memcheck @@ -67,8 +67,8 @@ jobs: xmake run pandagl_tests xmake run yutil_test --memcheck xmake run libcss_tests --memcheck - xmake run libui-router-tests --memcheck - xmake run libi18n-tests --memcheck + xmake run librouter_tests --memcheck + xmake run libi18n_tests --memcheck - name: Run tests for lcui with memcheck if: runner.os == 'Linux' @@ -81,8 +81,8 @@ jobs: xmake run pandagl_tests xmake run yutil_test xmake run libcss_tests - xmake run libui-router-tests - xmake run libi18n-tests + xmake run librouter_tests + xmake run libi18n_tests xmake run lcui_tests - name: Upload reports to Codecov diff --git a/.gitignore b/.gitignore index 355c1d8f8..7186f43e6 100644 --- a/.gitignore +++ b/.gitignore @@ -67,9 +67,6 @@ vendor/lib build/*.png build/*.jpg config.h -!lib/ui-router/include/ui_router/config.h test/build -lcpkg/* -!lcpkg/ports vsxmake* compile_commands.json \ No newline at end of file diff --git a/include/LCUI.h b/include/LCUI.h index 475c828a8..9f5a96447 100644 --- a/include/LCUI.h +++ b/include/LCUI.h @@ -13,11 +13,15 @@ #include #include #include -#include #include #include #include #include #include #include +#include #include +#include +#include +#include +#include diff --git a/include/LCUI/app.h b/include/LCUI/app.h index 5b359020b..98b4a7c3d 100644 --- a/include/LCUI/app.h +++ b/include/LCUI/app.h @@ -13,96 +13,15 @@ #define LCUI_INCLUDE_LCUI_APP_H #include "common.h" -#include -#include - -#define LCUI_MAX_FRAMES_PER_SEC 120 -#define LCUI_MAX_FRAME_MSEC ((int)(1000.0 / LCUI_MAX_FRAMES_PER_SEC + 0.5)) +#include LCUI_BEGIN_HEADER -// Settings - -typedef struct lcui_settings { - int frame_rate_cap; - int parallel_rendering_threads; - bool paint_flashing; -} lcui_settings_t; - -/* Initialize settings with the current global settings. */ -LCUI_API void lcui_get_settings(lcui_settings_t *settings); - -/* Update global settings with the given input. */ -LCUI_API void lcui_apply_settings(lcui_settings_t *settings); - -/* Reset global settings to their defaults. */ -LCUI_API void lcui_reset_settings(void); - -// Tasks - -LCUI_API worker_task_t *lcui_post_task(void *data, worker_task_cb task_cb, - worker_task_cb after_task_cb); -LCUI_API worker_task_t *lcui_post_async_task(void *data, worker_task_cb task_cb, - worker_task_cb after_task_cb); - -bool lcui_cancel_async_task(worker_task_t *task); -bool lcui_cancel_task(worker_task_t *task); - -// UI - -typedef enum lcui_display_mode_t { - LCUI_DISPLAY_MODE_DEFAULT, - LCUI_DISPLAY_MODE_WINDOWED, - LCUI_DISPLAY_MODE_FULLSCREEN, - LCUI_DISPLAY_MODE_SEAMLESS, -} lcui_display_mode_t; - -LCUI_API void lcui_init_ui(void); -LCUI_API void lcui_destroy_ui(void); -LCUI_API void lcui_update_ui(void); -LCUI_API size_t lcui_render_ui(void); -LCUI_API void lcui_preset_ui(void); -LCUI_API void lcui_dispatch_ui_event(ptk_event_t *app_event); -LCUI_API void lcui_set_ui_display_mode(lcui_display_mode_t mode); - -// Event - -LCUI_API int lcui_get_event(ptk_event_t *e); -LCUI_API int lcui_process_event(ptk_event_t *e); -LCUI_API int lcui_process_events(ptk_process_events_option_t option); - -INLINE int lcui_process_all_events(void) -{ - return lcui_process_events(PTK_PROCESS_EVENTS_ALL_IF_PRESENT); -} - -// Base - -LCUI_API uint32_t lcui_get_fps(void); - -LCUI_API void lcui_set_frame_rate_cap(unsigned rate_cap); - -LCUI_API void lcui_init_app(void); -LCUI_API void lcui_destroy_app(void); - -/** 初始化 LCUI 各项功能 */ -LCUI_API void lcui_init(void); - -LCUI_API int lcui_main(void); - -LCUI_API int lcui_run(void); - -/** 获取LCUI的版本 */ -LCUI_API const char *lcui_get_version(void); - -/** 释放LCUI占用的资源 */ -LCUI_API void lcui_destroy(void); - -/** 退出LCUI,释放LCUI占用的资源 */ -LCUI_API void lcui_quit(void); - -/** 退出 LCUI,并设置退出码 */ -LCUI_API void lcui_exit(int code); +LCUI_API uint32_t lcui_app_get_fps(void); +LCUI_API void lcui_app_set_frame_rate_cap(unsigned rate_cap); +LCUI_API int lcui_app_process_events(ptk_process_events_option_t option); +LCUI_API void lcui_app_init(void); +LCUI_API void lcui_app_destroy(void); LCUI_END_HEADER diff --git a/include/LCUI/base.h b/include/LCUI/base.h new file mode 100644 index 000000000..5d1589410 --- /dev/null +++ b/include/LCUI/base.h @@ -0,0 +1,35 @@ +/* + * include/LCUI/base.h + * + * Copyright (c) 2024, Liu Chao 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. + */ + +#ifndef LCUI_INCLUDE_LCUI_BASE_H +#define LCUI_INCLUDE_LCUI_BASE_H + +#include "common.h" + +LCUI_BEGIN_HEADER + +LCUI_API const char *lcui_get_version(void); + +LCUI_API void lcui_init(void); + +LCUI_API void lcui_destroy(void); + +LCUI_API int lcui_run(void); + +LCUI_API int lcui_main(void); + +LCUI_API void lcui_exit(int code); + +LCUI_API void lcui_quit(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/common.h b/include/LCUI/common.h index 4e0b2dad2..e2f6c517f 100644 --- a/include/LCUI/common.h +++ b/include/LCUI/common.h @@ -12,6 +12,7 @@ #ifndef LCUI_INCLUDE_LCUI_COMMON_H #define LCUI_INCLUDE_LCUI_COMMON_H +#include #include "config.h" #ifndef LCUI_API diff --git a/include/LCUI/settings.h b/include/LCUI/settings.h new file mode 100644 index 000000000..dcd5ccc8a --- /dev/null +++ b/include/LCUI/settings.h @@ -0,0 +1,37 @@ +/* + * include/LCUI/settings.h + * + * Copyright (c) 2024, Liu Chao 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. + */ + +#ifndef LCUI_INCLUDE_LCUI_SETTINGS_H +#define LCUI_INCLUDE_LCUI_SETTINGS_H + +#include "common.h" + +#define LCUI_MAX_FRAMES_PER_SEC 120 +#define LCUI_MAX_FRAME_MSEC ((int)(1000.0 / LCUI_MAX_FRAMES_PER_SEC + 0.5)) + +LCUI_BEGIN_HEADER + +typedef struct lcui_settings { + int frame_rate_cap; + int parallel_rendering_threads; + bool paint_flashing; +} lcui_settings_t; + +/* Initialize settings with the current global settings. */ +LCUI_API void lcui_get_settings(lcui_settings_t *settings); + +/* Update global settings with the given input. */ +LCUI_API void lcui_apply_settings(lcui_settings_t *settings); + +/* Reset global settings to their defaults. */ +LCUI_API void lcui_reset_settings(void); + +#endif diff --git a/include/LCUI/ui.h b/include/LCUI/ui.h new file mode 100644 index 000000000..29ec66043 --- /dev/null +++ b/include/LCUI/ui.h @@ -0,0 +1,38 @@ +/* + * include/LCUI/ui.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LCUI_INCLUDE_UI_H +#define LCUI_INCLUDE_UI_H + +#include "common.h" + +LCUI_BEGIN_HEADER + +typedef enum { + LCUI_DISPLAY_DEFAULT, + LCUI_DISPLAY_WINDOWED, + LCUI_DISPLAY_FULLSCREEN, + LCUI_DISPLAY_SEAMLESS, +} lcui_display_t; + +LCUI_API size_t lcui_ui_render(void); + +LCUI_API void lcui_ui_update(void); + +LCUI_API void lcui_ui_set_display(lcui_display_t mode); + +LCUI_API void lcui_ui_init(void); + +LCUI_API void lcui_ui_destroy(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets.h b/include/LCUI/widgets.h new file mode 100644 index 000000000..6734292ec --- /dev/null +++ b/include/LCUI/widgets.h @@ -0,0 +1,21 @@ +/* + * include/LCUI/widgets.h + * + * Copyright (c) 2023-2024, Liu Chao 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 "widgets/text.h" +#include "widgets/button.h" +#include "widgets/anchor.h" +#include "widgets/canvas.h" +#include "widgets/scrollarea.h" +#include "widgets/scrollbar.h" +#include "widgets/textinput.h" +#include "widgets/textcaret.h" +#include "widgets/router_link.h" +#include "widgets/router_view.h" diff --git a/include/LCUI/widgets/anchor.h b/include/LCUI/widgets/anchor.h new file mode 100644 index 000000000..a5194f726 --- /dev/null +++ b/include/LCUI/widgets/anchor.h @@ -0,0 +1,28 @@ +/* + * include/LCUI/widgets/anchor.h: to element in HTML. + * + * Copyright (c) 2018-2024, Liu chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_ANCHOR_H +#define LCUI_INCLUDE_WIDGETS_ANCHOR_H + +#include +#include + +LCUI_BEGIN_HEADER + +LCUI_API void ui_anchor_open(ui_widget_t* w); + +LCUI_API void ui_register_anchor(void); + +LCUI_API void ui_unregister_anchor(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets/button.h b/include/LCUI/widgets/button.h new file mode 100644 index 000000000..237297a47 --- /dev/null +++ b/include/LCUI/widgets/button.h @@ -0,0 +1,28 @@ +/* + * include/LCUI/widgets/button.h: -- LCUI‘s Button widget + * + * Copyright (c) 2018-2024, Liu chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_BUTTON_H +#define LCUI_INCLUDE_WIDGETS_BUTTON_H + +#include +#include + +LCUI_BEGIN_HEADER + +LCUI_API void ui_button_set_text_w(ui_widget_t* w, const wchar_t *wstr); + +LCUI_API void ui_button_set_text(ui_widget_t* w, const char *str); + +LCUI_API void ui_register_button(void); + +LCUI_END_HEADER + +#endif diff --git a/lib/ui-widgets/include/ui_widgets/canvas.h b/include/LCUI/widgets/canvas.h similarity index 78% rename from lib/ui-widgets/include/ui_widgets/canvas.h rename to include/LCUI/widgets/canvas.h index 0e95a93a2..4f8de07c6 100644 --- a/lib/ui-widgets/include/ui_widgets/canvas.h +++ b/include/LCUI/widgets/canvas.h @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/include/ui_widgets/canvas.h: -- canvas, used to draw custom graphics + * include/LCUI/widgets/canvas.h: -- canvas, used to draw custom graphics * * Copyright (c) 2019-2024, Liu chao All rights reserved. * @@ -9,13 +9,13 @@ * LICENSE.TXT file in the root directory of this source tree. */ -#ifndef LIB_UI_WIDGETS_INCLUDE_CANVAS_H -#define LIB_UI_WIDGETS_INCLUDE_CANVAS_H +#ifndef LCUI_INCLUDE_WIDGETS_CANVAS_H +#define LCUI_INCLUDE_WIDGETS_CANVAS_H +#include #include -#include "ui_widgets/common.h" -LIBUI_WIDGETS_BEGIN_DECLS +LCUI_BEGIN_HEADER /** @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/canvas#attributes */ @@ -55,10 +55,10 @@ typedef struct ui_canvas_rendering_context { * Get a drawing context on the canvas * Reference: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext */ -LIBUI_WIDGETS_PUBLIC ui_canvas_context_t *ui_canvas_get_context(ui_widget_t* w); +LCUI_API ui_canvas_context_t *ui_canvas_get_context(ui_widget_t* w); -LIBUI_WIDGETS_PUBLIC void ui_register_canvas(void); +LCUI_API void ui_register_canvas(void); -LIBUI_WIDGETS_END_DECLS +LCUI_END_HEADER #endif diff --git a/include/LCUI/widgets/router_link.h b/include/LCUI/widgets/router_link.h new file mode 100644 index 000000000..4ab3aa12e --- /dev/null +++ b/include/LCUI/widgets/router_link.h @@ -0,0 +1,30 @@ +/* + * include/LCUI/widgets/router_link.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LCUI_INCOIDE_ROUTER_LINK_H +#define LCUI_INCOIDE_ROUTER_LINK_H + +#include +#include +#include + +LCUI_BEGIN_HEADER + +LCUI_API void ui_router_link_set_location( + ui_widget_t *w, router_location_t *location); + +LCUI_API void ui_router_link_set_exact(ui_widget_t *w, bool exact); + +LCUI_API void ui_register_router_link(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets/router_view.h b/include/LCUI/widgets/router_view.h new file mode 100644 index 000000000..ce88a7db3 --- /dev/null +++ b/include/LCUI/widgets/router_view.h @@ -0,0 +1,27 @@ +/* + * include/LCUI/widgets/router_view.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LCUI_INCOIDE_ROUTER_VIEW_H +#define LCUI_INCOIDE_ROUTER_VIEW_H + +#include +#include + +LCUI_BEGIN_HEADER + +LCUI_API ui_widget_t *ui_router_view_get_matched_widget( + ui_widget_t *w); + +LCUI_API void ui_register_router_view(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets/scrollarea.h b/include/LCUI/widgets/scrollarea.h new file mode 100644 index 000000000..062c8ab38 --- /dev/null +++ b/include/LCUI/widgets/scrollarea.h @@ -0,0 +1,53 @@ +/* + * include/LCUI/widgets/scrollarea.h + * + * Copyright (c) 2024, Liu Chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_SCROLLAREA_H +#define LCUI_INCLUDE_WIDGETS_SCROLLAREA_H + +#include +#include + +typedef enum { + UI_SCROLLAREA_AUTO, + UI_SCROLLAREA_VERTICAL, + UI_SCROLLAREA_HORIZONTAL, +} ui_scrollarea_direction_t; + +LCUI_BEGIN_HEADER + +LCUI_API void ui_scrollarea_set_wheel_scroll_direction( + ui_widget_t *w, ui_scrollarea_direction_t direction); + +LCUI_API void ui_scrollarea_update(ui_widget_t *w); + +LCUI_API void ui_register_scrollarea(void); + +LCUI_API ui_widget_t *ui_create_scrollarea(void); + +LCUI_API ui_widget_t *ui_create_scrollarea_content(void); + +LCUI_API void ui_scrollarea_set_scroll_top(ui_widget_t *w, + float value); + +LCUI_API void ui_scrollarea_set_scroll_left(ui_widget_t *w, + float value); + +LCUI_API float ui_scrollarea_get_scroll_top(ui_widget_t *w); + +LCUI_API float ui_scrollarea_get_scroll_left(ui_widget_t *w); + +LCUI_API float ui_scrollarea_get_scroll_width(ui_widget_t *w); + +LCUI_API float ui_scrollarea_get_scroll_height(ui_widget_t *w); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets/scrollbar.h b/include/LCUI/widgets/scrollbar.h new file mode 100644 index 000000000..d314bb0d6 --- /dev/null +++ b/include/LCUI/widgets/scrollbar.h @@ -0,0 +1,36 @@ +/* + * include/LCUI/widgets/scrollbar.h: -- LCUI's scrollbar widget + * + * Copyright (c) 2018-2024, Liu chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_SCROLLBAR_H +#define LCUI_INCLUDE_WIDGETS_SCROLLBAR_H + +#include +#include + +LCUI_BEGIN_HEADER + +typedef enum { + UI_SCROLLBAR_HORIZONTAL, + UI_SCROLLBAR_VERTICAL +} ui_scrollbar_orientation_t; + +LCUI_API void ui_scrollbar_update(ui_widget_t *w); + +LCUI_API void ui_scrollbar_set_orientation(ui_widget_t* w, + ui_scrollbar_orientation_t orientation); + +LCUI_API ui_widget_t *ui_create_scrollbar(void); + +LCUI_API void ui_register_scrollbar(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets/text.h b/include/LCUI/widgets/text.h new file mode 100644 index 000000000..f163932a7 --- /dev/null +++ b/include/LCUI/widgets/text.h @@ -0,0 +1,37 @@ +/* + * include/LCUI/widgets/text.h: -- TextView widget for display + * + * Copyright (c) 2018-2024, Liu chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_TEXT_H +#define LCUI_INCLUDE_WIDGETS_TEXT_H + +#include +#include + +LCUI_BEGIN_HEADER + +LCUI_API int ui_text_set_content_w(ui_widget_t *w, + const wchar_t *text); + +LCUI_API size_t ui_text_get_content_w(ui_widget_t *w, wchar_t *buf, + size_t size); + +LCUI_API int ui_text_set_content(ui_widget_t *w, + const char *utf8_text); + +LCUI_API void ui_text_set_multiline(ui_widget_t *w, bool enable); + +LCUI_API void ui_register_text(void); + +LCUI_API void ui_unregister_text(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/widgets/textcaret.h b/include/LCUI/widgets/textcaret.h new file mode 100644 index 000000000..cd6419e72 --- /dev/null +++ b/include/LCUI/widgets/textcaret.h @@ -0,0 +1,27 @@ +/* + * include/LCUI/widgets/textcaret.h: -- textcaret widget, used in textinput. + * + * Copyright (c) 2018-2024, Liu chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_TEXTCARET_H +#define LCUI_INCLUDE_WIDGETS_TEXTCARET_H + +#include +#include + +LCUI_API void ui_textcaret_refresh(ui_widget_t* widget); + +LCUI_API void ui_textcaret_set_visible(ui_widget_t* widget, bool visible); + +/** 设置闪烁的时间间隔 */ +LCUI_API void ui_textcaret_set_blink_time(ui_widget_t* widget, unsigned int n_ms); + +LCUI_API void ui_register_textcaret(void); + +#endif diff --git a/include/LCUI/widgets/textinput.h b/include/LCUI/widgets/textinput.h new file mode 100644 index 000000000..5a95dee56 --- /dev/null +++ b/include/LCUI/widgets/textinput.h @@ -0,0 +1,63 @@ +/* + * include/LCUI/widgets/textinput.h: -- textinput widget, used to allow user edit text. + * + * Copyright (c) 2018-2024, Liu chao 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. + */ + +#ifndef LCUI_INCLUDE_WIDGETS_TEXTINPUT_H +#define LCUI_INCLUDE_WIDGETS_TEXTINPUT_H + +#include +#include + +LCUI_BEGIN_HEADER + +/** Enable style tag parser */ +LCUI_API void ui_textinput_enable_style_tag(ui_widget_t* widget, bool enable); + +LCUI_API void ui_textinput_enable_multiline(ui_widget_t* widget, bool enable); + +LCUI_API void ui_textinput_move_caret(ui_widget_t* widget, int row, int col); + +/** 清空文本内容 */ +LCUI_API void ui_textinput_clear_text(ui_widget_t* widget); + +/** 获取文本内容 */ +LCUI_API size_t ui_textinput_get_text_w(ui_widget_t* w, size_t start, + size_t max_len, wchar_t *buf); + +/** 获取文本长度 */ +LCUI_API size_t ui_textinput_get_text_length(ui_widget_t* w); + +/** 设置文本编辑框内的光标,指定是否闪烁、闪烁时间间隔 */ +LCUI_API void ui_textinput_set_caret_blink(ui_widget_t* w, bool visible, int time); + + /** 为文本框设置文本(宽字符版) */ +LCUI_API int ui_textinput_set_text_w(ui_widget_t* widget, const wchar_t *wstr); + +LCUI_API int ui_textinput_set_text(ui_widget_t* widget, const char *utf8_str); + +/** 为文本框追加文本(宽字符版) */ +LCUI_API int ui_textinput_append_text_w(ui_widget_t* widget, const wchar_t *wstr); + +/** 为文本框插入文本(宽字符版) */ +LCUI_API int ui_textinput_insert_text_w(ui_widget_t* widget, const wchar_t *wstr); + +/** 设置占位符,当文本编辑框内容为空时显示占位符 */ +LCUI_API int ui_textinput_set_placeholder_w(ui_widget_t* w, const wchar_t *wstr); + +LCUI_API int ui_textinput_set_placeholder(ui_widget_t* w, const char *str); + +/** 设置密码屏蔽符 */ +LCUI_API void ui_textinput_set_password_char(ui_widget_t* w, wchar_t ch); + +LCUI_API void ui_register_textinput(void); + +LCUI_END_HEADER + +#endif diff --git a/include/LCUI/worker.h b/include/LCUI/worker.h new file mode 100644 index 000000000..f2f688a21 --- /dev/null +++ b/include/LCUI/worker.h @@ -0,0 +1,44 @@ +/* + * include/LCUI/worker.h + * + * Copyright (c) 2024, Liu Chao 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. + */ + +#ifndef LCUI_INCLUDE_LCUI_WORKER_H +#define LCUI_INCLUDE_LCUI_WORKER_H + +#include "common.h" +#include + +LCUI_BEGIN_HEADER + +LCUI_API worker_task_t *lcui_worker_post_task(void *data, + worker_task_cb task_cb, + worker_task_cb after_task_cb); + +LCUI_API worker_task_t *lcui_worker_post_async_task( + void *data, worker_task_cb task_cb, worker_task_cb after_task_cb); + +LCUI_API bool lcui_worker_cancel_async_task(worker_task_t *task); + +LCUI_API bool lcui_worker_cancel_task(worker_task_t *task); + +LCUI_API void lcui_worker_run(void); + +LCUI_API void lcui_worker_init(void); + +LCUI_API void lcui_worker_destroy(void); + +LCUI_END_HEADER + +#define lcui_post_task lcui_worker_post_task +#define lcui_post_async_task lcui_worker_post_async_task +#define lcui_cancel_task lcui_worker_cancel_task +#define lcui_cancel_async_task lcui_worker_cancel_async_task + +#endif diff --git a/lib/css/src/keywords.c b/lib/css/src/keywords.c index 2b0909434..2550ff6fb 100644 --- a/lib/css/src/keywords.c +++ b/lib/css/src/keywords.c @@ -1,4 +1,4 @@ -/* +/* * lib/css/src/keywords.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. diff --git a/lib/i18n/xmake.lua b/lib/i18n/xmake.lua index 38a664c5d..047882c3d 100644 --- a/lib/i18n/xmake.lua +++ b/lib/i18n/xmake.lua @@ -20,7 +20,7 @@ target("libi18n") add_defines("LIBI18N_DLL_EXPORT") end -target("libi18n-tests") +target("libi18n_tests") set_default(false) set_kind("binary") add_files("tests/test.c") diff --git a/lib/ptk/include/ptk/app.h b/lib/ptk/include/ptk/app.h index 8ca70c265..18090e435 100644 --- a/lib/ptk/include/ptk/app.h +++ b/lib/ptk/include/ptk/app.h @@ -26,7 +26,7 @@ PTK_PUBLIC ptk_app_id_t ptk_get_app_id(void); PTK_PUBLIC void app_present(void); PTK_PUBLIC int ptk_init(const wchar_t *name); PTK_PUBLIC int ptk_run(void); -PTK_PUBLIC void app_exit(int exit_code); +PTK_PUBLIC void ptk_app_exit(int exit_code); PTK_PUBLIC void ptk_destroy(void); PTK_END_DECLS diff --git a/lib/ptk/src/linux/app.c b/lib/ptk/src/linux/app.c index df5c97903..862a12f02 100644 --- a/lib/ptk/src/linux/app.c +++ b/lib/ptk/src/linux/app.c @@ -171,7 +171,7 @@ void app_present(void) linux_app.app.present(); } -void app_exit(int exit_code) +void ptk_app_exit(int exit_code) { linux_app.app.exit(exit_code); } diff --git a/lib/ptk/src/windows/win32_app.c b/lib/ptk/src/windows/win32_app.c index e869eb068..eae7b441c 100644 --- a/lib/ptk/src/windows/win32_app.c +++ b/lib/ptk/src/windows/win32_app.c @@ -740,7 +740,7 @@ int ptk_app_init(const wchar_t *name) return 0; } -void app_exit(int exit_code) +void ptk_app_exit(int exit_code) { PostQuitMessage(exit_code); } diff --git a/lib/router/.gitignore b/lib/router/.gitignore new file mode 100644 index 000000000..bb678cac2 --- /dev/null +++ b/lib/router/.gitignore @@ -0,0 +1 @@ +!config.h \ No newline at end of file diff --git a/lib/ui-router/README.md b/lib/router/README.md similarity index 100% rename from lib/ui-router/README.md rename to lib/router/README.md diff --git a/lib/ui-router/README.zh-cn.md b/lib/router/README.zh-cn.md similarity index 100% rename from lib/ui-router/README.zh-cn.md rename to lib/router/README.zh-cn.md diff --git a/lib/router/include/router.h b/lib/router/include/router.h new file mode 100644 index 000000000..48f514510 --- /dev/null +++ b/lib/router/include/router.h @@ -0,0 +1,20 @@ +/* + * lib/router/include/router.h + * + * Copyright (c) 2023-2024, Liu Chao 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 +#include +#include +#include +#include +#include +#include +#include +#include diff --git a/lib/router/include/router/common.h b/lib/router/include/router/common.h new file mode 100644 index 000000000..a891f6120 --- /dev/null +++ b/lib/router/include/router/common.h @@ -0,0 +1,33 @@ +/* + * lib/router/include/router/common.h + * + * Copyright (c) 2023-2024, Liu Chao 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 "version.h" +#ifdef __cplusplus +#define LIBROUTER_BEGIN_DECLS extern "C" { +#define LIBROUTER_END_DECLS } +#else +#define LIBROUTER_BEGIN_DECLS +#define LIBROUTER_END_DECLS +#endif + +#ifndef LIBROUTER_PUBLIC +#if defined(_MSC_VER) && !defined(LIBROUTER_STATIC_BUILD) +#ifdef LIBROUTER_DLL_EXPORT +#define LIBROUTER_PUBLIC __declspec(dllexport) +#else +#define LIBROUTER_PUBLIC __declspec(dllimport) +#endif +#elif __GNUC__ >= 4 +#define LIBROUTER_PUBLIC extern __attribute__((visibility("default"))) +#else +#define LIBROUTER_PUBLIC extern +#endif +#endif diff --git a/lib/router/include/router/config.h b/lib/router/include/router/config.h new file mode 100644 index 000000000..5e66fe7eb --- /dev/null +++ b/lib/router/include/router/config.h @@ -0,0 +1,36 @@ +/* + * lib/router/include/router/config.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_CONFIG_H +#define LIB_ROUTER_INCLUDE_ROUTER_CONFIG_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC router_config_t *router_config_create(void); + +LIBROUTER_PUBLIC void router_config_destroy(router_config_t *config); + +LIBROUTER_PUBLIC void router_config_set_name(router_config_t *config, + const char *name); + +LIBROUTER_PUBLIC void router_config_set_path(router_config_t *config, + const char *path); + +LIBROUTER_PUBLIC void router_config_set_component(router_config_t *config, + const char *name, + const char *component); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/router/include/router/history.h b/lib/router/include/router/history.h new file mode 100644 index 000000000..b7f408848 --- /dev/null +++ b/lib/router/include/router/history.h @@ -0,0 +1,47 @@ +/* + * lib/router/include/router/history.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_HISTORY_H +#define LIB_ROUTER_INCLUDE_ROUTER_HISTORY_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC router_history_t *router_history_create(void); + +LIBROUTER_PUBLIC void router_history_destroy(router_history_t *history); + +LIBROUTER_PUBLIC router_watcher_t *router_history_watch( + router_history_t *history, router_callback_t callback, void *data); + +LIBROUTER_PUBLIC void router_history_unwatch(router_history_t *history, + router_watcher_t *watcher); + +LIBROUTER_PUBLIC void router_history_push(router_history_t *history, + router_route_t *route); + +LIBROUTER_PUBLIC void router_history_replace(router_history_t *history, + router_route_t *route); + +LIBROUTER_PUBLIC void router_history_go(router_history_t *history, + int delta); + +LIBROUTER_PUBLIC size_t +router_history_get_index(const router_history_t *history); + +LIBROUTER_PUBLIC size_t +router_history_get_length(const router_history_t *history); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/ui-router/include/ui_router/location.h b/lib/router/include/router/location.h similarity index 50% rename from lib/ui-router/include/ui_router/location.h rename to lib/router/include/router/location.h index 33b836f2d..d4f1d4c18 100644 --- a/lib/ui-router/include/ui_router/location.h +++ b/lib/router/include/router/location.h @@ -1,5 +1,5 @@ /* - * lib/ui-router/include/ui_router/location.h + * lib/router/include/router/location.h * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -9,48 +9,48 @@ * LICENSE.TXT file in the root directory of this source tree. */ -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_LOCATION_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_LOCATION_H +#ifndef LIB_ROUTER_INCLUDE_ROUTER_LOCATION_H +#define LIB_ROUTER_INCLUDE_ROUTER_LOCATION_H -#include -#include +#include +#include -LIBUI_ROUTER_BEGIN_DECLS +LIBROUTER_BEGIN_DECLS -LIBUI_ROUTER_PUBLIC router_location_t *router_location_create(const char *name, +LIBROUTER_PUBLIC router_location_t *router_location_create(const char *name, const char *path); -LIBUI_ROUTER_PUBLIC void router_location_destroy(router_location_t *location); +LIBROUTER_PUBLIC void router_location_destroy(router_location_t *location); -LIBUI_ROUTER_PUBLIC void router_location_set_name(router_location_t *location, +LIBROUTER_PUBLIC void router_location_set_name(router_location_t *location, const char *name); -LIBUI_ROUTER_PUBLIC router_location_t *router_location_duplicate( +LIBROUTER_PUBLIC router_location_t *router_location_duplicate( const router_location_t *location); -LIBUI_ROUTER_PUBLIC router_location_t *router_location_normalize( +LIBROUTER_PUBLIC router_location_t *router_location_normalize( const router_location_t *raw, const router_route_t *current, bool append); -LIBUI_ROUTER_PUBLIC int router_location_set_param(router_location_t *location, +LIBROUTER_PUBLIC int router_location_set_param(router_location_t *location, const char *key, const char *value); -LIBUI_ROUTER_PUBLIC const char *router_location_get_param( +LIBROUTER_PUBLIC const char *router_location_get_param( const router_location_t *location, const char *key); -LIBUI_ROUTER_PUBLIC int router_location_set_query(router_location_t *location, +LIBROUTER_PUBLIC int router_location_set_query(router_location_t *location, const char *key, const char *value); -LIBUI_ROUTER_PUBLIC const char *router_location_get_query( +LIBROUTER_PUBLIC const char *router_location_get_query( const router_location_t *location, const char *key); -LIBUI_ROUTER_PUBLIC const char *router_location_get_path( +LIBROUTER_PUBLIC const char *router_location_get_path( const router_location_t *location); -LIBUI_ROUTER_PUBLIC char *router_location_stringify( +LIBROUTER_PUBLIC char *router_location_stringify( const router_location_t *location); -LIBUI_ROUTER_END_DECLS +LIBROUTER_END_DECLS #endif diff --git a/lib/router/include/router/matcher.h b/lib/router/include/router/matcher.h new file mode 100644 index 000000000..5a45c4bb1 --- /dev/null +++ b/lib/router/include/router/matcher.h @@ -0,0 +1,34 @@ +/* + * lib/router/include/router/matcher.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_MATCHER_H +#define LIB_ROUTER_INCLUDE_ROUTER_MATCHER_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC router_matcher_t *router_matcher_create(void); + +LIBROUTER_PUBLIC void router_matcher_destroy(router_matcher_t *matcher); + +LIBROUTER_PUBLIC router_route_t *router_matcher_match( + router_matcher_t *matcher, const router_location_t *raw_location, + const router_route_t *current_route); + +LIBROUTER_PUBLIC router_route_record_t *router_matcher_add_route_record( + router_matcher_t *matcher, const router_config_t *config, + const router_route_record_t *parent); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/router/include/router/route.h b/lib/router/include/router/route.h new file mode 100644 index 000000000..f811d9ba2 --- /dev/null +++ b/lib/router/include/router/route.h @@ -0,0 +1,45 @@ +/* + * lib/router/include/router/route.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_ROUTE_H +#define LIB_ROUTER_INCLUDE_ROUTER_ROUTE_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC router_route_t *router_route_create( + const router_route_record_t *record, const router_location_t *location); + +LIBROUTER_PUBLIC void router_route_destroy(router_route_t *route); + +LIBROUTER_PUBLIC const router_route_record_t * +router_route_get_matched_record(const router_route_t *route, size_t index); + +LIBROUTER_PUBLIC const char *router_route_get_full_path( + const router_route_t *route); + +LIBROUTER_PUBLIC const char *router_route_get_path( + const router_route_t *route); + +LIBROUTER_PUBLIC const char *router_route_get_hash( + const router_route_t *route); + +LIBROUTER_PUBLIC const char *router_route_get_param( + const router_route_t *route, const char *key); + +LIBROUTER_PUBLIC const char *router_route_get_query( + const router_route_t *route, const char *key); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/router/include/router/route_record.h b/lib/router/include/router/route_record.h new file mode 100644 index 000000000..3eafc27b3 --- /dev/null +++ b/lib/router/include/router/route_record.h @@ -0,0 +1,33 @@ +/* + * lib/router/include/router/route_record.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_ROUTE_RECORD_H +#define LIB_ROUTER_INCLUDE_ROUTER_ROUTE_RECORD_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC router_route_record_t *router_route_record_create(void); + +LIBROUTER_PUBLIC void router_route_record_destroy( + router_route_record_t *record); + +LIBROUTER_PUBLIC void router_route_record_set_path( + router_route_record_t *record, const char *path); + +LIBROUTER_PUBLIC const char *router_route_record_get_component( + const router_route_record_t *record, const char *key); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/router/include/router/router.h b/lib/router/include/router/router.h new file mode 100644 index 000000000..825b4aea5 --- /dev/null +++ b/lib/router/include/router/router.h @@ -0,0 +1,76 @@ +/* + * lib/router/include/router/router.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_ROUTER_H +#define LIB_ROUTER_INCLUDE_ROUTER_ROUTER_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC router_t *router_create(const char *name); + +LIBROUTER_PUBLIC void router_destroy(router_t *router); + +LIBROUTER_PUBLIC router_route_record_t *router_add_route_record( + router_t *router, const router_config_t *config, + const router_route_record_t *parent); + +LIBROUTER_PUBLIC router_route_t *router_match( + router_t *router, const router_location_t *raw_location, + const router_route_t *current_route); + +LIBROUTER_PUBLIC router_route_record_t *router_get_matched_route_record( + router_t *router, size_t index); + +LIBROUTER_PUBLIC router_history_t *router_get_history(router_t *router); + +LIBROUTER_PUBLIC router_watcher_t *router_watch(router_t *router, + router_callback_t callback, + void *data); + +LIBROUTER_PUBLIC void router_unwatch(router_t *router, + router_watcher_t *watcher); + +LIBROUTER_PUBLIC router_resolved_t *router_resolve( + router_t *router, router_location_t *location, bool append); + +LIBROUTER_PUBLIC router_location_t *router_resolved_get_location( + router_resolved_t *resolved); + +LIBROUTER_PUBLIC router_route_t *router_resolved_get_route( + router_resolved_t *resolved); + +LIBROUTER_PUBLIC void router_resolved_destroy(router_resolved_t *resolved); + +LIBROUTER_PUBLIC const router_route_t *router_get_current_route( + router_t *router); + +LIBROUTER_PUBLIC void router_push(router_t *router, + router_location_t *location); + +LIBROUTER_PUBLIC void router_replace(router_t *router, + router_location_t *location); + +LIBROUTER_PUBLIC void router_go(router_t *router, int delta); + +LIBROUTER_PUBLIC void router_back(router_t *router); + +LIBROUTER_PUBLIC void router_forward(router_t *router); + +LIBROUTER_PUBLIC router_t *router_get_by_name(const char *name); + +LIBROUTER_PUBLIC const char *router_get_version(void); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/router/include/router/strmap.h b/lib/router/include/router/strmap.h new file mode 100644 index 000000000..59ec51d6c --- /dev/null +++ b/lib/router/include/router/strmap.h @@ -0,0 +1,47 @@ +/* + * lib/router/include/router/strmap.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_STRMAP_H +#define LIB_ROUTER_INCLUDE_ROUTER_STRMAP_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC strmap_t *strmap_create(void); + +LIBROUTER_PUBLIC void strmap_destroy(strmap_t *dict); + +LIBROUTER_PUBLIC void strmap_delete(strmap_t *dict, const char *key); + +LIBROUTER_PUBLIC int strmap_set(strmap_t *dict, const char *key, + const char *value); + +LIBROUTER_PUBLIC const char *strmap_get(strmap_t *dict, const char *key); + +LIBROUTER_PUBLIC size_t strmap_extend(strmap_t *target, strmap_t *other); + +LIBROUTER_PUBLIC strmap_t *strmap_duplicate(strmap_t *target); + +LIBROUTER_PUBLIC bool strmap_includes(strmap_t *a, strmap_t *b); + +LIBROUTER_PUBLIC bool strmap_equal(strmap_t *a, strmap_t *b); + +LIBROUTER_PUBLIC strmap_iterator_t *strmap_get_iterator(strmap_t *map); + +LIBROUTER_PUBLIC void strmap_destroy_iterator(strmap_iterator_t *iter); + +LIBROUTER_PUBLIC strmap_item_t *strmap_next(strmap_iterator_t *iter); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/ui-router/include/ui_router/types.h b/lib/router/include/router/types.h similarity index 89% rename from lib/ui-router/include/ui_router/types.h rename to lib/router/include/router/types.h index 29578a106..c9aca935a 100644 --- a/lib/ui-router/include/ui_router/types.h +++ b/lib/router/include/router/types.h @@ -1,5 +1,5 @@ /* - * lib/ui-router/include/ui_router/types.h + * lib/router/include/router/types.h * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -9,8 +9,8 @@ * LICENSE.TXT file in the root directory of this source tree. */ -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_TYPES_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_TYPES_H +#ifndef LIB_ROUTER_INCLUDE_ROUTER_TYPES_H +#define LIB_ROUTER_INCLUDE_ROUTER_TYPES_H #include #include diff --git a/lib/router/include/router/utils.h b/lib/router/include/router/utils.h new file mode 100644 index 000000000..96d6ee677 --- /dev/null +++ b/lib/router/include/router/utils.h @@ -0,0 +1,50 @@ +/* + * lib/router/include/router/utils.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef LIB_ROUTER_INCLUDE_ROUTER_UTILS_H +#define LIB_ROUTER_INCLUDE_ROUTER_UTILS_H + +#include +#include + +LIBROUTER_BEGIN_DECLS + +LIBROUTER_PUBLIC char *router_path_fill_params(const char *path, + strmap_t *params); + +LIBROUTER_PUBLIC const char *router_path_parse_key(const char *path, + char key[256], + size_t *key_len); + +LIBROUTER_PUBLIC size_t router_path_parse_keys(const char *path, + router_linkedlist_t *keys); + +LIBROUTER_PUBLIC char *router_path_resolve(const char *relative, + const char *base, bool append); + +LIBROUTER_PUBLIC strmap_t *router_parse_query(const char *query_str); + +LIBROUTER_PUBLIC int router_string_compare(const char *a, const char *b); + +LIBROUTER_PUBLIC int router_path_compare(const char *a, const char *b); + +LIBROUTER_PUBLIC bool router_path_starts_with(const char *path, + const char *subpath); + +LIBROUTER_PUBLIC bool router_is_same_route(const router_route_t *a, + const router_route_t *b); + +LIBROUTER_PUBLIC bool router_is_included_route(const router_route_t *current, + const router_route_t *target); + +LIBROUTER_END_DECLS + +#endif diff --git a/lib/ui-router/include/ui_router/version.h b/lib/router/include/router/version.h similarity index 53% rename from lib/ui-router/include/ui_router/version.h rename to lib/router/include/router/version.h index a767849ef..4bc8d22a5 100644 --- a/lib/ui-router/include/ui_router/version.h +++ b/lib/router/include/router/version.h @@ -1,5 +1,5 @@ /* - * lib/ui-router/include/ui_router/version.h + * lib/router/include/router/version.h * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -9,8 +9,8 @@ * LICENSE.TXT file in the root directory of this source tree. */ -#define LIBUI_ROUTER_VERSION "0.1.0-a" -#define LIBUI_ROUTER_VERSION_MAJOR 0 -#define LIBUI_ROUTER_VERSION_MINOR 1 -#define LIBUI_ROUTER_VERSION_ALTER 0 -#define LIBUI_ROUTER_STATIC_BUILD 1 +#define LIBROUTER_VERSION "0.1.0-a" +#define LIBROUTER_VERSION_MAJOR 0 +#define LIBROUTER_VERSION_MINOR 1 +#define LIBROUTER_VERSION_ALTER 0 +#define LIBROUTER_STATIC_BUILD 1 diff --git a/lib/ui-router/src/config.c b/lib/router/src/config.c similarity index 95% rename from lib/ui-router/src/config.c rename to lib/router/src/config.c index 3cde182a7..a1f369245 100644 --- a/lib/ui-router/src/config.c +++ b/lib/router/src/config.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/config.c + * lib/router/src/config.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,7 +10,7 @@ */ #include "private.h" -#include +#include router_config_t *router_config_create(void) { diff --git a/lib/ui-router/src/history.c b/lib/router/src/history.c similarity index 97% rename from lib/ui-router/src/history.c rename to lib/router/src/history.c index 413ad2bd0..f24c7e0a5 100644 --- a/lib/ui-router/src/history.c +++ b/lib/router/src/history.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/history.c + * lib/router/src/history.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,8 +10,8 @@ */ #include "private.h" -#include -#include +#include +#include router_history_t *router_history_create(void) { diff --git a/lib/ui-router/src/location.c b/lib/router/src/location.c similarity index 99% rename from lib/ui-router/src/location.c rename to lib/router/src/location.c index 8d1da71cf..a03e830cb 100644 --- a/lib/ui-router/src/location.c +++ b/lib/router/src/location.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/location.c + * lib/router/src/location.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,7 +10,7 @@ */ #include "private.h" -#include +#include router_location_t *router_location_create(const char *name, const char *path) { diff --git a/lib/ui-router/src/matcher.c b/lib/router/src/matcher.c similarity index 98% rename from lib/ui-router/src/matcher.c rename to lib/router/src/matcher.c index a11183715..db7a13499 100644 --- a/lib/ui-router/src/matcher.c +++ b/lib/router/src/matcher.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/matcher.c + * lib/router/src/matcher.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,10 +10,10 @@ */ #include "private.h" -#include -#include -#include -#include +#include +#include +#include +#include router_matcher_t *router_matcher_create(void) { diff --git a/lib/router/src/private.h b/lib/router/src/private.h new file mode 100644 index 000000000..a3178b1c3 --- /dev/null +++ b/lib/router/src/private.h @@ -0,0 +1,98 @@ +/* + * lib/router/src/private.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#ifndef ROUTER_PRIVATE_H +#define ROUTER_PRIVATE_H + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#pragma warning(disable : 4996) +#endif + +#define router_mem_free(ptr) \ + do { \ + if (ptr) { \ + free(ptr); \ + } \ + ptr = NULL; \ + } while (0) + +struct router_location { + char *name; + char *path; + char *hash; + strmap_t *params; + strmap_t *query; + bool normalized; +}; + +struct router_route { + char *name; + char *path; + char *full_path; + char *hash; + strmap_t *query; + strmap_t *params; + router_linkedlist_t matched; +}; + +struct router_route_record { + char *name; + char *path; + const router_route_record_t *parent; + strmap_t *components; + router_linkedlist_node_t node; +}; + +struct router_history { + int index; + router_route_t *current; + router_linkedlist_t routes; + router_linkedlist_t watchers; +}; + +struct router_config { + char *name; + char *path; + strmap_t *components; +}; + +struct router_matcher { + dict_t *name_map; + dict_t *path_map; + router_linkedlist_t path_list; +}; + +struct router_watcher { + void *data; + router_callback_t callback; + router_linkedlist_node_t node; +}; + +struct router_resolved { + router_route_t *route; + router_location_t *location; +}; + +struct router { + char *name; + char *link_active_class; + char *link_exact_active_class; + router_matcher_t *matcher; + router_history_t *history; +}; + +#endif diff --git a/lib/ui-router/src/route.c b/lib/router/src/route.c similarity index 96% rename from lib/ui-router/src/route.c rename to lib/router/src/route.c index f24e435f9..15909fa64 100644 --- a/lib/ui-router/src/route.c +++ b/lib/router/src/route.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/route.c + * lib/router/src/route.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,8 +10,8 @@ */ #include "private.h" -#include -#include +#include +#include // https://github.com/vuejs/vue-router/blob/65de048ee9f0ebf899ae99c82b71ad397727e55d/dist/vue-router.esm.js#L266 diff --git a/lib/ui-router/src/route_record.c b/lib/router/src/route_record.c similarity index 94% rename from lib/ui-router/src/route_record.c rename to lib/router/src/route_record.c index ce6a5ac74..19babfc2d 100644 --- a/lib/ui-router/src/route_record.c +++ b/lib/router/src/route_record.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/route_record.c + * lib/router/src/route_record.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,7 +10,7 @@ */ #include "private.h" -#include +#include router_route_record_t *router_route_record_create(void) { diff --git a/lib/ui-router/src/router.c b/lib/router/src/router.c similarity index 98% rename from lib/ui-router/src/router.c rename to lib/router/src/router.c index 9921d241c..e01947c54 100644 --- a/lib/ui-router/src/router.c +++ b/lib/router/src/router.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/router.c + * lib/router/src/router.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -10,7 +10,7 @@ */ #include "private.h" -#include +#include static dict_t *routers = NULL; static dict_type_t routers_dict_type; @@ -177,5 +177,5 @@ router_t *router_get_by_name(const char *name) const char *router_get_version(void) { - return LIBUI_ROUTER_VERSION; + return LIBROUTER_VERSION; } diff --git a/lib/ui-router/src/strmap.c b/lib/router/src/strmap.c similarity index 99% rename from lib/ui-router/src/strmap.c rename to lib/router/src/strmap.c index 65916c13a..f71486cc7 100644 --- a/lib/ui-router/src/strmap.c +++ b/lib/router/src/strmap.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/strmap.c + * lib/router/src/strmap.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * diff --git a/lib/ui-router/src/utils.c b/lib/router/src/utils.c similarity index 99% rename from lib/ui-router/src/utils.c rename to lib/router/src/utils.c index 2a79149ff..0823d4a43 100644 --- a/lib/ui-router/src/utils.c +++ b/lib/router/src/utils.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/utils.c + * lib/router/src/utils.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * diff --git a/lib/router/src/version.h.in b/lib/router/src/version.h.in new file mode 100644 index 000000000..6939b9fc1 --- /dev/null +++ b/lib/router/src/version.h.in @@ -0,0 +1,16 @@ +/* + * lib/ui-router/include/router/version.h + * + * Copyright (c) 2023-2024, Liu Chao 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. + */ + +#define LIBROUTER_VERSION "${VERSION}" +#define LIBROUTER_VERSION_MAJOR ${VERSION_MAJOR} +#define LIBROUTER_VERSION_MINOR ${VERSION_MINOR} +#define LIBROUTER_VERSION_ALTER ${VERSION_ALTER} +${define LIBROUTER_STATIC_BUILD} diff --git a/lib/ui-router/tests/test.c b/lib/router/tests/test.c similarity index 84% rename from lib/ui-router/tests/test.c rename to lib/router/tests/test.c index 658cf56a8..af81bc5bf 100644 --- a/lib/ui-router/tests/test.c +++ b/lib/router/tests/test.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/tests/test.c + * lib/router/tests/test.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -11,8 +11,7 @@ #include "../src/private.h" #include -#include -#include +#include void test_router_location(void) { @@ -565,106 +564,6 @@ void test_router_history(void) router_destroy(router); } -void test_router_components(void) -{ - router_t *router; - router_config_t *config; - ui_widget_t *root; - ui_widget_t *link_foo; - ui_widget_t *link_foobar; - ui_widget_t *link_bar; - ui_widget_t *view; - ui_widget_t *matched_widget; - ui_event_t e; - - router = router_create(NULL); - config = router_config_create(); - router_config_set_path(config, "/foo"); - router_config_set_component(config, NULL, "foo"); - router_add_route_record(router, config, NULL); - router_config_destroy(config); - - config = router_config_create(); - router_config_set_path(config, "/foo/bar"); - router_config_set_component(config, NULL, "foobar"); - router_add_route_record(router, config, NULL); - router_config_destroy(config); - - config = router_config_create(); - router_config_set_path(config, "/bar"); - router_config_set_component(config, NULL, "bar"); - router_add_route_record(router, config, NULL); - router_config_destroy(config); - - ui_init(); - ui_register_text(); - ui_register_router_link(); - ui_register_router_view(); - ui_create_widget_prototype("foo", NULL); - ui_create_widget_prototype("foobar", NULL); - ui_create_widget_prototype("bar", NULL); - root = ui_root(); - view = ui_create_widget("router-view"); - link_foo = ui_create_widget("router-link"); - link_foobar = ui_create_widget("router-link"); - link_bar = ui_create_widget("router-link"); - ui_widget_set_attr(link_foo, "to", "/foo"); - ui_widget_set_attr(link_foobar, "to", "/foo/bar"); - ui_widget_set_attr(link_bar, "to", "/bar"); - ui_widget_append(root, link_foo); - ui_widget_append(root, link_foobar); - ui_widget_append(root, link_bar); - ui_widget_append(root, view); - ui_update(); - - ui_event_init(&e, "click"); - ui_widget_emit_event(link_foo, e, NULL); - // ui_update(); - matched_widget = ui_router_view_get_matched_widget(view); - ctest_equal_bool("[/foo] widget should load widget", - strcmp(matched_widget->type, "foo") == 0, true); - ctest_equal_bool( - "[/foo] linkFoo should has active classes", - (ui_widget_has_class(link_foo, "router-link-active") && - ui_widget_has_class(link_foo, "router-link-exact-active")), - true); - ui_widget_emit_event(link_bar, e, NULL); - matched_widget = ui_router_view_get_matched_widget(view); - ctest_equal_bool("[/bar] widget should load widget", - strcmp(matched_widget->type, "bar") == 0, true); - ctest_equal_bool( - "[/bar] linkFoo should not has active classes", - (!ui_widget_has_class(link_foo, "router-link-exact-active") && - !ui_widget_has_class(link_foo, "router-link-active")), - true); - - ui_widget_emit_event(link_foobar, e, NULL); - matched_widget = ui_router_view_get_matched_widget(view); - ctest_equal_bool( - "[/foo/bar] widget should load widget", - strcmp(matched_widget->type, "foobar") == 0, true); - ctest_equal_bool( - "[/foo/bar] linkFooBar should has active classes", - (ui_widget_has_class(link_foobar, "router-link-exact-active") && - ui_widget_has_class(link_foobar, "router-link-active")), - true); - ctest_equal_bool( - "[/foo/bar] linkFoo should only has the exact active class", - (!ui_widget_has_class(link_foo, "router-link-exact-active") && - ui_widget_has_class(link_foo, "router-link-active")), - true); - ui_widget_set_attr(link_foo, "exact", "exact"); - ui_widget_emit_event(link_foobar, e, NULL); - ctest_equal_bool( - "[/foo/bar] linkFoo should not has any active classes (exact)", - (!ui_widget_has_class(link_foo, "router-link-exact-active") && - !ui_widget_has_class(link_foo, "router-link-active")), - true); - - ui_destroy(); - router_destroy(router); -} - int main(void) { logger_set_level(LOGGER_LEVEL_OFF); @@ -673,6 +572,5 @@ int main(void) ctest_describe("router route", test_router_route); ctest_describe("router matcher", test_router_matcher); ctest_describe("router history", test_router_history); - ctest_describe("router components", test_router_components); return ctest_finish(); } diff --git a/lib/ui-router/xmake.lua b/lib/router/xmake.lua similarity index 74% rename from lib/ui-router/xmake.lua rename to lib/router/xmake.lua index 4a221e2f4..9d1833b84 100644 --- a/lib/ui-router/xmake.lua +++ b/lib/router/xmake.lua @@ -1,24 +1,24 @@ -set_project("libui-router") +set_project("librouter") set_version("0.1.0-a") -target("libui-router") +target("librouter") set_kind("$(kind)") add_files("src/*.c") - add_deps("yutil", "libui", "libui-widgets") - set_configdir("include/ui_router") + add_deps("yutil", "libui") + set_configdir("include/router") add_configfiles("src/version.h.in") - add_headerfiles("include/ui_router.h", "include/(ui_router/*.h)") + add_headerfiles("include/router.h", "include/(router/*.h)") if is_kind("static") then - set_configvar("LIBUI_ROUTER_STATIC_BUILD", 1) + set_configvar("LIBROUTER_STATIC_BUILD", 1) elseif is_plat("windows") then - add_defines("LIBUI_ROUTER_DLL_EXPORT") + add_defines("LIBROUTER_DLL_EXPORT") end -target("libui-router-tests") +target("librouter_tests") set_default(false) set_kind("binary") add_files("tests/test.c") - add_deps("libui-router", "ctest") + add_deps("librouter", "ctest") on_run(function (target) import("core.base.option") local argv = {} diff --git a/lib/ui-router/include/ui_router.h b/lib/ui-router/include/ui_router.h deleted file mode 100644 index a0b03f500..000000000 --- a/lib/ui-router/include/ui_router.h +++ /dev/null @@ -1,22 +0,0 @@ -/* - * lib/ui-router/include/ui_router.h - * - * Copyright (c) 2023-2024, Liu Chao 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 -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include diff --git a/lib/ui-router/include/ui_router/common.h b/lib/ui-router/include/ui_router/common.h deleted file mode 100644 index afb189f24..000000000 --- a/lib/ui-router/include/ui_router/common.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * lib/ui-router/include/ui_router/common.h - * - * Copyright (c) 2023-2024, Liu Chao 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 "version.h" -#ifdef __cplusplus -#define LIBUI_ROUTER_BEGIN_DECLS extern "C" { -#define LIBUI_ROUTER_END_DECLS } -#else -#define LIBUI_ROUTER_BEGIN_DECLS -#define LIBUI_ROUTER_END_DECLS -#endif - -#ifndef LIBUI_ROUTER_PUBLIC -#if defined(_MSC_VER) && !defined(LIBUI_ROUTER_STATIC_BUILD) -#ifdef LIBUI_ROUTER_DLL_EXPORT -#define LIBUI_ROUTER_PUBLIC __declspec(dllexport) -#else -#define LIBUI_ROUTER_PUBLIC __declspec(dllimport) -#endif -#elif __GNUC__ >= 4 -#define LIBUI_ROUTER_PUBLIC extern __attribute__((visibility("default"))) -#else -#define LIBUI_ROUTER_PUBLIC extern -#endif -#endif diff --git a/lib/ui-router/include/ui_router/config.h b/lib/ui-router/include/ui_router/config.h deleted file mode 100644 index 0fb76fa78..000000000 --- a/lib/ui-router/include/ui_router/config.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * lib/ui-router/include/ui_router/config.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_CONFIG_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_CONFIG_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC router_config_t *router_config_create(void); - -LIBUI_ROUTER_PUBLIC void router_config_destroy(router_config_t *config); - -LIBUI_ROUTER_PUBLIC void router_config_set_name(router_config_t *config, - const char *name); - -LIBUI_ROUTER_PUBLIC void router_config_set_path(router_config_t *config, - const char *path); - -LIBUI_ROUTER_PUBLIC void router_config_set_component(router_config_t *config, - const char *name, - const char *component); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/history.h b/lib/ui-router/include/ui_router/history.h deleted file mode 100644 index 68e37b6ae..000000000 --- a/lib/ui-router/include/ui_router/history.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * lib/ui-router/include/ui_router/history.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_HISTORY_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_HISTORY_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC router_history_t *router_history_create(void); - -LIBUI_ROUTER_PUBLIC void router_history_destroy(router_history_t *history); - -LIBUI_ROUTER_PUBLIC router_watcher_t *router_history_watch( - router_history_t *history, router_callback_t callback, void *data); - -LIBUI_ROUTER_PUBLIC void router_history_unwatch(router_history_t *history, - router_watcher_t *watcher); - -LIBUI_ROUTER_PUBLIC void router_history_push(router_history_t *history, - router_route_t *route); - -LIBUI_ROUTER_PUBLIC void router_history_replace(router_history_t *history, - router_route_t *route); - -LIBUI_ROUTER_PUBLIC void router_history_go(router_history_t *history, - int delta); - -LIBUI_ROUTER_PUBLIC size_t -router_history_get_index(const router_history_t *history); - -LIBUI_ROUTER_PUBLIC size_t -router_history_get_length(const router_history_t *history); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/link.h b/lib/ui-router/include/ui_router/link.h deleted file mode 100644 index 61cece297..000000000 --- a/lib/ui-router/include/ui_router/link.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * lib/ui-router/include/ui_router/link.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_LINK_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_LINK_H - -#include -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC void ui_router_link_set_location( - ui_widget_t *w, router_location_t *location); - -LIBUI_ROUTER_PUBLIC void ui_router_link_set_exact(ui_widget_t *w, bool exact); - -LIBUI_ROUTER_PUBLIC void ui_register_router_link(void); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/matcher.h b/lib/ui-router/include/ui_router/matcher.h deleted file mode 100644 index 28ed1f3c2..000000000 --- a/lib/ui-router/include/ui_router/matcher.h +++ /dev/null @@ -1,34 +0,0 @@ -/* - * lib/ui-router/include/ui_router/matcher.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_MATCHER_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_MATCHER_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC router_matcher_t *router_matcher_create(void); - -LIBUI_ROUTER_PUBLIC void router_matcher_destroy(router_matcher_t *matcher); - -LIBUI_ROUTER_PUBLIC router_route_t *router_matcher_match( - router_matcher_t *matcher, const router_location_t *raw_location, - const router_route_t *current_route); - -LIBUI_ROUTER_PUBLIC router_route_record_t *router_matcher_add_route_record( - router_matcher_t *matcher, const router_config_t *config, - const router_route_record_t *parent); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/route.h b/lib/ui-router/include/ui_router/route.h deleted file mode 100644 index aad0dd32a..000000000 --- a/lib/ui-router/include/ui_router/route.h +++ /dev/null @@ -1,45 +0,0 @@ -/* - * lib/ui-router/include/ui_router/route.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_ROUTE_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_ROUTE_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC router_route_t *router_route_create( - const router_route_record_t *record, const router_location_t *location); - -LIBUI_ROUTER_PUBLIC void router_route_destroy(router_route_t *route); - -LIBUI_ROUTER_PUBLIC const router_route_record_t * -router_route_get_matched_record(const router_route_t *route, size_t index); - -LIBUI_ROUTER_PUBLIC const char *router_route_get_full_path( - const router_route_t *route); - -LIBUI_ROUTER_PUBLIC const char *router_route_get_path( - const router_route_t *route); - -LIBUI_ROUTER_PUBLIC const char *router_route_get_hash( - const router_route_t *route); - -LIBUI_ROUTER_PUBLIC const char *router_route_get_param( - const router_route_t *route, const char *key); - -LIBUI_ROUTER_PUBLIC const char *router_route_get_query( - const router_route_t *route, const char *key); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/route_record.h b/lib/ui-router/include/ui_router/route_record.h deleted file mode 100644 index e66913d28..000000000 --- a/lib/ui-router/include/ui_router/route_record.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * lib/ui-router/include/ui_router/route_record.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_ROUTE_RECORD_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_ROUTE_RECORD_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC router_route_record_t *router_route_record_create(void); - -LIBUI_ROUTER_PUBLIC void router_route_record_destroy( - router_route_record_t *record); - -LIBUI_ROUTER_PUBLIC void router_route_record_set_path( - router_route_record_t *record, const char *path); - -LIBUI_ROUTER_PUBLIC const char *router_route_record_get_component( - const router_route_record_t *record, const char *key); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/router.h b/lib/ui-router/include/ui_router/router.h deleted file mode 100644 index dd5589000..000000000 --- a/lib/ui-router/include/ui_router/router.h +++ /dev/null @@ -1,76 +0,0 @@ -/* - * lib/ui-router/include/ui_router/router.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_ROUTER_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_ROUTER_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC router_t *router_create(const char *name); - -LIBUI_ROUTER_PUBLIC void router_destroy(router_t *router); - -LIBUI_ROUTER_PUBLIC router_route_record_t *router_add_route_record( - router_t *router, const router_config_t *config, - const router_route_record_t *parent); - -LIBUI_ROUTER_PUBLIC router_route_t *router_match( - router_t *router, const router_location_t *raw_location, - const router_route_t *current_route); - -LIBUI_ROUTER_PUBLIC router_route_record_t *router_get_matched_route_record( - router_t *router, size_t index); - -LIBUI_ROUTER_PUBLIC router_history_t *router_get_history(router_t *router); - -LIBUI_ROUTER_PUBLIC router_watcher_t *router_watch(router_t *router, - router_callback_t callback, - void *data); - -LIBUI_ROUTER_PUBLIC void router_unwatch(router_t *router, - router_watcher_t *watcher); - -LIBUI_ROUTER_PUBLIC router_resolved_t *router_resolve( - router_t *router, router_location_t *location, bool append); - -LIBUI_ROUTER_PUBLIC router_location_t *router_resolved_get_location( - router_resolved_t *resolved); - -LIBUI_ROUTER_PUBLIC router_route_t *router_resolved_get_route( - router_resolved_t *resolved); - -LIBUI_ROUTER_PUBLIC void router_resolved_destroy(router_resolved_t *resolved); - -LIBUI_ROUTER_PUBLIC const router_route_t *router_get_current_route( - router_t *router); - -LIBUI_ROUTER_PUBLIC void router_push(router_t *router, - router_location_t *location); - -LIBUI_ROUTER_PUBLIC void router_replace(router_t *router, - router_location_t *location); - -LIBUI_ROUTER_PUBLIC void router_go(router_t *router, int delta); - -LIBUI_ROUTER_PUBLIC void router_back(router_t *router); - -LIBUI_ROUTER_PUBLIC void router_forward(router_t *router); - -LIBUI_ROUTER_PUBLIC router_t *router_get_by_name(const char *name); - -LIBUI_ROUTER_PUBLIC const char *router_get_version(void); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/strmap.h b/lib/ui-router/include/ui_router/strmap.h deleted file mode 100644 index b3f7bdac6..000000000 --- a/lib/ui-router/include/ui_router/strmap.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - * lib/ui-router/include/ui_router/strmap.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_STRMAP_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_STRMAP_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC strmap_t *strmap_create(void); - -LIBUI_ROUTER_PUBLIC void strmap_destroy(strmap_t *dict); - -LIBUI_ROUTER_PUBLIC void strmap_delete(strmap_t *dict, const char *key); - -LIBUI_ROUTER_PUBLIC int strmap_set(strmap_t *dict, const char *key, - const char *value); - -LIBUI_ROUTER_PUBLIC const char *strmap_get(strmap_t *dict, const char *key); - -LIBUI_ROUTER_PUBLIC size_t strmap_extend(strmap_t *target, strmap_t *other); - -LIBUI_ROUTER_PUBLIC strmap_t *strmap_duplicate(strmap_t *target); - -LIBUI_ROUTER_PUBLIC bool strmap_includes(strmap_t *a, strmap_t *b); - -LIBUI_ROUTER_PUBLIC bool strmap_equal(strmap_t *a, strmap_t *b); - -LIBUI_ROUTER_PUBLIC strmap_iterator_t *strmap_get_iterator(strmap_t *map); - -LIBUI_ROUTER_PUBLIC void strmap_destroy_iterator(strmap_iterator_t *iter); - -LIBUI_ROUTER_PUBLIC strmap_item_t *strmap_next(strmap_iterator_t *iter); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/utils.h b/lib/ui-router/include/ui_router/utils.h deleted file mode 100644 index f73a8c16d..000000000 --- a/lib/ui-router/include/ui_router/utils.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * lib/ui-router/include/ui_router/utils.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_UTILS_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_UTILS_H - -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC char *router_path_fill_params(const char *path, - strmap_t *params); - -LIBUI_ROUTER_PUBLIC const char *router_path_parse_key(const char *path, - char key[256], - size_t *key_len); - -LIBUI_ROUTER_PUBLIC size_t router_path_parse_keys(const char *path, - router_linkedlist_t *keys); - -LIBUI_ROUTER_PUBLIC char *router_path_resolve(const char *relative, - const char *base, bool append); - -LIBUI_ROUTER_PUBLIC strmap_t *router_parse_query(const char *query_str); - -LIBUI_ROUTER_PUBLIC int router_string_compare(const char *a, const char *b); - -LIBUI_ROUTER_PUBLIC int router_path_compare(const char *a, const char *b); - -LIBUI_ROUTER_PUBLIC bool router_path_starts_with(const char *path, - const char *subpath); - -LIBUI_ROUTER_PUBLIC bool router_is_same_route(const router_route_t *a, - const router_route_t *b); - -LIBUI_ROUTER_PUBLIC bool router_is_included_route(const router_route_t *current, - const router_route_t *target); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/include/ui_router/view.h b/lib/ui-router/include/ui_router/view.h deleted file mode 100644 index d1d1bc753..000000000 --- a/lib/ui-router/include/ui_router/view.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * lib/ui-router/include/ui_router/view.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef LIB_UI_ROUTER_INCLUDE_UI_ROUTER_VIEW_H -#define LIB_UI_ROUTER_INCLUDE_UI_ROUTER_VIEW_H - -#include -#include -#include - -LIBUI_ROUTER_BEGIN_DECLS - -LIBUI_ROUTER_PUBLIC ui_widget_t *ui_router_view_get_matched_widget( - ui_widget_t *w); - -LIBUI_ROUTER_PUBLIC void ui_register_router_view(void); - -LIBUI_ROUTER_END_DECLS - -#endif diff --git a/lib/ui-router/src/private.h b/lib/ui-router/src/private.h deleted file mode 100644 index 89bbbebc9..000000000 --- a/lib/ui-router/src/private.h +++ /dev/null @@ -1,98 +0,0 @@ -/* - * lib/ui-router/src/private.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#ifndef UI_ROUTER_PRIVATE_H -#define UI_ROUTER_PRIVATE_H - -#include -#include -#include -#include -#include - -#ifdef _WIN32 -#pragma warning(disable: 4996) -#endif - -#define router_mem_free(ptr) \ - do { \ - if (ptr) { \ - free(ptr); \ - } \ - ptr = NULL; \ - } while (0) - -struct router_location { - char *name; - char *path; - char *hash; - strmap_t *params; - strmap_t *query; - bool normalized; -}; - -struct router_route { - char *name; - char *path; - char *full_path; - char *hash; - strmap_t *query; - strmap_t *params; - router_linkedlist_t matched; -}; - -struct router_route_record { - char *name; - char *path; - const router_route_record_t *parent; - strmap_t *components; - router_linkedlist_node_t node; -}; - -struct router_history { - int index; - router_route_t *current; - router_linkedlist_t routes; - router_linkedlist_t watchers; -}; - -struct router_config { - char *name; - char *path; - strmap_t *components; -}; - -struct router_matcher { - dict_t *name_map; - dict_t *path_map; - router_linkedlist_t path_list; -}; - -struct router_watcher { - void *data; - router_callback_t callback; - router_linkedlist_node_t node; -}; - -struct router_resolved { - router_route_t *route; - router_location_t *location; -}; - -struct router { - char *name; - char *link_active_class; - char *link_exact_active_class; - router_matcher_t *matcher; - router_history_t *history; -}; - -#endif diff --git a/lib/ui-router/src/version.h.in b/lib/ui-router/src/version.h.in deleted file mode 100644 index 1317db01d..000000000 --- a/lib/ui-router/src/version.h.in +++ /dev/null @@ -1,16 +0,0 @@ -/* - * lib/ui-router/include/ui_router/version.h - * - * Copyright (c) 2023-2024, Liu Chao 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. - */ - -#define LIBUI_ROUTER_VERSION "${VERSION}" -#define LIBUI_ROUTER_VERSION_MAJOR ${VERSION_MAJOR} -#define LIBUI_ROUTER_VERSION_MINOR ${VERSION_MINOR} -#define LIBUI_ROUTER_VERSION_ALTER ${VERSION_ALTER} -${define LIBUI_ROUTER_STATIC_BUILD} diff --git a/lib/ui-server/src/server.c b/lib/ui-server/src/server.c index fd9ac24d1..abe64aa00 100644 --- a/lib/ui-server/src/server.c +++ b/lib/ui-server/src/server.c @@ -735,6 +735,7 @@ void ui_server_update(void) void ui_server_init(void) { ui_cursor_init(); + ui_server.num_rendering_threads = 4; ui_server.observer = ui_mutation_observer_create(ui_server_on_widget_mutation, NULL); ptk_on_event(PTK_EVENT_VISIBILITY_CHANGE, @@ -760,6 +761,9 @@ void ui_server_init(void) void ui_server_set_threads(int threads) { + if (threads < 1) { + return; + } ui_server.num_rendering_threads = threads; } diff --git a/lib/ui-widgets/include/ui_widgets.h b/lib/ui-widgets/include/ui_widgets.h deleted file mode 100644 index 4cefed2ca..000000000 --- a/lib/ui-widgets/include/ui_widgets.h +++ /dev/null @@ -1,20 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets.h - * - * Copyright (c) 2023-2024, Liu Chao 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 "ui_widgets/common.h" -#include "ui_widgets/text.h" -#include "ui_widgets/button.h" -#include "ui_widgets/anchor.h" -#include "ui_widgets/canvas.h" -#include "ui_widgets/scrollarea.h" -#include "ui_widgets/scrollbar.h" -#include "ui_widgets/textinput.h" -#include "ui_widgets/textcaret.h" diff --git a/lib/ui-widgets/include/ui_widgets/anchor.h b/lib/ui-widgets/include/ui_widgets/anchor.h deleted file mode 100644 index 14f155bd8..000000000 --- a/lib/ui-widgets/include/ui_widgets/anchor.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/anchor.h: to element in HTML. - * - * Copyright (c) 2018-2024, Liu chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_ANCHOR_H -#define LIB_UI_WIDGETS_INCLUDE_ANCHOR_H - -#include -#include "ui_widgets/common.h" - -LIBUI_WIDGETS_BEGIN_DECLS - -LIBUI_WIDGETS_PUBLIC void ui_anchor_open(ui_widget_t* w); - -LIBUI_WIDGETS_PUBLIC void ui_register_anchor(void); - -LIBUI_WIDGETS_PUBLIC void ui_unregister_anchor(void); - -LIBUI_WIDGETS_END_DECLS - -#endif diff --git a/lib/ui-widgets/include/ui_widgets/button.h b/lib/ui-widgets/include/ui_widgets/button.h deleted file mode 100644 index e13bd7e7c..000000000 --- a/lib/ui-widgets/include/ui_widgets/button.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/button.h: -- LCUI‘s Button widget - * - * Copyright (c) 2018-2024, Liu chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_BUTTON_H -#define LIB_UI_WIDGETS_INCLUDE_BUTTON_H - -#include -#include "ui_widgets/common.h" - -LIBUI_WIDGETS_BEGIN_DECLS - -LIBUI_WIDGETS_PUBLIC void ui_button_set_text_w(ui_widget_t* w, const wchar_t *wstr); - -LIBUI_WIDGETS_PUBLIC void ui_button_set_text(ui_widget_t* w, const char *str); - -LIBUI_WIDGETS_PUBLIC void ui_register_button(void); - -LIBUI_WIDGETS_END_DECLS - -#endif diff --git a/lib/ui-widgets/include/ui_widgets/common.h b/lib/ui-widgets/include/ui_widgets/common.h deleted file mode 100644 index 744190214..000000000 --- a/lib/ui-widgets/include/ui_widgets/common.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/common.h - * - * Copyright (c) 2023-2024, Liu Chao 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 "config.h" -#ifdef __cplusplus -#define LIBUI_WIDGETS_BEGIN_DECLS extern "C" { -#define LIBUI_WIDGETS_END_DECLS } -#else -#define LIBUI_WIDGETS_BEGIN_DECLS -#define LIBUI_WIDGETS_END_DECLS -#endif - -#ifndef LIBUI_WIDGETS_PUBLIC -#if defined(_MSC_VER) && !defined(LIBUI_WIDGETS_STATIC_BUILD) -#ifdef LIBUI_WIDGETS_DLL_EXPORT -#define LIBUI_WIDGETS_PUBLIC __declspec(dllexport) -#else -#define LIBUI_WIDGETS_PUBLIC __declspec(dllimport) -#endif -#elif __GNUC__ >= 4 -#define LIBUI_WIDGETS_PUBLIC extern __attribute__((visibility("default"))) -#else -#define LIBUI_WIDGETS_PUBLIC extern -#endif -#endif diff --git a/lib/ui-widgets/include/ui_widgets/scrollarea.h b/lib/ui-widgets/include/ui_widgets/scrollarea.h deleted file mode 100644 index 871204a1b..000000000 --- a/lib/ui-widgets/include/ui_widgets/scrollarea.h +++ /dev/null @@ -1,53 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/scrollarea.h - * - * Copyright (c) 2024, Liu Chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_SCROLLAREA_H -#define LIB_UI_WIDGETS_INCLUDE_SCROLLAREA_H - -#include -#include "ui_widgets/common.h" - -typedef enum { - UI_SCROLLAREA_AUTO, - UI_SCROLLAREA_VERTICAL, - UI_SCROLLAREA_HORIZONTAL, -} ui_scrollarea_direction_t; - -LIBUI_WIDGETS_BEGIN_DECLS - -LIBUI_WIDGETS_PUBLIC void ui_scrollarea_set_wheel_scroll_direction( - ui_widget_t *w, ui_scrollarea_direction_t direction); - -LIBUI_WIDGETS_PUBLIC void ui_scrollarea_update(ui_widget_t *w); - -LIBUI_WIDGETS_PUBLIC void ui_register_scrollarea(void); - -LIBUI_WIDGETS_PUBLIC ui_widget_t *ui_create_scrollarea(void); - -LIBUI_WIDGETS_PUBLIC ui_widget_t *ui_create_scrollarea_content(void); - -LIBUI_WIDGETS_PUBLIC void ui_scrollarea_set_scroll_top(ui_widget_t *w, - float value); - -LIBUI_WIDGETS_PUBLIC void ui_scrollarea_set_scroll_left(ui_widget_t *w, - float value); - -LIBUI_WIDGETS_PUBLIC float ui_scrollarea_get_scroll_top(ui_widget_t *w); - -LIBUI_WIDGETS_PUBLIC float ui_scrollarea_get_scroll_left(ui_widget_t *w); - -LIBUI_WIDGETS_PUBLIC float ui_scrollarea_get_scroll_width(ui_widget_t *w); - -LIBUI_WIDGETS_PUBLIC float ui_scrollarea_get_scroll_height(ui_widget_t *w); - -LIBUI_WIDGETS_END_DECLS - -#endif diff --git a/lib/ui-widgets/include/ui_widgets/scrollbar.h b/lib/ui-widgets/include/ui_widgets/scrollbar.h deleted file mode 100644 index 59f026dd9..000000000 --- a/lib/ui-widgets/include/ui_widgets/scrollbar.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/scrollbar.h: -- LCUI's scrollbar widget - * - * Copyright (c) 2018-2024, Liu chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_SCROLLBAR_H -#define LIB_UI_WIDGETS_INCLUDE_SCROLLBAR_H - -#include -#include "ui_widgets/common.h" - -LIBUI_WIDGETS_BEGIN_DECLS - -typedef enum { - UI_SCROLLBAR_HORIZONTAL, - UI_SCROLLBAR_VERTICAL -} ui_scrollbar_orientation_t; - -LIBUI_WIDGETS_PUBLIC void ui_scrollbar_update(ui_widget_t *w); - -LIBUI_WIDGETS_PUBLIC void ui_scrollbar_set_orientation(ui_widget_t* w, - ui_scrollbar_orientation_t orientation); - -LIBUI_WIDGETS_PUBLIC ui_widget_t *ui_create_scrollbar(void); - -LIBUI_WIDGETS_PUBLIC void ui_register_scrollbar(void); - -LIBUI_WIDGETS_END_DECLS - -#endif diff --git a/lib/ui-widgets/include/ui_widgets/text.h b/lib/ui-widgets/include/ui_widgets/text.h deleted file mode 100644 index 841244d9d..000000000 --- a/lib/ui-widgets/include/ui_widgets/text.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/text.h: -- TextView widget for display - * text. - * - * Copyright (c) 2018-2024, Liu chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_TEXTVIEW_H -#define LIB_UI_WIDGETS_INCLUDE_TEXTVIEW_H - -#include -#include "ui_widgets/common.h" - -LIBUI_WIDGETS_BEGIN_DECLS - -LIBUI_WIDGETS_PUBLIC int ui_text_set_content_w(ui_widget_t *w, - const wchar_t *text); - -LIBUI_WIDGETS_PUBLIC size_t ui_text_get_content_w(ui_widget_t *w, wchar_t *buf, - size_t size); - -LIBUI_WIDGETS_PUBLIC int ui_text_set_content(ui_widget_t *w, - const char *utf8_text); - -LIBUI_WIDGETS_PUBLIC void ui_text_set_multiline(ui_widget_t *w, bool enable); - -LIBUI_WIDGETS_PUBLIC void ui_register_text(void); - -LIBUI_WIDGETS_PUBLIC void ui_unregister_text(void); - -LIBUI_WIDGETS_END_DECLS - -#endif diff --git a/lib/ui-widgets/include/ui_widgets/textcaret.h b/lib/ui-widgets/include/ui_widgets/textcaret.h deleted file mode 100644 index 8316ae93f..000000000 --- a/lib/ui-widgets/include/ui_widgets/textcaret.h +++ /dev/null @@ -1,27 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/textcaret.h: -- textcaret widget, used in textinput. - * - * Copyright (c) 2018-2024, Liu chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_TEXTCARET_H -#define LIB_UI_WIDGETS_INCLUDE_TEXTCARET_H - -#include -#include "ui_widgets/common.h" - -LIBUI_WIDGETS_PUBLIC void ui_textcaret_refresh(ui_widget_t* widget); - -LIBUI_WIDGETS_PUBLIC void ui_textcaret_set_visible(ui_widget_t* widget, bool visible); - -/** 设置闪烁的时间间隔 */ -LIBUI_WIDGETS_PUBLIC void ui_textcaret_set_blink_time(ui_widget_t* widget, unsigned int n_ms); - -LIBUI_WIDGETS_PUBLIC void ui_register_textcaret(void); - -#endif diff --git a/lib/ui-widgets/include/ui_widgets/textinput.h b/lib/ui-widgets/include/ui_widgets/textinput.h deleted file mode 100644 index 58d9da411..000000000 --- a/lib/ui-widgets/include/ui_widgets/textinput.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * lib/ui-widgets/include/ui_widgets/textinput.h: -- textinput widget, used to allow user edit text. - * - * Copyright (c) 2018-2024, Liu chao 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. - */ - -#ifndef LIB_UI_WIDGETS_INCLUDE_TEXTEDIT_H -#define LIB_UI_WIDGETS_INCLUDE_TEXTEDIT_H - -#include -#include "ui_widgets/common.h" - -LIBUI_WIDGETS_BEGIN_DECLS - -/** Enable style tag parser */ -LIBUI_WIDGETS_PUBLIC void ui_textinput_enable_style_tag(ui_widget_t* widget, bool enable); - -LIBUI_WIDGETS_PUBLIC void ui_textinput_enable_multiline(ui_widget_t* widget, bool enable); - -LIBUI_WIDGETS_PUBLIC void ui_textinput_move_caret(ui_widget_t* widget, int row, int col); - -/** 清空文本内容 */ -LIBUI_WIDGETS_PUBLIC void ui_textinput_clear_text(ui_widget_t* widget); - -/** 获取文本内容 */ -LIBUI_WIDGETS_PUBLIC size_t ui_textinput_get_text_w(ui_widget_t* w, size_t start, - size_t max_len, wchar_t *buf); - -/** 获取文本长度 */ -LIBUI_WIDGETS_PUBLIC size_t ui_textinput_get_text_length(ui_widget_t* w); - -/** 设置文本编辑框内的光标,指定是否闪烁、闪烁时间间隔 */ -LIBUI_WIDGETS_PUBLIC void ui_textinput_set_caret_blink(ui_widget_t* w, bool visible, int time); - - /** 为文本框设置文本(宽字符版) */ -LIBUI_WIDGETS_PUBLIC int ui_textinput_set_text_w(ui_widget_t* widget, const wchar_t *wstr); - -LIBUI_WIDGETS_PUBLIC int ui_textinput_set_text(ui_widget_t* widget, const char *utf8_str); - -/** 为文本框追加文本(宽字符版) */ -LIBUI_WIDGETS_PUBLIC int ui_textinput_append_text_w(ui_widget_t* widget, const wchar_t *wstr); - -/** 为文本框插入文本(宽字符版) */ -LIBUI_WIDGETS_PUBLIC int ui_textinput_insert_text_w(ui_widget_t* widget, const wchar_t *wstr); - -/** 设置占位符,当文本编辑框内容为空时显示占位符 */ -LIBUI_WIDGETS_PUBLIC int ui_textinput_set_placeholder_w(ui_widget_t* w, const wchar_t *wstr); - -LIBUI_WIDGETS_PUBLIC int ui_textinput_set_placeholder(ui_widget_t* w, const char *str); - -/** 设置密码屏蔽符 */ -LIBUI_WIDGETS_PUBLIC void ui_textinput_set_password_char(ui_widget_t* w, wchar_t ch); - -LIBUI_WIDGETS_PUBLIC void ui_register_textinput(void); - -LIBUI_WIDGETS_END_DECLS - -#endif diff --git a/lib/ui-widgets/src/config.h.in b/lib/ui-widgets/src/config.h.in deleted file mode 100644 index ac2b1fc38..000000000 --- a/lib/ui-widgets/src/config.h.in +++ /dev/null @@ -1,5 +0,0 @@ -#define LIBUI_WIDGETS_VERSION "${VERSION}" -#define LIBUI_WIDGETS_VERSION_MAJOR ${VERSION_MAJOR} -#define LIBUI_WIDGETS_VERSION_MINOR ${VERSION_MINOR} -#define LIBUI_WIDGETS_VERSION_ALTER ${VERSION_ALTER} -${define LIBUI_WIDGETS_STATIC_BUILD} diff --git a/lib/ui-widgets/xmake.lua b/lib/ui-widgets/xmake.lua deleted file mode 100644 index 2a9cf0efa..000000000 --- a/lib/ui-widgets/xmake.lua +++ /dev/null @@ -1,15 +0,0 @@ -set_project("libui-widgets") -set_version("0.1.0-a") - -target("libui-widgets") - set_kind("$(kind)") - add_files("src/**.c") - add_deps("yutil", "libcss", "pandagl", "libthread", "libui", "libui-xml", "libworker", "libptk") - set_configdir("include/ui_widgets") - add_configfiles("src/config.h.in") - add_headerfiles("include/ui_widgets.h", "include/(ui_widgets/*.h)") - if is_kind("static") then - set_configvar("LIBUI_WIDGETS_STATIC_BUILD", 1) - elseif is_plat("windows") then - add_defines("LIBUI_WIDGETS_DLL_EXPORT") - end diff --git a/lib/ui/src/ui_resizer.c b/lib/ui/src/ui_resizer.c index 63049a834..440ef2ffd 100644 --- a/lib/ui/src/ui_resizer.c +++ b/lib/ui/src/ui_resizer.c @@ -1,3 +1,14 @@ +/* + * lib/ui/src/ui_resizer.c + * + * Copyright (c) 2024, Liu Chao 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 #include #include "ui_widget_style.h" diff --git a/lib/ui/src/ui_resizer.h b/lib/ui/src/ui_resizer.h index 0a7d847cf..a25230001 100644 --- a/lib/ui/src/ui_resizer.h +++ b/lib/ui/src/ui_resizer.h @@ -1,3 +1,14 @@ +/* + * lib/ui/src/ui_resizer.h + * + * Copyright (c) 2024, Liu Chao 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 typedef struct ui_resizer { diff --git a/lib/ui/src/ui_widget_layout.h b/lib/ui/src/ui_widget_layout.h index 925825378..601b344fb 100644 --- a/lib/ui/src/ui_widget_layout.h +++ b/lib/ui/src/ui_widget_layout.h @@ -1 +1,12 @@ +/* + * lib/ui/src/ui_widget_layout.h + * + * Copyright (c) 2024, Liu Chao 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. + */ + void ui_widget_reflow_with_resizer(ui_widget_t *w, ui_resizer_t *resizer); diff --git a/src/lcui.c b/src/lcui.c index 5c3a66ae2..09c648f24 100644 --- a/src/lcui.c +++ b/src/lcui.c @@ -10,94 +10,23 @@ */ #include -#include -#include -#include -#include +#include #include #include -#include -#include -#include -#include +#include +#include +#include -/** LCUI 应用程序数据 */ -static struct lcui_app { - ptk_steptimer_t timer; - worker_t *main_worker; - worker_t *async_worker; -} lcui_app; +extern void lcui_fonts_init(void); +extern void lcui_widgets_init(void); +extern void lcui_widgets_destroy(void); const char *lcui_get_version(void) { return PACKAGE_VERSION; } -worker_task_t *lcui_post_task(void *data, worker_task_cb task_cb, - worker_task_cb after_task_cb) -{ - if (!lcui_app.main_worker) { - return NULL; - } - return worker_post_task(lcui_app.main_worker, data, task_cb, - after_task_cb); -} -worker_task_t *lcui_post_async_task(void *data, worker_task_cb task_cb, - worker_task_cb after_task_cb) -{ - return worker_post_task(lcui_app.async_worker, data, task_cb, - after_task_cb); -} - -bool lcui_cancel_async_task(worker_task_t *task) -{ - return worker_cancel_task(lcui_app.async_worker, task); -} - -bool lcui_cancel_task(worker_task_t *task) -{ - return worker_cancel_task(lcui_app.async_worker, task); -} - -uint32_t lcui_get_fps(void) -{ - return lcui_app.timer.frames_per_second; -} - -void lcui_set_frame_rate_cap(unsigned rate_cap) -{ - if (rate_cap > 0) { - lcui_app.timer.target_elapsed_time = 1000 / rate_cap; - lcui_app.timer.is_fixed_time_step = true; - } else { - lcui_app.timer.is_fixed_time_step = false; - } -} - -static void lcui_app_on_tick(ptk_steptimer_t *timer, void *data) -{ - lcui_render_ui(); - app_present(); -} - -static int lcui_dispatch_app_event(ptk_event_t *e) -{ - if (e->type == PTK_EVENT_QUIT) { - return 0; - } - lcui_dispatch_ui_event(e); - lcui_update_ui(); - worker_run(lcui_app.main_worker); - ptk_steptimer_tick(&lcui_app.timer, lcui_app_on_tick, NULL); - return 0; -} - -int lcui_process_events(ptk_process_events_option_t option) -{ - return ptk_process_native_events(option); -} - -void lcui_init_app(void) +void lcui_init(void) { logger_log(LOGGER_LEVEL_INFO, "LCUI (LC's UI) version " PACKAGE_VERSION "\n" @@ -109,42 +38,23 @@ void lcui_init_app(void) "See source distribution for detailed copyright notices.\n" "To learn more, visit http://www.lcui.org.\n\n"); + lcui_app_init(); + lcui_ui_init(); + lcui_fonts_init(); + lcui_widgets_init(); lcui_reset_settings(); - ptk_steptimer_init(&lcui_app.timer); - lcui_app.main_worker = worker_create(); - lcui_app.async_worker = worker_create(); - lcui_app.timer.target_elapsed_time = 0; - worker_run_async(lcui_app.async_worker); -} - -void lcui_destroy_app(void) -{ - worker_destroy(lcui_app.main_worker); - worker_destroy(lcui_app.async_worker); - lcui_app.main_worker = NULL; - lcui_app.async_worker = NULL; -} - -void lcui_init(void) -{ - lcui_init_app(); - if (ptk_init(L"LCUI Application") != 0) { - abort(); - } - ptk_set_event_dispatcher(lcui_dispatch_app_event); - lcui_init_ui(); } void lcui_destroy(void) { - lcui_destroy_ui(); - lcui_destroy_app(); - ptk_destroy(); + lcui_widgets_destroy(); + lcui_ui_destroy(); + lcui_app_destroy(); } void lcui_exit(int code) { - app_exit(code); + ptk_app_exit(code); } void lcui_quit(void) @@ -154,7 +64,7 @@ void lcui_quit(void) int lcui_run(void) { - return lcui_process_events(PTK_PROCESS_EVENTS_UNTIL_QUIT); + return lcui_app_process_events(PTK_PROCESS_EVENTS_UNTIL_QUIT); } int lcui_main(void) diff --git a/src/lcui_app.c b/src/lcui_app.c new file mode 100644 index 000000000..dd0c5d39f --- /dev/null +++ b/src/lcui_app.c @@ -0,0 +1,193 @@ +/* + * src/lcui_app.c + * + * Copyright (c) 2024, Liu Chao 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 +#include +#include +#include +#include +#include +#include + +static struct lcui_app { + ptk_steptimer_t timer; +} lcui_app; + +static void lcui_dispatch_ui_mouse_event(ui_event_type_t type, + ptk_event_t *app_evt) +{ + ui_event_t e = { 0 }; + float scale = ui_server_get_window_scale(app_evt->window); + + e.type = type; + e.mouse.y = (float)round(app_evt->mouse.y / scale); + e.mouse.x = (float)round(app_evt->mouse.x / scale); + ui_dispatch_event(&e); +} + +static void lcui_dispatch_ui_keyboard_event(ui_event_type_t type, + ptk_event_t *app_evt) +{ + ui_event_t e = { 0 }; + + e.type = type; + e.key.code = app_evt->key.code; + e.key.is_composing = app_evt->key.is_composing; + e.key.alt_key = app_evt->key.alt_key; + e.key.shift_key = app_evt->key.shift_key; + e.key.ctrl_key = app_evt->key.ctrl_key; + e.key.meta_key = app_evt->key.meta_key; + ui_dispatch_event(&e); +} + +static void lcui_dispatch_ui_touch_event(ptk_event_t *app_event) +{ + size_t i; + ui_event_t e = { 0 }; + float scale = ui_server_get_window_scale(app_event->window); + + e.type = UI_EVENT_TOUCH; + e.touch.n_points = app_event->touch.n_points; + e.touch.points = malloc(sizeof(ui_touch_point_t) * e.touch.n_points); + for (i = 0; i < e.touch.n_points; ++i) { + switch (app_event->touch.points[i].state) { + case PTK_EVENT_TOUCHDOWN: + e.touch.points[i].state = UI_EVENT_TOUCHDOWN; + break; + case PTK_EVENT_TOUCHUP: + e.touch.points[i].state = UI_EVENT_TOUCHUP; + break; + case PTK_EVENT_TOUCHMOVE: + e.touch.points[i].state = UI_EVENT_TOUCHMOVE; + break; + default: + break; + } + e.touch.points[i].x = + (float)round(app_event->touch.points[i].x / scale); + e.touch.points[i].y = + (float)round(app_event->touch.points[i].y / scale); + } + ui_dispatch_event(&e); + ui_event_destroy(&e); +} + +static void lcui_dispatch_ui_textinput_event(ptk_event_t *app_evt) +{ + ui_event_t e = { 0 }; + + e.type = UI_EVENT_TEXTINPUT; + e.text.length = app_evt->text.length; + e.text.text = wcsdup2(app_evt->text.text); + ui_dispatch_event(&e); + ui_event_destroy(&e); +} + +static void lcui_dispatch_ui_wheel_event(app_wheel_event_t *wheel) +{ + ui_event_t e = { 0 }; + + // TODO: + e.type = UI_EVENT_WHEEL; + e.wheel.delta_mode = UI_WHEEL_DELTA_PIXEL; + e.wheel.delta_y = wheel->delta_y; + ui_dispatch_event(&e); +} + +static void lcui_dispatch_ui_event(ptk_event_t *app_event) +{ + switch (app_event->type) { + case PTK_EVENT_KEYDOWN: + lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYDOWN, app_event); + break; + case PTK_EVENT_KEYUP: + lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYUP, app_event); + break; + case PTK_EVENT_KEYPRESS: + lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYPRESS, app_event); + break; + case PTK_EVENT_MOUSEDOWN: + lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEDOWN, app_event); + break; + case PTK_EVENT_MOUSEUP: + lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEUP, app_event); + break; + case PTK_EVENT_MOUSEMOVE: + lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEMOVE, app_event); + break; + case PTK_EVENT_TOUCH: + lcui_dispatch_ui_touch_event(app_event); + break; + case PTK_EVENT_WHEEL: + lcui_dispatch_ui_wheel_event(&app_event->wheel); + break; + case PTK_EVENT_COMPOSITION: + lcui_dispatch_ui_textinput_event(app_event); + break; + default: + break; + } +} + +static void lcui_app_on_tick(ptk_steptimer_t *timer, void *data) +{ + lcui_ui_render(); + app_present(); +} + +static int lcui_app_dispatch(ptk_event_t *e) +{ + if (e->type == PTK_EVENT_QUIT) { + return 0; + } + lcui_dispatch_ui_event(e); + lcui_ui_update(); + lcui_worker_run(); + ptk_steptimer_tick(&lcui_app.timer, lcui_app_on_tick, NULL); + return 0; +} + +uint32_t lcui_app_get_fps(void) +{ + return lcui_app.timer.frames_per_second; +} + +void lcui_app_set_frame_rate_cap(unsigned rate_cap) +{ + if (rate_cap > 0) { + lcui_app.timer.target_elapsed_time = 1000 / rate_cap; + lcui_app.timer.is_fixed_time_step = true; + } else { + lcui_app.timer.is_fixed_time_step = false; + } +} + +int lcui_app_process_events(ptk_process_events_option_t option) +{ + return ptk_process_native_events(option); +} + +void lcui_app_init(void) +{ + lcui_worker_init(); + ptk_steptimer_init(&lcui_app.timer); + lcui_app.timer.target_elapsed_time = 0; + if (ptk_init(L"LCUI Application") != 0) { + abort(); + } + ptk_set_event_dispatcher(lcui_app_dispatch); +} + +void lcui_app_destroy(void) +{ + lcui_worker_destroy(); + ptk_destroy(); +} diff --git a/src/lcui_fonts.c b/src/lcui_fonts.c new file mode 100644 index 000000000..ef814a58d --- /dev/null +++ b/src/lcui_fonts.c @@ -0,0 +1,124 @@ +/* + * src/lcui_fonts.c + * + * Copyright (c) 2024, Liu Chao 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 +#include +#include + +#ifdef PTK_WIN32 +static void lcui_windows_fonts_init(void) +{ + size_t i; + int *ids = NULL; + const char *names[] = { "Consola", "Simsun", "Microsoft YaHei", NULL }; + const char *fonts[] = { "C:/Windows/Fonts/consola.ttf", + "C:/Windows/Fonts/simsun.ttc", + "C:/Windows/Fonts/msyh.ttf", + "C:/Windows/Fonts/msyh.ttc" }; + + for (i = 0; i < sizeof(fonts) / sizeof(char *); ++i) { + pd_font_library_load_file(fonts[i]); + } + i = pd_font_library_query(&ids, PD_FONT_STYLE_NORMAL, + PD_FONT_WEIGHT_NORMAL, names); + if (i > 0) { + pd_font_library_set_default_font(ids[i - 1]); + } + free(ids); +} + +#else + +#ifdef HAVE_FONTCONFIG + +static void lcui_fc_fonts_init(void) +{ + size_t i; + char *path; + int *ids = NULL; + const char *names[] = { "Noto Sans CJK", "Ubuntu", + "WenQuanYi Micro Hei", NULL }; + const char *fonts[] = { "Ubuntu", "Noto Sans CJK SC", + "WenQuanYi Micro Hei" }; + + for (i = 0; i < sizeof(fonts) / sizeof(char *); ++i) { + path = pd_font_library_get_font_path(fonts[i]); + pd_font_library_load_file(path); + free(path); + } + i = pd_font_library_query(&ids, PD_FONT_STYLE_NORMAL, + PD_FONT_WEIGHT_NORMAL, names); + if (i > 0) { + pd_font_library_set_default_font(ids[i - 1]); + } + free(ids); +} + +#else + +static void lcui_linux_fonts_init(void) +{ + size_t i; + int *ids = NULL; + const char *names[] = { "Noto Sans CJK SC", "Ubuntu", "Ubuntu Mono", + "WenQuanYi Micro Hei", NULL }; + const char *fonts[] = { + "/usr/share/fonts/truetype/ubuntu/Ubuntu-BI.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-C.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-LI.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-L.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-MI.ttf", + "/usr/share/fonts/truetype/ubuntu/UbuntuMono-BI.ttf", + "/usr/share/fonts/truetype/ubuntu/UbuntuMono-B.ttf", + "/usr/share/fonts/truetype/ubuntu/UbuntuMono-RI.ttf", + "/usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-M.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-RI.ttf", + "/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-RI.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-MI.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-L.ttf", + "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-LI.ttf", + "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", + "/usr/share/fonts/opentype/noto/NotoSansCJK.ttc", + "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc" + }; + + for (i = 0; i < sizeof(fonts) / sizeof(char *); ++i) { + pd_font_library_load_file(fonts[i]); + } + i = pd_font_library_query(&ids, PD_FONT_STYLE_NORMAL, + PD_FONT_WEIGHT_NORMAL, names); + if (i > 0) { + pd_font_library_set_default_font(ids[i - 1]); + } + free(ids); +} +#endif + +#endif + +void lcui_fonts_init(void) +{ +#ifdef PTK_WIN32 + lcui_windows_fonts_init(); +#elif defined(HAVE_FONTCONFIG) + logger_debug("[font] fontconfig enabled\n"); + lcui_fc_fonts_init(); +#else + lcui_linux_fonts_init(); +#endif +} diff --git a/src/lcui_settings.c b/src/lcui_settings.c index d1962c9d5..adc77d474 100644 --- a/src/lcui_settings.c +++ b/src/lcui_settings.c @@ -13,6 +13,7 @@ #include #include +#include #include static lcui_settings_t lcui_settings; @@ -32,7 +33,7 @@ void lcui_apply_settings(lcui_settings_t *settings) y_max(lcui_settings.parallel_rendering_threads, 1); ui_server_set_threads(lcui_settings.parallel_rendering_threads); ui_server_set_paint_flashing_enabled(lcui_settings.paint_flashing); - lcui_set_frame_rate_cap(lcui_settings.frame_rate_cap); + lcui_app_set_frame_rate_cap(lcui_settings.frame_rate_cap); } /* Reset global settings to their defaults. */ diff --git a/src/lcui_ui.c b/src/lcui_ui.c index 2db383b5a..12464cc0e 100644 --- a/src/lcui_ui.c +++ b/src/lcui_ui.c @@ -15,8 +15,7 @@ #include #include #include -#include -#include +#include #define DEFAULT_WINDOW_WIDTH 800 #define DEFAULT_WINDOW_HEIGHT 600 @@ -31,135 +30,19 @@ typedef struct { static struct lcui_ui { bool quit_after_all_windows_closed; lcui_ui_image_loader_t image_loader; - lcui_display_mode_t mode; + lcui_display_t mode; ui_mutation_observer_t *observer; /** list_t */ list_t windows; } lcui_ui; -static void lcui_dispatch_ui_mouse_event(ui_event_type_t type, - ptk_event_t *app_evt) -{ - ui_event_t e = { 0 }; - float scale = ui_server_get_window_scale(app_evt->window); - - e.type = type; - e.mouse.y = (float)round(app_evt->mouse.y / scale); - e.mouse.x = (float)round(app_evt->mouse.x / scale); - ui_dispatch_event(&e); -} - -static void lcui_dispatch_ui_keyboard_event(ui_event_type_t type, - ptk_event_t *app_evt) -{ - ui_event_t e = { 0 }; - - e.type = type; - e.key.code = app_evt->key.code; - e.key.is_composing = app_evt->key.is_composing; - e.key.alt_key = app_evt->key.alt_key; - e.key.shift_key = app_evt->key.shift_key; - e.key.ctrl_key = app_evt->key.ctrl_key; - e.key.meta_key = app_evt->key.meta_key; - ui_dispatch_event(&e); -} - -static void lcui_dispatch_ui_touch_event(ptk_event_t *app_event) -{ - size_t i; - ui_event_t e = { 0 }; - float scale = ui_server_get_window_scale(app_event->window); - - e.type = UI_EVENT_TOUCH; - e.touch.n_points = app_event->touch.n_points; - e.touch.points = malloc(sizeof(ui_touch_point_t) * e.touch.n_points); - for (i = 0; i < e.touch.n_points; ++i) { - switch (app_event->touch.points[i].state) { - case PTK_EVENT_TOUCHDOWN: - e.touch.points[i].state = UI_EVENT_TOUCHDOWN; - break; - case PTK_EVENT_TOUCHUP: - e.touch.points[i].state = UI_EVENT_TOUCHUP; - break; - case PTK_EVENT_TOUCHMOVE: - e.touch.points[i].state = UI_EVENT_TOUCHMOVE; - break; - default: - break; - } - e.touch.points[i].x = - (float)round(app_event->touch.points[i].x / scale); - e.touch.points[i].y = - (float)round(app_event->touch.points[i].y / scale); - } - ui_dispatch_event(&e); - ui_event_destroy(&e); -} - -static void lcui_dispatch_ui_textinput_event(ptk_event_t *app_evt) -{ - ui_event_t e = { 0 }; - - e.type = UI_EVENT_TEXTINPUT; - e.text.length = app_evt->text.length; - e.text.text = wcsdup2(app_evt->text.text); - ui_dispatch_event(&e); - ui_event_destroy(&e); -} - -static void lcui_dispatch_ui_wheel_event(app_wheel_event_t *wheel) -{ - ui_event_t e = { 0 }; - - // TODO: - e.type = UI_EVENT_WHEEL; - e.wheel.delta_mode = UI_WHEEL_DELTA_PIXEL; - e.wheel.delta_y = wheel->delta_y; - ui_dispatch_event(&e); -} - -void lcui_dispatch_ui_event(ptk_event_t *app_event) -{ - switch (app_event->type) { - case PTK_EVENT_KEYDOWN: - lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYDOWN, app_event); - break; - case PTK_EVENT_KEYUP: - lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYUP, app_event); - break; - case PTK_EVENT_KEYPRESS: - lcui_dispatch_ui_keyboard_event(UI_EVENT_KEYPRESS, app_event); - break; - case PTK_EVENT_MOUSEDOWN: - lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEDOWN, app_event); - break; - case PTK_EVENT_MOUSEUP: - lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEUP, app_event); - break; - case PTK_EVENT_MOUSEMOVE: - lcui_dispatch_ui_mouse_event(UI_EVENT_MOUSEMOVE, app_event); - break; - case PTK_EVENT_TOUCH: - lcui_dispatch_ui_touch_event(app_event); - break; - case PTK_EVENT_WHEEL: - lcui_dispatch_ui_wheel_event(&app_event->wheel); - break; - case PTK_EVENT_COMPOSITION: - lcui_dispatch_ui_textinput_event(app_event); - break; - default: - break; - } -} - -size_t lcui_render_ui(void) +size_t lcui_ui_render(void) { return ui_server_render(); } -void lcui_update_ui(void) +void lcui_ui_update(void) { ui_server_update(); thread_mutex_lock(&lcui_ui.image_loader.mutex); @@ -167,12 +50,12 @@ void lcui_update_ui(void) thread_mutex_unlock(&lcui_ui.image_loader.mutex); } -static void lcui_process_ui_mutation(ui_mutation_record_t *mutation) +static void lcui_ui_process_mutation(ui_mutation_record_t *mutation) { list_node_t *node; if (mutation->type != UI_MUTATION_RECORD_TYPE_CHILD_LIST || - lcui_ui.mode != LCUI_DISPLAY_MODE_SEAMLESS) { + lcui_ui.mode != LCUI_DISPLAY_SEAMLESS) { return; } for (list_each(node, &mutation->removed_widgets)) { @@ -183,17 +66,17 @@ static void lcui_process_ui_mutation(ui_mutation_record_t *mutation) } } -static void lcui_on_ui_mutation(ui_mutation_list_t *mutation_list, +static void lcui_ui_on_mutation(ui_mutation_list_t *mutation_list, ui_mutation_observer_t *observer, void *arg) { list_node_t *node; for (list_each(node, mutation_list)) { - lcui_process_ui_mutation(node->data); + lcui_ui_process_mutation(node->data); } } -static void lcui_on_window_destroy(ptk_event_t *e, void *arg) +static void lcui_ui_on_window_destroy(ptk_event_t *e, void *arg) { list_node_t *node; @@ -205,35 +88,35 @@ static void lcui_on_window_destroy(ptk_event_t *e, void *arg) } if (lcui_ui.quit_after_all_windows_closed && lcui_ui.windows.length == 0) { - lcui_quit(); + ptk_app_exit(0); } } -static void lcui_close_window(void *arg) +static void lcui_ui_close_window(void *arg) { ptk_window_close(arg); } -void lcui_set_ui_display_mode(lcui_display_mode_t mode) +void lcui_ui_set_display(lcui_display_t mode) { ptk_window_t *wnd; list_node_t *node; ui_mutation_observer_init_t options = { 0 }; - if (mode == LCUI_DISPLAY_MODE_DEFAULT) { - mode = LCUI_DISPLAY_MODE_WINDOWED; + if (mode == LCUI_DISPLAY_DEFAULT) { + mode = LCUI_DISPLAY_WINDOWED; } if (lcui_ui.mode == mode) { return; } - if (lcui_ui.mode == LCUI_DISPLAY_MODE_FULLSCREEN || - lcui_ui.mode == LCUI_DISPLAY_MODE_WINDOWED) { + if (lcui_ui.mode == LCUI_DISPLAY_FULLSCREEN || + lcui_ui.mode == LCUI_DISPLAY_WINDOWED) { wnd = ui_server_get_window(ui_root()); - if (mode == LCUI_DISPLAY_MODE_FULLSCREEN) { + if (mode == LCUI_DISPLAY_FULLSCREEN) { ptk_window_set_fullscreen(wnd, true); lcui_ui.mode = mode; return; - } else if (mode == LCUI_DISPLAY_MODE_WINDOWED) { + } else if (mode == LCUI_DISPLAY_WINDOWED) { ptk_window_set_fullscreen(wnd, false); lcui_ui.mode = mode; return; @@ -245,19 +128,19 @@ void lcui_set_ui_display_mode(lcui_display_mode_t mode) lcui_ui.observer = NULL; } lcui_ui.quit_after_all_windows_closed = false; - list_destroy(&lcui_ui.windows, lcui_close_window); + list_destroy(&lcui_ui.windows, lcui_ui_close_window); switch (mode) { - case LCUI_DISPLAY_MODE_FULLSCREEN: + case LCUI_DISPLAY_FULLSCREEN: wnd = ptk_window_create(NULL, 0, 0, 0, 0, NULL); list_append(&lcui_ui.windows, wnd); ui_server_connect(ui_root(), wnd); ptk_window_set_fullscreen(wnd, true); ui_metrics.dpi = 1.f * ptk_window_get_dpi(wnd); break; - case LCUI_DISPLAY_MODE_SEAMLESS: + case LCUI_DISPLAY_SEAMLESS: options.child_list = true; lcui_ui.observer = - ui_mutation_observer_create(lcui_on_ui_mutation, NULL); + ui_mutation_observer_create(lcui_ui_on_mutation, NULL); ui_mutation_observer_observe(lcui_ui.observer, ui_root(), options); for (list_each(node, &ui_root()->children)) { @@ -265,7 +148,7 @@ void lcui_set_ui_display_mode(lcui_display_mode_t mode) ui_server_connect(node->data, wnd); } break; - case LCUI_DISPLAY_MODE_WINDOWED: + case LCUI_DISPLAY_WINDOWED: default: wnd = ptk_window_create(NULL, 0, 0, 0, 0, NULL); list_append(&lcui_ui.windows, wnd); @@ -277,134 +160,6 @@ void lcui_set_ui_display_mode(lcui_display_mode_t mode) lcui_ui.quit_after_all_windows_closed = true; } -void lcui_init_ui_preset_widgets(void) -{ - ui_register_text(); - ui_register_canvas(); - ui_register_anchor(); - ui_register_button(); - ui_register_scrollarea(); - ui_register_scrollbar(); - ui_register_textcaret(); - ui_register_textinput(); -} - -void lcui_destroy_ui_preset_widgets(void) -{ - ui_unregister_text(); - ui_unregister_anchor(); -} - -#ifdef PTK_WIN32 -static void lcui_load_fonts_for_windows(void) -{ - size_t i; - int *ids = NULL; - const char *names[] = { "Consola", "Simsun", "Microsoft YaHei", NULL }; - const char *fonts[] = { "C:/Windows/Fonts/consola.ttf", - "C:/Windows/Fonts/simsun.ttc", - "C:/Windows/Fonts/msyh.ttf", - "C:/Windows/Fonts/msyh.ttc" }; - - for (i = 0; i < sizeof(fonts) / sizeof(char *); ++i) { - pd_font_library_load_file(fonts[i]); - } - i = pd_font_library_query(&ids, PD_FONT_STYLE_NORMAL, - PD_FONT_WEIGHT_NORMAL, names); - if (i > 0) { - pd_font_library_set_default_font(ids[i - 1]); - } - free(ids); -} - -#else - -#ifdef HAVE_FONTCONFIG - -static void lcui_load_fonts_by_font_config(void) -{ - size_t i; - char *path; - int *ids = NULL; - const char *names[] = { "Noto Sans CJK", "Ubuntu", - "WenQuanYi Micro Hei", NULL }; - const char *fonts[] = { "Ubuntu", "Noto Sans CJK SC", - "WenQuanYi Micro Hei" }; - - for (i = 0; i < sizeof(fonts) / sizeof(char *); ++i) { - path = pd_font_library_get_font_path(fonts[i]); - pd_font_library_load_file(path); - free(path); - } - i = pd_font_library_query(&ids, PD_FONT_STYLE_NORMAL, - PD_FONT_WEIGHT_NORMAL, names); - if (i > 0) { - pd_font_library_set_default_font(ids[i - 1]); - } - free(ids); -} - -#else - -static void lcui_load_fonts_for_linux(void) -{ - size_t i; - int *ids = NULL; - const char *names[] = { "Noto Sans CJK SC", "Ubuntu", "Ubuntu Mono", - "WenQuanYi Micro Hei", NULL }; - const char *fonts[] = { - "/usr/share/fonts/truetype/ubuntu/Ubuntu-BI.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-B.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-C.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-LI.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-L.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-MI.ttf", - "/usr/share/fonts/truetype/ubuntu/UbuntuMono-BI.ttf", - "/usr/share/fonts/truetype/ubuntu/UbuntuMono-B.ttf", - "/usr/share/fonts/truetype/ubuntu/UbuntuMono-RI.ttf", - "/usr/share/fonts/truetype/ubuntu/UbuntuMono-R.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-M.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-RI.ttf", - "/usr/share/fonts/truetype/ubuntu/Ubuntu-R.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-R.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-RI.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-B.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-BI.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-M.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-MI.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-L.ttf", - "/usr/share/fonts/truetype/ubuntu-font-family/Ubuntu-LI.ttf", - "/usr/share/fonts/opentype/noto/NotoSansCJK-Regular.ttc", - "/usr/share/fonts/opentype/noto/NotoSansCJK.ttc", - "/usr/share/fonts/truetype/wqy/wqy-microhei.ttc" - }; - - for (i = 0; i < sizeof(fonts) / sizeof(char *); ++i) { - pd_font_library_load_file(fonts[i]); - } - i = pd_font_library_query(&ids, PD_FONT_STYLE_NORMAL, - PD_FONT_WEIGHT_NORMAL, names); - if (i > 0) { - pd_font_library_set_default_font(ids[i - 1]); - } - free(ids); -} -#endif - -#endif - -static void lcui_load_default_fonts(void) -{ -#ifdef PTK_WIN32 - lcui_load_fonts_for_windows(); -#elif defined(HAVE_FONTCONFIG) - logger_debug("[font] fontconfig enabled\n"); - lcui_load_fonts_by_font_config(); -#else - lcui_load_fonts_for_linux(); -#endif -} - static void lcui_ui_image_loader_refresh(void) { thread_mutex_lock(&lcui_ui.image_loader.mutex); @@ -429,7 +184,7 @@ static void lcui_ui_image_loader_thread(void *unused) thread_exit(NULL); } -void lcui_init_ui(void) +void lcui_ui_init(void) { thread_cond_init(&lcui_ui.image_loader.cond); thread_mutex_init(&lcui_ui.image_loader.mutex); @@ -446,16 +201,14 @@ void lcui_init_ui(void) ui_widget_resize(ui_root(), DEFAULT_WINDOW_WIDTH, DEFAULT_WINDOW_HEIGHT); list_create(&lcui_ui.windows); - lcui_set_ui_display_mode(LCUI_DISPLAY_MODE_DEFAULT); - lcui_init_ui_preset_widgets(); - lcui_load_default_fonts(); - ptk_on_event(PTK_EVENT_CLOSE, lcui_on_window_destroy, NULL); + lcui_ui_set_display(LCUI_DISPLAY_DEFAULT); + ptk_on_event(PTK_EVENT_CLOSE, lcui_ui_on_window_destroy, NULL); } -void lcui_destroy_ui(void) +void lcui_ui_destroy(void) { - ptk_off_event(PTK_EVENT_CLOSE, lcui_on_window_destroy); - list_destroy(&lcui_ui.windows, lcui_close_window); + ptk_off_event(PTK_EVENT_CLOSE, lcui_ui_on_window_destroy); + list_destroy(&lcui_ui.windows, lcui_ui_close_window); if (lcui_ui.observer) { ui_mutation_observer_disconnect(lcui_ui.observer); ui_mutation_observer_destroy(lcui_ui.observer); @@ -467,7 +220,6 @@ void lcui_destroy_ui(void) thread_join(lcui_ui.image_loader.thread, NULL); thread_mutex_destroy(&lcui_ui.image_loader.mutex); thread_cond_destroy(&lcui_ui.image_loader.cond); - lcui_destroy_ui_preset_widgets(); ui_server_destroy(); ui_destroy(); } diff --git a/src/lcui_widgets.c b/src/lcui_widgets.c new file mode 100644 index 000000000..412405bd8 --- /dev/null +++ b/src/lcui_widgets.c @@ -0,0 +1,32 @@ +/* + * src/lcui_widgets.c + * + * Copyright (c) 2024, Liu Chao 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 + +void lcui_widgets_init(void) +{ + ui_register_text(); + ui_register_canvas(); + ui_register_anchor(); + ui_register_button(); + ui_register_scrollarea(); + ui_register_scrollbar(); + ui_register_textcaret(); + ui_register_textinput(); + ui_register_router_link(); + ui_register_router_view(); +} + +void lcui_widgets_destroy(void) +{ + ui_unregister_text(); + ui_unregister_anchor(); +} diff --git a/src/lcui_worker.c b/src/lcui_worker.c new file mode 100644 index 000000000..f1025992b --- /dev/null +++ b/src/lcui_worker.c @@ -0,0 +1,67 @@ +/* + * src/lcui_worker.c + * + * Copyright (c) 2024, Liu Chao 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 +#include +#include +#include + +static struct lcui_worker { + worker_t *main_worker; + worker_t *async_worker; +} lcui_worker; + +worker_task_t *lcui_worker_post_task(void *data, worker_task_cb task_cb, + worker_task_cb after_task_cb) +{ + if (!lcui_worker.main_worker) { + return NULL; + } + return worker_post_task(lcui_worker.main_worker, data, task_cb, + after_task_cb); +} + +worker_task_t *lcui_worker_post_async_task(void *data, worker_task_cb task_cb, + worker_task_cb after_task_cb) +{ + return worker_post_task(lcui_worker.async_worker, data, task_cb, + after_task_cb); +} + +bool lcui_worker_cancel_async_task(worker_task_t *task) +{ + return worker_cancel_task(lcui_worker.async_worker, task); +} + +bool lcui_worker_cancel_task(worker_task_t *task) +{ + return worker_cancel_task(lcui_worker.async_worker, task); +} + +void lcui_worker_run(void) +{ + worker_run(lcui_worker.main_worker); +} + +void lcui_worker_init(void) +{ + lcui_worker.main_worker = worker_create(); + lcui_worker.async_worker = worker_create(); + worker_run_async(lcui_worker.async_worker); +} + +void lcui_worker_destroy(void) +{ + worker_destroy(lcui_worker.main_worker); + worker_destroy(lcui_worker.async_worker); + lcui_worker.main_worker = NULL; + lcui_worker.async_worker = NULL; +} diff --git a/lib/ui-widgets/src/anchor.c b/src/widgets/anchor.c similarity index 98% rename from lib/ui-widgets/src/anchor.c rename to src/widgets/anchor.c index cbc51722e..21ce034b2 100644 --- a/lib/ui-widgets/src/anchor.c +++ b/src/widgets/anchor.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/anchor.c: to element in HTML. + * src/widgets/anchor.c: to element in HTML. * * Copyright (c) 2018-2024, Liu chao All rights reserved. * @@ -13,9 +13,9 @@ #include #include #include -#include #include #include +#include typedef struct xml_loader { /** 键,作为在视图加载完后传给事件处理器的额外参数 */ diff --git a/lib/ui-widgets/src/button.c b/src/widgets/button.c similarity index 91% rename from lib/ui-widgets/src/button.c rename to src/widgets/button.c index b9d4989a4..e08665123 100644 --- a/lib/ui-widgets/src/button.c +++ b/src/widgets/button.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/button.c: -- Button widget + * src/widgets/button.c: -- Button widget * * Copyright (c) 2018-2024, Liu chao All rights reserved. * @@ -13,8 +13,8 @@ #include #include #include -#include -#include +#include +#include static ui_widget_prototype_t *ui_button_prototype = NULL; diff --git a/lib/ui-widgets/src/canvas.c b/src/widgets/canvas.c similarity index 97% rename from lib/ui-widgets/src/canvas.c rename to src/widgets/canvas.c index 1ec93dcef..e077a664a 100644 --- a/lib/ui-widgets/src/canvas.c +++ b/src/widgets/canvas.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/canvas.c: -- canvas, used to draw custom graphics + * src/widgets/canvas.c: -- canvas, used to draw custom graphics * * Copyright (c) 2019-2024, Liu chao All rights reserved. * @@ -12,7 +12,7 @@ #include #include #include -#include +#include typedef struct ui_canvas { pd_canvas_t buffer; diff --git a/src/widgets/config.h.in b/src/widgets/config.h.in new file mode 100644 index 000000000..f43cd2872 --- /dev/null +++ b/src/widgets/config.h.in @@ -0,0 +1,5 @@ +#define LCUI_VERSION "${VERSION}" +#define LCUI_VERSION_MAJOR ${VERSION_MAJOR} +#define LCUI_VERSION_MINOR ${VERSION_MINOR} +#define LCUI_VERSION_ALTER ${VERSION_ALTER} +${define LCUI_STATIC_BUILD} diff --git a/lib/ui-router/src/link.c b/src/widgets/router_link.c similarity index 92% rename from lib/ui-router/src/link.c rename to src/widgets/router_link.c index 1d57a4be7..33b4e3db9 100644 --- a/lib/ui-router/src/link.c +++ b/src/widgets/router_link.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/link.c + * src/widgets/router_link.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -9,8 +9,9 @@ * LICENSE.TXT file in the root directory of this source tree. */ -#include "private.h" -#include +#include +#include +#include // Refer: https://router.vuejs.org/api/#router-link-props @@ -59,7 +60,7 @@ static void ui_router_link_refresh(ui_widget_t *w) ui_router_link_t *link = ui_widget_get_data(w, ui_router_link_proto); if (link->router) { ui_router_link_on_route_update( - w, link->router->history->current, NULL); + w, router_get_current_route(link->router), NULL); } } @@ -95,14 +96,14 @@ static void ui_router_link_on_set_attr(ui_widget_t *w, const char *name, ui_widget_remove_class(w, link->exact_active_class); free(link->exact_active_class); } - link->exact_active_class = strdup(value); + link->exact_active_class = strdup2(value); ui_router_link_refresh(w); } else if (strcmp(name, "active-class") == 0) { if (link->active_class) { ui_widget_remove_class(w, link->active_class); free(link->active_class); } - link->active_class = strdup(value); + link->active_class = strdup2(value); ui_router_link_refresh(w); } else { ui_router_link_proto->proto->setattr(w, name, value); @@ -138,8 +139,8 @@ static void ui_router_link_on_init(ui_widget_t *w) link = ui_widget_add_data(w, ui_router_link_proto, sizeof(ui_router_link_t)); - link->active_class = strdup("router-link-active"); - link->exact_active_class = strdup("router-link-exact-active"); + link->active_class = strdup2("router-link-active"); + link->exact_active_class = strdup2("router-link-exact-active"); link->to = NULL; link->replace = false; link->exact = false; @@ -159,8 +160,8 @@ static void ui_router_link_on_destroy(ui_widget_t *w) router_unwatch(link->router, link->watcher); } router_location_destroy(link->to); - router_mem_free(link->active_class); - router_mem_free(link->exact_active_class); + free(link->active_class); + free(link->exact_active_class); link->watcher = NULL; link->to = NULL; ui_router_link_proto->proto->destroy(w); diff --git a/lib/ui-router/src/view.c b/src/widgets/router_view.c similarity index 97% rename from lib/ui-router/src/view.c rename to src/widgets/router_view.c index fa76edb21..30d360286 100644 --- a/lib/ui-router/src/view.c +++ b/src/widgets/router_view.c @@ -1,5 +1,5 @@ /* - * lib/ui-router/src/view.c + * src/widgets/router_view.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * @@ -9,8 +9,9 @@ * LICENSE.TXT file in the root directory of this source tree. */ -#include "private.h" -#include +#include +#include +#include typedef struct ui_router_view { size_t index; diff --git a/lib/ui-widgets/src/scrollarea.c b/src/widgets/scrollarea.c similarity index 99% rename from lib/ui-widgets/src/scrollarea.c rename to src/widgets/scrollarea.c index 2c6acbf19..aebe27bb9 100644 --- a/lib/ui-widgets/src/scrollarea.c +++ b/src/widgets/scrollarea.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/scrollarea.c + * src/widgets/scrollarea.c * * Copyright (c) 2024, Liu Chao All rights reserved. * @@ -10,7 +10,7 @@ */ #include -#include +#include typedef struct ui_scrollarea { float scroll_top; diff --git a/lib/ui-widgets/src/scrollbar.c b/src/widgets/scrollbar.c similarity index 99% rename from lib/ui-widgets/src/scrollbar.c rename to src/widgets/scrollbar.c index 41f670cfd..ff117758c 100644 --- a/lib/ui-widgets/src/scrollbar.c +++ b/src/widgets/scrollbar.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/scrollbar.c: -- Scrollbar widget + * src/widgets/scrollbar.c: -- Scrollbar widget * * Copyright (c) 2018-2024, Liu chao All rights reserved. * @@ -14,8 +14,8 @@ #include #include #include -#include -#include +#include +#include #include typedef struct ui_scrollbar { diff --git a/lib/ui-widgets/src/text.c b/src/widgets/text.c similarity index 99% rename from lib/ui-widgets/src/text.c rename to src/widgets/text.c index 20feecfd3..1c2bd6769 100644 --- a/lib/ui-widgets/src/text.c +++ b/src/widgets/text.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/text.c: -- TextView widget for display text. + * src/widgets/text.c: -- TextView widget for display text. * * Copyright (c) 2018-2024, Liu chao All rights reserved. * @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include "textstyle.h" typedef struct ui_text_task { diff --git a/lib/ui-widgets/src/textcaret.c b/src/widgets/textcaret.c similarity index 96% rename from lib/ui-widgets/src/textcaret.c rename to src/widgets/textcaret.c index 3cda34287..e43e4b7d2 100644 --- a/lib/ui-widgets/src/textcaret.c +++ b/src/widgets/textcaret.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/textcaret.c: -- textcaret widget, used in textinput. + * src/widgets/textcaret.c: -- textcaret widget, used in textinput. * * Copyright (c) 2018-2024, Liu chao All rights reserved. * @@ -13,8 +13,8 @@ #include #include #include -#include -#include +#include +#include #include typedef struct ui_textcaret_task { diff --git a/lib/ui-widgets/src/textinput.c b/src/widgets/textinput.c similarity index 99% rename from lib/ui-widgets/src/textinput.c rename to src/widgets/textinput.c index e827e650c..6de976a6f 100644 --- a/lib/ui-widgets/src/textinput.c +++ b/src/widgets/textinput.c @@ -1,6 +1,5 @@ /* - * lib/ui-widgets/src/textinput.c: -- textinput widget, used to allow user edit - * text. + * src/widgets/textinput.c: -- textinput widget, used to allow user edit * * Copyright (c) 2018-2024, Liu chao All rights reserved. * @@ -17,8 +16,8 @@ #include #include #include -#include -#include +#include +#include #include "textstyle.h" #define TEXTBLOCK_SIZE 512 diff --git a/lib/ui-widgets/src/textstyle.c b/src/widgets/textstyle.c similarity index 96% rename from lib/ui-widgets/src/textstyle.c rename to src/widgets/textstyle.c index bc6fe8592..d03e9d0c2 100644 --- a/lib/ui-widgets/src/textstyle.c +++ b/src/widgets/textstyle.c @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/textstyle.c + * src/widgets/textstyle.c * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * diff --git a/lib/ui-widgets/src/textstyle.h b/src/widgets/textstyle.h similarity index 91% rename from lib/ui-widgets/src/textstyle.h rename to src/widgets/textstyle.h index 86306cc19..b80160016 100644 --- a/lib/ui-widgets/src/textstyle.h +++ b/src/widgets/textstyle.h @@ -1,5 +1,5 @@ /* - * lib/ui-widgets/src/textstyle.h + * src/widgets/textstyle.h * * Copyright (c) 2023-2024, Liu Chao All rights reserved. * diff --git a/tests/cases/test_mainloop.c b/tests/cases/test_mainloop.c index 310a3b79e..9e79f0fc0 100644 --- a/tests/cases/test_mainloop.c +++ b/tests/cases/test_mainloop.c @@ -27,7 +27,7 @@ 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); - lcui_process_events(PTK_PROCESS_EVENTS_UNTIL_QUIT); + lcui_app_process_events(PTK_PROCESS_EVENTS_UNTIL_QUIT); lcui_quit(); } diff --git a/tests/cases/test_router.c b/tests/cases/test_router.c new file mode 100644 index 000000000..df545d5ab --- /dev/null +++ b/tests/cases/test_router.c @@ -0,0 +1,103 @@ + +#include +#include +#include + +void test_router_components(void) +{ + router_t *router; + router_config_t *config; + ui_widget_t *root; + ui_widget_t *link_foo; + ui_widget_t *link_foobar; + ui_widget_t *link_bar; + ui_widget_t *view; + ui_widget_t *matched_widget; + ui_event_t e; + + router = router_create(NULL); + config = router_config_create(); + router_config_set_path(config, "/foo"); + router_config_set_component(config, NULL, "foo"); + router_add_route_record(router, config, NULL); + router_config_destroy(config); + + config = router_config_create(); + router_config_set_path(config, "/foo/bar"); + router_config_set_component(config, NULL, "foobar"); + router_add_route_record(router, config, NULL); + router_config_destroy(config); + + config = router_config_create(); + router_config_set_path(config, "/bar"); + router_config_set_component(config, NULL, "bar"); + router_add_route_record(router, config, NULL); + router_config_destroy(config); + + ui_init(); + ui_register_text(); + ui_register_router_link(); + ui_register_router_view(); + ui_create_widget_prototype("foo", NULL); + ui_create_widget_prototype("foobar", NULL); + ui_create_widget_prototype("bar", NULL); + root = ui_root(); + view = ui_create_widget("router-view"); + link_foo = ui_create_widget("router-link"); + link_foobar = ui_create_widget("router-link"); + link_bar = ui_create_widget("router-link"); + ui_widget_set_attr(link_foo, "to", "/foo"); + ui_widget_set_attr(link_foobar, "to", "/foo/bar"); + ui_widget_set_attr(link_bar, "to", "/bar"); + ui_widget_append(root, link_foo); + ui_widget_append(root, link_foobar); + ui_widget_append(root, link_bar); + ui_widget_append(root, view); + ui_update(); + + ui_event_init(&e, "click"); + ui_widget_emit_event(link_foo, e, NULL); + matched_widget = ui_router_view_get_matched_widget(view); + ctest_equal_bool("[/foo] widget should load widget", + strcmp(matched_widget->type, "foo") == 0, true); + ctest_equal_bool( + "[/foo] linkFoo should has active classes", + (ui_widget_has_class(link_foo, "router-link-active") && + ui_widget_has_class(link_foo, "router-link-exact-active")), + true); + ui_widget_emit_event(link_bar, e, NULL); + matched_widget = ui_router_view_get_matched_widget(view); + ctest_equal_bool("[/bar] widget should load widget", + strcmp(matched_widget->type, "bar") == 0, true); + ctest_equal_bool( + "[/bar] linkFoo should not has active classes", + (!ui_widget_has_class(link_foo, "router-link-exact-active") && + !ui_widget_has_class(link_foo, "router-link-active")), + true); + + ui_widget_emit_event(link_foobar, e, NULL); + matched_widget = ui_router_view_get_matched_widget(view); + ctest_equal_bool( + "[/foo/bar] widget should load widget", + strcmp(matched_widget->type, "foobar") == 0, true); + ctest_equal_bool( + "[/foo/bar] linkFooBar should has active classes", + (ui_widget_has_class(link_foobar, "router-link-exact-active") && + ui_widget_has_class(link_foobar, "router-link-active")), + true); + ctest_equal_bool( + "[/foo/bar] linkFoo should only has the exact active class", + (!ui_widget_has_class(link_foo, "router-link-exact-active") && + ui_widget_has_class(link_foo, "router-link-active")), + true); + ui_widget_set_attr(link_foo, "exact", "exact"); + ui_widget_emit_event(link_foobar, e, NULL); + ctest_equal_bool( + "[/foo/bar] linkFoo should not has any active classes (exact)", + (!ui_widget_has_class(link_foo, "router-link-exact-active") && + !ui_widget_has_class(link_foo, "router-link-active")), + true); + + ui_destroy(); + router_destroy(router); +} diff --git a/tests/cases/test_scrollbar.c b/tests/cases/test_scrollbar.c index 61f2d5b55..e4980f363 100644 --- a/tests/cases/test_scrollbar.c +++ b/tests/cases/test_scrollbar.c @@ -102,7 +102,7 @@ void test_scrollbar(void) ui_widget_resize(ui_root(), 800, 640); ui_load_css_string(test_css, __FILE__); build_content_view(); - lcui_update_ui(); + lcui_ui_update(); content = ui_get_widget("license_content"); left = content->computed_style.left; @@ -112,20 +112,20 @@ void test_scrollbar(void) e.mouse.x = 300; e.mouse.y = 275; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); e.type = UI_EVENT_MOUSEDOWN; e.mouse.button = MOUSE_BUTTON_LEFT; e.mouse.x = 300; e.mouse.y = 275; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); e.type = UI_EVENT_MOUSEMOVE; e.mouse.x = 600; e.mouse.y = 275; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); ctest_equal_bool("content should be moved to the left", content->computed_style.left < left && @@ -144,7 +144,7 @@ void test_scrollbar(void) e.mouse.x = 400; e.mouse.y = 275; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); ctest_equal_bool("content should be moved to the right", content->computed_style.left > left && @@ -158,20 +158,20 @@ void test_scrollbar(void) e.mouse.x = 555; e.mouse.y = 45; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); e.type = UI_EVENT_MOUSEDOWN; e.mouse.button = MOUSE_BUTTON_LEFT; e.mouse.x = 555; e.mouse.y = 45; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); e.type = UI_EVENT_MOUSEMOVE; e.mouse.x = 555; e.mouse.y = 200; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); ctest_equal_bool("content should be moved to the top", content->computed_style.left == left && @@ -190,7 +190,7 @@ void test_scrollbar(void) e.mouse.x = 555; e.mouse.y = 100; ui_dispatch_event(&e); - lcui_update_ui(); + lcui_ui_update(); ctest_equal_bool("the content should have scrolled to the bottom", content->computed_style.left == left && diff --git a/tests/cases/test_settings.c b/tests/cases/test_settings.c index 6de87be34..60ccdbb24 100644 --- a/tests/cases/test_settings.c +++ b/tests/cases/test_settings.c @@ -17,7 +17,7 @@ static void check_settings_frame_rate_cap(void *arg) { char str[256]; int fps_limit = *((int *)arg); - int fps = (int)lcui_get_fps(); + int fps = (int)lcui_app_get_fps(); sprintf(str, "should work when frame cap is %u (actual %u)", fps_limit, fps); diff --git a/tests/helloworld_uwp/App.cpp b/tests/helloworld_uwp/App.cpp index d01c7d3a9..4e27733d2 100644 --- a/tests/helloworld_uwp/App.cpp +++ b/tests/helloworld_uwp/App.cpp @@ -2,8 +2,8 @@ #include #include #include -#include -#include +#include +#include #include #include LCUI_APP_H diff --git a/tests/run_tests.c b/tests/run_tests.c index c1a5a62ba..332e3dbde 100644 --- a/tests/run_tests.c +++ b/tests/run_tests.c @@ -31,6 +31,7 @@ int main(int argc, char **argv) ctest_describe("test text resize", test_text_resize); ctest_describe("test textinput", test_textinput); ctest_describe("test scrollbar", test_scrollbar); + ctest_describe("test router components", test_router_components); ctest_describe("test widget rect", test_widget_rect); ctest_describe("test block layout", test_block_layout); ctest_describe("test flex layout", test_flex_layout); diff --git a/tests/run_tests.h b/tests/run_tests.h index e50be3a81..cafb3012f 100644 --- a/tests/run_tests.h +++ b/tests/run_tests.h @@ -24,3 +24,4 @@ void test_block_layout(void); void test_flex_layout(void); void test_widget_rect(void); void test_clipboard(void); +void test_router_components(void); diff --git a/tests/test_render.c b/tests/test_render.c index c4427cfd2..1edddcd4b 100644 --- a/tests/test_render.c +++ b/tests/test_render.c @@ -157,8 +157,8 @@ int main(int argc, char* argv[]) for (i = 0; i < 600; ++i) { UpdateFrame(self.box); lcui_process_timers(); - lcui_update_ui(); - lcui_render_ui(); + lcui_ui_update(); + lcui_ui_render(); app_present(); ++self.fps; ++self.color_index; diff --git a/tests/test_widget.c b/tests/test_widget.c index b3070bb86..a67be2c19 100644 --- a/tests/test_widget.c +++ b/tests/test_widget.c @@ -12,7 +12,7 @@ #include #include #include -#include +#include int main(void) { diff --git a/xmake.lua b/xmake.lua index 21baa2dd0..17d7a2e0c 100644 --- a/xmake.lua +++ b/xmake.lua @@ -14,12 +14,11 @@ add_includedirs( "lib/i18n/include", "lib/ptk/include", "lib/worker/include", + "lib/router/include", "lib/ui/include", "lib/ui-server/include", - "lib/ui-widgets/include", "lib/ui-cursor/include", "lib/ui-xml/include", - "lib/ui-router/include", "include", {public = true} ) @@ -74,7 +73,7 @@ target("lcui_tests") target("lcui") set_kind("$(kind)") - add_files("src/*.c") + add_files("src/**.c") if is_kind("static") then set_configvar("LCUI_STATIC_BUILD", 1) elseif is_plat("windows") then @@ -91,10 +90,9 @@ target("lcui") "libcss", "libi18n", "libui", - "libui-widgets", "libui-cursor", "libui-server", - "libui-router", + "librouter", "libui-xml" ) add_headerfiles("include/LCUI.h", "include/(LCUI/*.h)")