diff --git a/.github/workflows/ccpp.yml b/.github/workflows/ccpp.yml index f6be3fa82..be636413b 100644 --- a/.github/workflows/ccpp.yml +++ b/.github/workflows/ccpp.yml @@ -25,7 +25,9 @@ jobs: - name: Install tools if: runner.os == 'Linux' - run: sudo apt install debhelper lcov valgrind -yy + run: | + sudo apt-get update --fix-missing + sudo apt-get install debhelper lcov valgrind -yy - name: Configure for coverage mode if: runner.os == 'Linux' @@ -98,7 +100,7 @@ jobs: xmake package xmake install -o dist/lcui-package - - name: Package exmaples + - name: Package examples run: | cd examples xmake -P . -v -y @@ -122,7 +124,7 @@ jobs: uses: actions/cache@v3 with: path: ~/.xmake/.cache/packages - key: ${{ runner.os }}-xmake-pacages + key: ${{ runner.os }}-xmake-packages release: if: startsWith(github.ref, 'refs/tags/v') diff --git a/examples/fabric/xmake.lua b/examples/fabric/xmake.lua index ff9354d26..cae897a55 100644 --- a/examples/fabric/xmake.lua +++ b/examples/fabric/xmake.lua @@ -1,4 +1,4 @@ -add_requires("cairo 1.17.6") +add_requires("cairo") target("fabric") set_kind("binary") diff --git a/lib/css/src/library.c b/lib/css/src/library.c index 8ba7a2be6..12b0baede 100644 --- a/lib/css/src/library.c +++ b/lib/css/src/library.c @@ -254,7 +254,7 @@ static css_style_group_t *css_style_group_create(void) static css_style_decl_t *css_find_style_store(css_selector_t *selector, const char *space) { - int i, right; + int i, right, len; css_style_link_t *link; css_style_rule_t *snode; css_style_link_group_t *slg; @@ -296,8 +296,15 @@ static css_style_decl_t *css_find_style_store(css_selector_t *selector, strcpy(fullname, buf); } else { strcpy(fullname, buf); - snprintf(buf, CSS_SELECTOR_MAX_LEN, "%s %s", + len = snprintf(buf, CSS_SELECTOR_MAX_LEN, "%s %s", sn->fullname, fullname); + if (len < 0) { + logger_error("[css-library] %s: " + "selector(%s...) too long\n", + space, fullname); + return NULL; + } + buf[len] = 0; } /* 如果有上一级的父链接记录,则将当前链接添加进去 */ if (parents) { diff --git a/lib/css/tests/test_css_computed.c b/lib/css/tests/test_css_computed.c index c2d10c972..a83ea6fea 100644 --- a/lib/css/tests/test_css_computed.c +++ b/lib/css/tests/test_css_computed.c @@ -9,7 +9,7 @@ static void check_length(const char *str, css_numeric_value_t actual, ctest_equal_int(str, (int)actual, (int)expected); } -static test_button_focus_style(void) +static void test_button_focus_style(void) { css_selector_t *selector; css_style_decl_t *result; diff --git a/lib/i18n/tests/test.c b/lib/i18n/tests/test.c index 7d63db24c..d7ecb4d7f 100644 --- a/lib/i18n/tests/test.c +++ b/lib/i18n/tests/test.c @@ -22,29 +22,29 @@ void test_i18n(void) i18n_change_language(L"en"); - ctest_equal_bool("i18n_translate(L\"name\") == L\"English\")", + ctest_equal_bool("en: i18n_translate(L\"name\") == L\"English\")", wcscmp(i18n_translate(L"name"), L"English") == 0, true); - ctest_equal_bool("i18n_translate(L\"button.ok\") == L\"Ok\")", + ctest_equal_bool("en: i18n_translate(L\"button.ok\") == L\"Ok\")", wcscmp(i18n_translate(L"button.ok"), L"Ok") == 0, true); - ctest_equal_bool("i18n_translate(L\"button.notfound\") == NULL)", + ctest_equal_bool("en: i18n_translate(L\"button.notfound\") == NULL)", i18n_translate(L"button.notfound")== NULL, true); i18n_change_language(L"zh-CN"); - ctest_equal_bool("i18n_translate(L\"name\") == L\"中文\")", - wcscmp(i18n_translate(L"name"), L"中文") == 0, + ctest_equal_bool("zh-CN: i18n_translate(L\"name\")", + wcscmp(i18n_translate(L"name"), L"\u4E2D\u6587") == 0, true); - ctest_equal_bool("i18n_translate(L\"button.ok\") == L\"确定\")", - wcscmp(i18n_translate(L"button.ok"), L"确定") == 0, + ctest_equal_bool("zh-CN: i18n_translate(L\"button.ok\")", + wcscmp(i18n_translate(L"button.ok"), L"\u786E\u5B9A") == 0, true); - ctest_equal_bool("i18n_translate(L\"button.notfound\") == NULL)", + ctest_equal_bool("zh-CN: i18n_translate(L\"button.notfound\") == NULL", i18n_translate(L"button.notfound")== NULL, true); i18n_clear(); diff --git a/lib/ui/src/ui_tree.c b/lib/ui/src/ui_tree.c index 5a579325c..00b0dba66 100644 --- a/lib/ui/src/ui_tree.c +++ b/lib/ui/src/ui_tree.c @@ -11,386 +11,390 @@ #define TYPE_CHILD_LIST UI_MUTATION_RECORD_TYPE_CHILD_LIST -int ui_widget_append(ui_widget_t* parent, ui_widget_t* widget) +int ui_widget_append(ui_widget_t *parent, ui_widget_t *widget) { - ui_event_t ev = { 0 }; - ui_mutation_record_t* record; + ui_event_t ev = { 0 }; + ui_mutation_record_t *record; - if (!parent || !widget) { - return -1; - } - if (parent == widget) { - return -2; - } - ui_widget_unlink(widget); - widget->parent = parent; - widget->state = UI_WIDGET_STATE_CREATED; - widget->index = parent->children.length; - widget->parent->update.should_update_children = true; - list_append_node(&parent->children, &widget->node); - ev.cancel_bubble = true; - ev.type = UI_EVENT_LINK; - ui_widget_request_refresh_style(widget); - ui_widget_refresh_children_style(widget); - ui_widget_emit_event(widget, ev, NULL); - ui_widget_update_status(widget); - ui_widget_request_reflow(parent); - if (ui_widget_has_observer(parent, TYPE_CHILD_LIST)) { - record = ui_mutation_record_create(widget, TYPE_CHILD_LIST); - list_append(&record->added_widgets, widget); - ui_widget_add_mutation_record(parent, record); - ui_mutation_record_destroy(record); - } - return 0; + if (!parent || !widget) { + return -1; + } + if (parent == widget) { + return -2; + } + ui_widget_unlink(widget); + widget->parent = parent; + widget->state = UI_WIDGET_STATE_CREATED; + widget->index = parent->children.length; + widget->parent->update.should_update_children = true; + list_append_node(&parent->children, &widget->node); + ev.cancel_bubble = true; + ev.type = UI_EVENT_LINK; + ui_widget_request_refresh_style(widget); + ui_widget_refresh_children_style(widget); + ui_widget_emit_event(widget, ev, NULL); + ui_widget_update_status(widget); + ui_widget_request_reflow(parent); + if (ui_widget_has_observer(parent, TYPE_CHILD_LIST)) { + record = ui_mutation_record_create(widget, TYPE_CHILD_LIST); + list_append(&record->added_widgets, widget); + ui_widget_add_mutation_record(parent, record); + ui_mutation_record_destroy(record); + } + return 0; } -int ui_widget_prepend(ui_widget_t* parent, ui_widget_t* widget) +int ui_widget_prepend(ui_widget_t *parent, ui_widget_t *widget) { - ui_widget_t* child; - ui_mutation_record_t* record; - ui_event_t ev = { 0 }; - list_node_t* node; + ui_widget_t *child; + ui_mutation_record_t *record; + ui_event_t ev = { 0 }; + list_node_t *node; - if (!parent || !widget) { - return -1; - } - if (parent == widget) { - return -2; - } - child = widget->parent; - ui_widget_unlink(widget); - widget->index = 0; - widget->parent = parent; - widget->state = UI_WIDGET_STATE_CREATED; - widget->parent->update.should_update_children = true; - node = &widget->node; - list_insert_node(&parent->children, 0, node); - /** 修改它后面的部件的 index 值 */ - node = node->next; - while (node) { - child = node->data; - child->index += 1; - node = node->next; - } - ev.cancel_bubble = true; - ev.type = UI_EVENT_LINK; - ui_widget_emit_event(widget, ev, NULL); - ui_widget_request_refresh_children(widget); - ui_widget_update_status(widget); - ui_widget_request_reflow(parent); - if (ui_widget_has_observer(parent, TYPE_CHILD_LIST)) { - record = ui_mutation_record_create(widget, TYPE_CHILD_LIST); - list_append(&record->added_widgets, widget); - ui_widget_add_mutation_record(parent, record); - ui_mutation_record_destroy(record); - } - return 0; + if (!parent || !widget) { + return -1; + } + if (parent == widget) { + return -2; + } + child = widget->parent; + ui_widget_unlink(widget); + widget->index = 0; + widget->parent = parent; + widget->state = UI_WIDGET_STATE_CREATED; + widget->parent->update.should_update_children = true; + node = &widget->node; + list_insert_node(&parent->children, 0, node); + /** 修改它后面的部件的 index 值 */ + node = node->next; + while (node) { + child = node->data; + child->index += 1; + node = node->next; + } + ev.cancel_bubble = true; + ev.type = UI_EVENT_LINK; + ui_widget_emit_event(widget, ev, NULL); + ui_widget_request_refresh_children(widget); + ui_widget_update_status(widget); + ui_widget_request_reflow(parent); + if (ui_widget_has_observer(parent, TYPE_CHILD_LIST)) { + record = ui_mutation_record_create(widget, TYPE_CHILD_LIST); + list_append(&record->added_widgets, widget); + ui_widget_add_mutation_record(parent, record); + ui_mutation_record_destroy(record); + } + return 0; } -int ui_widget_unwrap(ui_widget_t* w) +int ui_widget_unwrap(ui_widget_t *w) { - size_t len; - ui_widget_t* child; - ui_event_t ev = { 0 }; - ui_mutation_record_t* record; - list_t* children; - list_node_t *target, *node, *prev; + size_t len; + ui_widget_t *child; + ui_event_t ev = { 0 }; + ui_mutation_record_t *record; + list_t *children; + list_node_t *target, *node, *prev; - if (!w->parent) { - return -1; - } - if (ui_widget_has_observer(w, TYPE_CHILD_LIST)) { - record = ui_mutation_record_create(w, TYPE_CHILD_LIST); - for (list_each(node, &w->children)) { - list_append(&record->removed_widgets, node->data); - } - ui_widget_add_mutation_record(w, record); - ui_mutation_record_destroy(record); - } - if (ui_widget_has_observer(w->parent, TYPE_CHILD_LIST)) { - record = ui_mutation_record_create(w->parent, TYPE_CHILD_LIST); - for (list_each(node, &w->children)) { - list_append(&record->added_widgets, node->data); - } - ui_widget_add_mutation_record(w->parent, record); - ui_mutation_record_destroy(record); - } - children = &w->parent->children; - len = w->children.length; - if (len > 0) { - node = list_get_node(&w->children, 0); - ui_widget_remove_status(node->data, "first-child"); - node = list_get_last_node(&w->children); - ui_widget_remove_status(node->data, "last-child"); - } - node = &w->node; - target = node->prev; - node = w->children.tail.prev; - ev.cancel_bubble = true; - while (len > 0) { - assert(node != NULL); - assert(node->data != NULL); - prev = node->prev; - child = node->data; - ev.type = UI_EVENT_UNLINK; - ui_widget_emit_event(child, ev, NULL); - list_unlink(&w->children, node); - list_link(children, target, node); - child->parent = w->parent; - ev.type = UI_EVENT_LINK; - ui_widget_emit_event(child, ev, NULL); - ui_widget_request_refresh_children(child); - node = prev; - --len; - } - if (w->index == 0) { - ui_widget_add_status(target->next->data, "first-child"); - } - if (w->index == children->length - 1) { - node = list_get_last_node(children); - ui_widget_add_status(node->data, "last-child"); - } - ui_widget_remove(w); - return 0; + if (!w->parent) { + return -1; + } + if (ui_widget_has_observer(w, TYPE_CHILD_LIST)) { + record = ui_mutation_record_create(w, TYPE_CHILD_LIST); + for (list_each(node, &w->children)) { + list_append(&record->removed_widgets, node->data); + } + ui_widget_add_mutation_record(w, record); + ui_mutation_record_destroy(record); + } + if (ui_widget_has_observer(w->parent, TYPE_CHILD_LIST)) { + record = ui_mutation_record_create(w->parent, TYPE_CHILD_LIST); + for (list_each(node, &w->children)) { + list_append(&record->added_widgets, node->data); + } + ui_widget_add_mutation_record(w->parent, record); + ui_mutation_record_destroy(record); + } + children = &w->parent->children; + len = w->children.length; + if (len > 0) { + node = list_get_node(&w->children, 0); + ui_widget_remove_status(node->data, "first-child"); + node = list_get_last_node(&w->children); + ui_widget_remove_status(node->data, "last-child"); + } + node = &w->node; + target = node->prev; + node = w->children.tail.prev; + ev.cancel_bubble = true; + while (len > 0) { + assert(node != NULL); + assert(node->data != NULL); + prev = node->prev; + child = node->data; + ev.type = UI_EVENT_UNLINK; + ui_widget_emit_event(child, ev, NULL); + list_unlink(&w->children, node); + list_link(children, target, node); + child->parent = w->parent; + ev.type = UI_EVENT_LINK; + ui_widget_emit_event(child, ev, NULL); + ui_widget_request_refresh_children(child); + node = prev; + --len; + } + if (w->index == 0) { + ui_widget_add_status(target->next->data, "first-child"); + } + if (w->index == children->length - 1) { + node = list_get_last_node(children); + ui_widget_add_status(node->data, "last-child"); + } + ui_widget_remove(w); + return 0; } -int ui_widget_unlink(ui_widget_t* w) +int ui_widget_unlink(ui_widget_t *w) { - ui_widget_t* child; - ui_event_t ev = { 0 }; - ui_mutation_record_t* record; - list_node_t* node; + ui_widget_t *child; + ui_event_t ev = { 0 }; + ui_mutation_record_t *record; + list_node_t *node; - if (!w->parent) { - return -1; - } - node = &w->node; - if (w->index == w->parent->children.length - 1) { - ui_widget_remove_status(w, "last-child"); - child = ui_widget_prev(w); - if (child) { - ui_widget_add_status(child, "last-child"); - } - } - if (w->index == 0) { - ui_widget_remove_status(w, "first-child"); - child = ui_widget_next(w); - if (child) { - ui_widget_add_status(child, "first-child"); - } - } - /** 修改它后面的部件的 index 值 */ - node = node->next; - while (node) { - child = node->data; - child->index -= 1; - node = node->next; - } - node = &w->node; - ev.cancel_bubble = true; - ev.type = UI_EVENT_UNLINK; - ui_widget_emit_event(w, ev, NULL); - list_unlink(&w->parent->children, node); - list_unlink(&w->parent->stacking_context, &w->node_show); - ui_widget_request_reflow(w->parent); - if (ui_widget_has_observer(w->parent, TYPE_CHILD_LIST)) { - record = ui_mutation_record_create(w->parent, TYPE_CHILD_LIST); - list_append(&record->removed_widgets, w->parent); - ui_widget_add_mutation_record(w->parent, record); - ui_mutation_record_destroy(record); - } - w->parent = NULL; - return 0; + if (!w->parent) { + return -1; + } + node = &w->node; + if (w->index == w->parent->children.length - 1) { + ui_widget_remove_status(w, "last-child"); + child = ui_widget_prev(w); + if (child) { + ui_widget_add_status(child, "last-child"); + } + } + if (w->index == 0) { + ui_widget_remove_status(w, "first-child"); + child = ui_widget_next(w); + if (child) { + ui_widget_add_status(child, "first-child"); + } + } + /** 修改它后面的部件的 index 值 */ + node = node->next; + while (node) { + child = node->data; + child->index -= 1; + node = node->next; + } + node = &w->node; + ev.cancel_bubble = true; + ev.type = UI_EVENT_UNLINK; + ui_widget_emit_event(w, ev, NULL); + list_unlink(&w->parent->children, node); + list_unlink(&w->parent->stacking_context, &w->node_show); + ui_widget_request_reflow(w->parent); + if (ui_widget_has_observer(w->parent, TYPE_CHILD_LIST)) { + record = ui_mutation_record_create(w->parent, TYPE_CHILD_LIST); + list_append(&record->removed_widgets, w->parent); + ui_widget_add_mutation_record(w->parent, record); + ui_mutation_record_destroy(record); + } + w->parent = NULL; + return 0; } -void ui_widget_empty(ui_widget_t* w) +void ui_widget_empty(ui_widget_t *w) { - ui_widget_t* child; - list_node_t* node; - ui_event_t ev = { 0 }; - ui_mutation_record_t* record; + ui_widget_t *child; + list_node_t *node; + ui_event_t ev = { 0 }; + ui_mutation_record_t *record; - ui_event_init(&ev, "unlink"); - if (ui_widget_has_observer(w, TYPE_CHILD_LIST)) { - record = ui_mutation_record_create(w->parent, TYPE_CHILD_LIST); - for (list_each(node, &w->children)) { - list_append(&record->removed_widgets, node->data); - } - ui_widget_add_mutation_record(w, record); - ui_mutation_record_destroy(record); - } - while ((node = list_get_first_node(&w->children)) != NULL) { - child = node->data; - list_unlink(&w->children, node); - ui_widget_emit_event(child, ev, NULL); - ui_trash_add(child); - } - list_destroy_without_node(&w->stacking_context, NULL); - ui_widget_mark_dirty_rect(w, NULL, UI_BOX_TYPE_GRAPH_BOX); - ui_widget_request_refresh_style(w); + ui_event_init(&ev, "unlink"); + if (ui_widget_has_observer(w, TYPE_CHILD_LIST)) { + record = ui_mutation_record_create(w->parent, TYPE_CHILD_LIST); + for (list_each(node, &w->children)) { + list_append(&record->removed_widgets, node->data); + } + ui_widget_add_mutation_record(w, record); + ui_mutation_record_destroy(record); + } + while ((node = list_get_first_node(&w->children)) != NULL) { + child = node->data; + list_unlink(&w->children, node); + ui_widget_emit_event(child, ev, NULL); + ui_trash_add(child); + } + list_destroy_without_node(&w->stacking_context, NULL); + ui_widget_mark_dirty_rect(w, NULL, UI_BOX_TYPE_GRAPH_BOX); + ui_widget_request_refresh_style(w); } -void ui_widget_remove(ui_widget_t* w) +void ui_widget_remove(ui_widget_t *w) { - ui_widget_t* child; - list_node_t* node; + ui_widget_t *child; + list_node_t *node; - assert(w->state != UI_WIDGET_STATE_DELETED); - if (!w->parent) { - ui_trash_add(w); - return; - } - /* Update the index of the siblings behind it */ - node = w->node.next; - while (node) { - child = node->data; - child->index -= 1; - node = node->next; - } - if (w->computed_style.type_bits.position != CSS_POSITION_ABSOLUTE) { - ui_widget_request_reflow(w->parent); - } - ui_widget_mark_dirty_rect(w->parent, &w->canvas_box, - UI_BOX_TYPE_CONTENT_BOX); - ui_widget_unlink(w); - ui_trash_add(w); + assert(w->state != UI_WIDGET_STATE_DELETED); + if (!w->parent) { + ui_trash_add(w); + return; + } + /* Update the index of the siblings behind it */ + node = w->node.next; + while (node) { + child = node->data; + child->index -= 1; + node = node->next; + } + if (w->computed_style.type_bits.position != CSS_POSITION_ABSOLUTE) { + ui_widget_request_reflow(w->parent); + } + ui_widget_mark_dirty_rect(w->parent, &w->canvas_box, + UI_BOX_TYPE_CONTENT_BOX); + ui_widget_unlink(w); + ui_trash_add(w); } -ui_widget_t* ui_widget_prev(ui_widget_t* w) +ui_widget_t *ui_widget_prev(ui_widget_t *w) { - list_node_t* node = &w->node; - if (node->prev && node != w->parent->children.head.next) { - return node->prev->data; - } - return NULL; + list_node_t *node = &w->node; + if (node->prev && node != w->parent->children.head.next) { + return node->prev->data; + } + return NULL; } -ui_widget_t* ui_widget_next(ui_widget_t* w) +ui_widget_t *ui_widget_next(ui_widget_t *w) { - list_node_t* node = &w->node; - if (node->next) { - return node->next->data; - } - return NULL; + list_node_t *node = &w->node; + if (node->next) { + return node->next->data; + } + return NULL; } -ui_widget_t* ui_widget_get_child(ui_widget_t* w, size_t index) +ui_widget_t *ui_widget_get_child(ui_widget_t *w, size_t index) { - list_node_t* node = list_get_node(&w->children, index); - if (node) { - return node->data; - } - return NULL; + list_node_t *node = list_get_node(&w->children, index); + if (node) { + return node->data; + } + return NULL; } -size_t ui_widget_each(ui_widget_t* w, ui_widget_callback_t callback, void *arg) +size_t ui_widget_each(ui_widget_t *w, ui_widget_callback_t callback, void *arg) { - size_t count = 0; + size_t count = 0; - ui_widget_t* next; - ui_widget_t* child = list_get(&w->children, 0); + ui_widget_t *next; + ui_widget_t *child = list_get(&w->children, 0); - while (child && child != w) { - callback(child, arg); - ++count; - next = list_get(&child->children, 0); - while (!next && child != w) { - next = ui_widget_next(child); - child = child->parent; - } - child = next; - } - return count; + while (child && child != w) { + callback(child, arg); + ++count; + next = list_get(&child->children, 0); + while (!next && child != w) { + next = ui_widget_next(child); + child = child->parent; + } + child = next; + } + return count; } -ui_widget_t* ui_widget_at(ui_widget_t* widget, int ix, int iy) +ui_widget_t *ui_widget_at(ui_widget_t *widget, int ix, int iy) { - float x, y; - bool is_hit; - list_node_t* node; - ui_widget_t *target = widget, *c = NULL; + float x, y; + bool is_hit; + list_node_t *node; + ui_widget_t *target = widget, *c = NULL; - if (!widget) { - return NULL; - } - x = 1.0f * ix; - y = 1.0f * iy; - do { - is_hit = false; - for (list_each(node, &target->stacking_context)) { - c = node->data; - if (!ui_widget_is_visible(c)) { - continue; - } - if (ui_rect_has_point(&c->border_box, x, y)) { - target = c; - x -= c->padding_box.x; - y -= c->padding_box.y; - is_hit = true; - break; - } - } - } while (is_hit); - return target == widget ? NULL : target; + if (!widget) { + return NULL; + } + x = 1.0f * ix; + y = 1.0f * iy; + do { + is_hit = false; + for (list_each(node, &target->stacking_context)) { + c = node->data; + if (!ui_widget_is_visible(c)) { + continue; + } + if (ui_rect_has_point(&c->border_box, x, y)) { + target = c; + x -= c->padding_box.x; + y -= c->padding_box.y; + is_hit = true; + break; + } + } + } while (is_hit); + return target == widget ? NULL : target; } -static void _ui_print_tree(ui_widget_t* w, int depth, const char* prefix) +#include +#include + +static void _ui_print_tree(ui_widget_t *w, int depth, const wchar_t *prefix) { - size_t len; - ui_widget_t* child; - list_node_t* node; - css_selector_node_t* snode; - char str[16], child_prefix[512]; + ui_widget_t *child; + list_node_t *node; + css_selector_node_t *snode; + wchar_t str[16], child_prefix[512]; + size_t len; - len = strlen(prefix); - strcpy(child_prefix, prefix); - for (list_each(node, &w->children)) { - if (node == w->children.tail.prev) { - strcpy(str, "└"); - strcpy(&child_prefix[len], " "); - } else { - strcpy(str, "├"); - strcpy(&child_prefix[len], "│ "); - } - strcat(str, "─"); - child = node->data; - if (child->children.length == 0) { - strcat(str, "─"); - } else { - strcat(str, "┬"); - } - snode = ui_widget_create_selector_node(child); - logger_error( - "%s%s %s, xy:(%g,%g), size:(%g,%g), " - "visible: %s, display: %d, padding: (%g,%g,%g,%g), margin: " - "(%g,%g,%g,%g)\n", - prefix, str, snode->fullname, child->border_box.x, - child->border_box.y, child->border_box.width, - child->border_box.height, - ui_widget_is_visible(child) ? "true" : "false", - child->computed_style.type_bits.display, - child->computed_style.padding_top, - child->computed_style.padding_right, - child->computed_style.padding_bottom, - child->computed_style.padding_left, - child->computed_style.margin_top, - child->computed_style.margin_right, - child->computed_style.margin_bottom, - child->computed_style.margin_left); - css_selector_node_destroy(snode); - _ui_print_tree(child, depth + 1, child_prefix); - } + len = wcslen(prefix); + wcscpy(child_prefix, prefix); + for (list_each(node, &w->children)) { + if (node == w->children.tail.prev) { + wcscpy(str, L"\u2514"); + wcscpy(child_prefix + len, L" "); + } else { + wcscpy(str, L"\u251C"); + wcscpy(child_prefix + len, L"\u2502 "); + } + wcscat(str, L"\u2500\u2500"); + child = node->data; + if (child->children.length == 0) { + wcscat(str, L"\u2500\u2500"); + } else { + wcscat(str, L"\u252C\u2500"); + } + snode = ui_widget_create_selector_node(child); + logger_error( + "%ls%ls %s, xy:(%g,%g), size:(%g,%g), " + "visible: %s, display: %d, padding: (%g,%g,%g,%g), margin: " + "(%g,%g,%g,%g)\n", + prefix, str, snode->fullname, child->border_box.x, + child->border_box.y, child->border_box.width, + child->border_box.height, + ui_widget_is_visible(child) ? "true" : "false", + child->computed_style.type_bits.display, + child->computed_style.padding_top, + child->computed_style.padding_right, + child->computed_style.padding_bottom, + child->computed_style.padding_left, + child->computed_style.margin_top, + child->computed_style.margin_right, + child->computed_style.margin_bottom, + child->computed_style.margin_left); + css_selector_node_destroy(snode); + _ui_print_tree(child, depth + 1, child_prefix); + } } -void ui_print_tree(ui_widget_t* w) +void ui_print_tree(ui_widget_t *w) { - css_selector_node_t* node; - w = w ? w : ui_root(); - node = ui_widget_create_selector_node(w); - logger_error("%s, xy:(%g,%g), size:(%g,%g), visible: %s\n", - node->fullname, w->border_box.x, w->border_box.y, - w->border_box.width, w->border_box.height, - ui_widget_is_visible(w) ? "true" : "false"); - css_selector_node_destroy(node); - _ui_print_tree(w, 0, " "); + css_selector_node_t *node; + + w = w ? w : ui_root(); + node = ui_widget_create_selector_node(w); + logger_error("%s, xy:(%g,%g), size:(%g,%g), visible: %s\n", + node->fullname, w->border_box.x, w->border_box.y, + w->border_box.width, w->border_box.height, + ui_widget_is_visible(w) ? "true" : "false"); + css_selector_node_destroy(node); + _ui_print_tree(w, 0, L" "); } diff --git a/lib/ui/src/ui_updater.c b/lib/ui/src/ui_updater.c index f355d2998..e2accfc19 100644 --- a/lib/ui/src/ui_updater.c +++ b/lib/ui/src/ui_updater.c @@ -132,12 +132,10 @@ static void ui_widget_match_style(ui_widget_t* w) { css_selector_t* selector; css_style_decl_t* style; - const css_style_decl_t* matched_style; if (w->hash && w->update.should_refresh_style) { ui_widget_generate_self_hash(w); } - matched_style = w->matched_style; if (w->hash) { style = dict_fetch_value(ui_updater.style_cache, &w->hash); if (!style) { diff --git a/tests/cases/test_font_load.c b/tests/cases/test_font_load.c index 0492ce653..ffd2e7f16 100644 --- a/tests/cases/test_font_load.c +++ b/tests/cases/test_font_load.c @@ -36,10 +36,9 @@ void test_segoe_ui_font_load(void) ctest_equal_int( "load seguili.ttf", pd_font_library_load_file("C:/windows/fonts/seguili.ttf"), 0); - ctest_equal_bool( - "check get font (style: normal, weight: normal)", - id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_NORMAL), - TRUE); + id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_NORMAL); + ctest_equal_bool("check get font (style: normal, weight: normal)", + id > 0, true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -47,10 +46,9 @@ void test_segoe_ui_font_load(void) ctest_equal_int("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); } - ctest_equal_bool( - "check get font (style: italic, weight: normal)", - id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_NORMAL), - TRUE); + id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_NORMAL); + ctest_equal_bool("check get font (style: italic, weight: normal)", + id > 0, true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -58,10 +56,9 @@ void test_segoe_ui_font_load(void) ctest_equal_int("check font weight", font->weight, PD_FONT_WEIGHT_NORMAL); } - ctest_equal_bool( - "check get font (style: normal, weight: bold)", - id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BOLD), - TRUE); + id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BOLD); + ctest_equal_bool("check get font (style: normal, weight: bold)", id > 0, + true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -69,10 +66,9 @@ void test_segoe_ui_font_load(void) ctest_equal_int("check font weight", font->weight, PD_FONT_WEIGHT_BOLD); } - ctest_equal_bool( - "check get font (style: normal, weight: light)", - id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_LIGHT), - TRUE); + id = GetSegoeUIFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_LIGHT); + ctest_equal_bool("check get font (style: normal, weight: light)", + id > 0, true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -80,10 +76,9 @@ void test_segoe_ui_font_load(void) ctest_equal_int("check font weight", font->weight, PD_FONT_WEIGHT_LIGHT); } + id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_EXTRA_LIGHT); ctest_equal_bool("check get font (style: italic, weight: extra light)", - id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, - PD_FONT_WEIGHT_EXTRA_LIGHT), - TRUE); + id > 0, true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -115,7 +110,7 @@ void test_arial_font_load(void) ctest_equal_bool( "check get font (style: normal, weight: normal)", id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_NORMAL), - TRUE); + true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -126,7 +121,7 @@ void test_arial_font_load(void) ctest_equal_bool( "check get font (style: italic, weight: normal)", id = GetArialFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_NORMAL), - TRUE); + true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -136,7 +131,7 @@ void test_arial_font_load(void) } ctest_equal_bool( "check get font (style: normal, weight: bold)", - id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BOLD), TRUE); + id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BOLD), true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -147,7 +142,7 @@ void test_arial_font_load(void) ctest_equal_bool( "check get font (style: normal, weight: black)", id = GetArialFont(PD_FONT_STYLE_NORMAL, PD_FONT_WEIGHT_BLACK), - TRUE); + true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -158,7 +153,7 @@ void test_arial_font_load(void) ctest_equal_bool( "check get font (style: italic, weight: bold)", id = GetSegoeUIFont(PD_FONT_STYLE_ITALIC, PD_FONT_WEIGHT_BOLD), - TRUE); + true); if (id > 0) { font = pd_font_library_get_font(id); ctest_equal_int("check font style", font->style, @@ -186,6 +181,6 @@ void test_font_load(void) ui_load_css_file("test_font_load.css"), 0); ctest_equal_bool("check pd_font_library_get_font_id success", pd_font_library_get_font_id("icomoon", 0, 0) > 0, - TRUE); + true); ui_destroy(); }