mirror of
https://github.com/lc-soft/LCUI.git
synced 2026-11-30 16:48:21 +01:00
feat(css): add css value definition parser refactor(css): change the parameter types of css_parse_* functions refactor(css): migrate to new data types refactor(css): migrate to new data types (2) refactor(css): migrate to new data types (3) test: add valdef test feat(css): add css_valdef_parser_finish() refactor(css): split css_library.c refactor(css): css_data_type.c -> css_data_types.c fix(css): the parsing error message of sign is not truncated fix(css): correct initialization of data type library fix(css): error message should not be empty feat(css): add css_valdef_to_string() feat(css): add double bar combinator feat(css): add double ampersand combinator feat(css): add curly braces multiplier feat(css): add brackets combinator parser docs: update css value matcher section feat(css): add question mark multiplier test(css): add test for brackets combinator docs(css): update libcss_css_value.md docs: update directory structure refactor: numberic -> numeric refactor(css): delete style property parser refactor: migrate to css property API docs(css): add css value converter section feat(css): add css_computed_style_t refactor(css): rename `css_style` associated identifiers feat(css): add css_cascade_style() refactor(css): change type of css_value_matcher_t::value refactor(css): update args of css_register_property() refactor(css): move css_computed_style_t feat(css): update opacity property feat(css): update z-index property feat(css): update display property feat(css): update pointer-events property feat(css): update flex-wrap property feat(css): update flex-direction property feat(css): update flex-grow property feat(css): update flex-shrink property feat(css): update align-items property feat(css): update justify-content property feat(css): update position property feat(css): update box-sizing property feat(css): update align-content property feat(css): update white-space property feat(css): update content property feat(css): update text-align property feat(css): automatically register new keywords feat(css): update font-style property feat(css): update visibility property feat(css): update border-*-style property refactor: update css_unit_t definition feat(css): update border-*-*-radius properties refactor(css): delete CSS_PERCENTAGE_VALUE refactor(css): css_cascade_length() -> css_cascade_length_auto() refactor(css): update enum definitions feat(css): update border-*-width properties feat(css): update border-*-color properties feat(css): add css_array_value_get_length() feat(css): add border-width shorthand property feat(css): add border-style shorthand property feat(css): add border-radius shorthand property feat(css): add border-color shorthand property feat(css): add border shorthand property feat(css): add margin shorthand property feat(css): add padding shorthand property feat(css): update size related properties feat(css): update top, right, bottom, left properties feat(css): update flex-basis property feat(css): update line-height property feat(css): update color property refactor(css): add css_cascade_bg_border_color() refactor(css): bits -> keyword_bits refactor(css): flag -> keyword refactor(css): update css_color_value_t definition feat(css): add CSS_COLOR_TRANSPARENT refactor(css): remove transparent keyword feat(css): update font-size property feat(css): update font-family property feat(css): update background shorthand property feat(css): update vertical-align property feat(css): update box-shadow property feat(css): update the computing of the box-shadow property feat(css): update the computing of the background property feat(css): update the computing of the border property refactor(css): keyword_bits -> type_bits refactor(css): enum css_*_e -> uint8_t feat(css): add absolute size computing feat(css): add absolute padding computing feat(css): add absolute margin computing style(css): format code feat(css): add top, right, bottom, and left absolute value computing feat(css): add flex-basis absolute value computing refactor(ui): replace data type of computed style feat(ui): update widget background style computing feat(ui): update widget box-shadow style computing feat(ui): update widget border style computing feat(ui): update widget box computing feat(ui): use tabindex instead of focusable feat(css): remove focusable property feat(css): update font-weight property fix(css): clear compile errors refactor(ui): adapt to new computed style data structure refactor(ui): delete ui_widget_box_model_t fix: clear some compiler warnings refactor(ui): ui_font_style.c -> ui_text_style.c feat(ui): remove unnecessary helper functions fix: clear some compiler warnings fix(font): correct bitmap cache access fix(css): correct the key assignment of keywords fix(css): some memory access errors fix: missing NULL at the end of font names fix: clear gcc errors refactor: clear gcc warnings fix(css): array subscript is above array bounds fix(css): incorrect property name memory allocation fix(css): style parser memory leak fix(css): prop->valdef memory leak refactor(css): logger_debug -> DEBUG_MSG refactor(ui-builder): clear warnings fix(css): css_properties.list memory leak fix(css): css_style_link_group_create() memory leak fix(css): incorrect keyword storage test(css): correct color_value comparison test: clear compiler errors fix(css): correct the return value of css_register_keyword() fix(css): correct integer type value parsing chore(css): _DEBUG -> DEBUG feat(css): add string value parsing fix(css): correct font-family initial value test(css): add test_css_computed.c fix(css): value read error in css_cascade_background() fix(css): add some missing properties feat(css): add flex shorthand property build: update rundir of lcui-css-test fix(css): font-family parsing error feat(css): style array value to string chore(vscode): add compileCommands fix(css): string value parsing error fix(css): correct content property initial value fix(css): the parsed style data is not stored correctly fix(css): correct cascading of some properties fix(css): percentage value parsing inccorect fix(css): <length> should not contain <percentage> fix(css): css_array_value_duplicate() did not copy the last value feat(css): add visible keyword feat(css): cascade each property in order refactor(css): add style_decl.c refactor(css): use css_style_decl_t instead of css_style_t fix(css): incorrect number of resolved values refactor(css): add css_style.c feat(css): parse shorthand properties in the parsing phase refactor(css): add background property parser refactor(css): add border property parser refactor(css): css_select_style_decl -> css_find_style_store refactor(css): add css_select_style_with_cache() refactor(css): add margin property parser refactor(css): add padding property parser refactor(css): add flex property parser fix(ui): incorrect widget style cascading order refactor(css): const css_propdef_t* -> css_propdef_t* refactor(css): update arguments of shorthand property parser fix(css): incorrect value parsing of shorthand property fix(css): unexpected truncation while parsing color value fix(css): correct value matching and style computing fix(ui): correct css style operation fix(platform): crash when closing window refactor(css): delete file prefix refactor(css): delete style.c refactor(css): clear compiler warnings refactor: update directory structure and build configuration feat(css): add dump functions fix(css): correct valdef parser cursor operation fix(css): correct the definition of margin and padding fix(css): correct flex property parsing and definition refactor(ui): adjust the use of calculated styles in the layout engine chore: tests/helloword -> examples/hello fix(ui): some bugs in block layout fix(css): correct flex property definition refactor(ui): simplify the naming of widget style and layout diff API refactor(ui): update reflow trigger rules refactor(ui): ui_widget_auto_reflow -> ui_widget_reflow feat(ui): allow multiple observers to connect to the same widget refactor(ui): simplify widget update process refactor(ui): adjust row processing in block layout refactor(ui): adjust the data structure used in the flexbox layout fix(ui): correct flex layout algorithm build: update config
5.6 KiB
5.6 KiB
libapp
一个为 GUI 应用程序提供窗口和事件管理接口的跨平台开发库。
设计参考
- https://docs.microsoft.com/zh-cn/uwp/api/windows.applicationmodel.core.iframeworkview?view=winrt-20348
- https://wiki.libsdl.org/CategoryEvents
- https://developer.mozilla.org/en-US/docs/Web/API/Event
对象
- app_dispatcher:事件分发器,一个线程上只会分配一个分发器,一个分发器可以管理多个窗口的事件。
- app_window_paint:窗口的绘制上下文。
- app_window: 窗口对象。
- app:应用程序,管理应用程序内包括窗口、事件等在内的资源。
改动
- StepTimer 改为只针对渲染器,不再影响主循环的每秒循环次数
- 取消 MainLoop 主循环相关函数
- 重新设计主循环
- 将 settings 相关逻辑从主循环中分离
功能设计
暴露的公开操作函数只负责调用系统窗口函数,等消息循环处理到相关消息时才更新窗口数据。
接口设计
typedef struct app_t app_t;
typedef struct app_framebuffer_t app_framebuffer_t;
typedef struct app_dispatcher_t app_dispatcher_t;
typedef struct app_event_t app_event_t;
typedef struct app_window_t app_window_t;
typedef struct app_window_rect_t app_window_rect_t;
typedef struct app_window_paint_t app_window_paint_t;
typedef enum app_event_type_t {
APP_EVENT_NONE = 0,
APP_EVENT_WINDOW_CLOSED,
APP_EVENT_POINTER_MOVED,
APP_EVENT_POINTER_PRESSED,
APP_EVENT_POINTER_RELEASED,
APP_EVENT_POINTER_WHEEL_CHANGED,
APP_EVENT_KEY_DOWN,
APP_EVENT_KEY_UP,
APP_EVENT_PAINT,
APP_EVENT_USER = 1000
};
typedef struct app_window_event_t {
app_event_type_t type
};
typedef struct app_event_t {
app_window_t window;
app_window_event_t data;
}
struct app_framebuffer_t {
unsigned width;
unsigned height;
unsigned char *data;
unsigned bits_per_pixel;
size_t line_length;
size_t data_length;
};
struct app_window_rect_t {
unsigned x;
unsigned y;
unsigned width;
unsigned height;
}
struct app_window_paint_t {
app_framebuffer_t fb;
app_window_rect_t rect;
}
// 应用程序基本操作
void app_init(void);
void app_run(void);
void app_stop(void);
void app_free(void);
// 事件功能的内部方法
static void app_dispatcher_new(app_dispatcher_t **dispatcher);
static void app_dispatcher_get_event(app_dispatcher_t *dispatcher);
static void app_dispatcher_post_event(app_dispatcher_t *dispatcher,
app_event_t *e);
// 事件操作
void app_get_event(app_event_t *e);
void app_post_event(app_event_t *e);
void app_poll_event(app_event_t *e);
void app_process_event(app_event_t *e);
// 窗口状态操作
void app_window_new(app_window_t **wnd, wchar_t *title,
int x, int y, int width, int height);
void app_window_activate(app_window_t *wnd);
void app_window_close(app_window_t *wnd);
// 窗口的属性操作
void app_window_set_title(app_window_t *wnd, const wchar_t *title);
void app_window_move(app_window_t *wnd, int x, int y);
void app_window_resize(app_window_t *wnd, int width, int width);
void app_window_get_rect(app_window_t *wnd, app_window_rect_t *rect);
void app_window_set_rect(app_window_t *wnd, app_window_rect_t *rect);
// 窗口的绘制操作
void app_window_begin_paint(app_window_t *wnd, app_window_paint_t **paint,
app_window_rect_t *rect);
void app_window_end_paint(app_window_t *wnd, app_window_paint_t **paint);
更新记录
v0.1.0
采用赋值的形式注册事件回调函数。
int main(void)
{
app_t *app;
app_new(&app);
app->on_pointer_move = on_pointer_move;
app->on_window_closed = on_window_closed;
app->on_key_down = on_key_down;
app_run(app);
app_free(&app);
}
存在的问题:
-
libui 接入难度大
这种事件绑定方式限制了一个事件只能绑定一个处理器,只适合让用户代码处理事件,再接入其它库来处理事件较为困难。
v0.2.0
改为提供专用的函数来绑定事件。
int main(void)
{
app_t *app;
app_event_t e;
ui_init(&app);
app_new(&app);
while (app->running) {
while (app_get_event(app, &e)) {
ui_process_event(&e);
switch (e.type) {
case APP_EVENT_WINDOW_CLOSED:
// ...
break;
default: break;
}
app_process_event(app, &e);
// do somethings
}
}
app_free(&app);
}
问题:
-
写法与 Win32 消息循环相似,没有特色
上述示例代码相当于换了种命名风格的 Win32 消息循环处理代码,例如:
app_get_event()->GetMessage()app_process_event()->DefWindowProc()
-
创建和传递 app 实例对象是多余的
应用程序创建多个 app 对象没有意义,app 应该作为全局存在的单例对象。
v0.3.0
int main()
{
app_event_t e;
app_init();
while (app->running) {
if (app_get_event(&e)) {
ui_process_event(e);
switch (e.type) {
case APP_EVENT_WINDOW_CLSOED:
// ...
break;
default: break;
}
app_process_event(e);
}
}
app_free();
}
v0.4.0
// https://docs.microsoft.com/en-us/uwp/api/Windows.UI.Core.CoreProcessEventsOption?view=winrt-22000
int main()
{
app_event_t e;
app_init_engine();
app_process_events();
// or
app_process_all_events();
// or
app_process_events_until_quit();
app_destroy_engine();
}