Skip to content

Commit 16002e0

Browse files
committed
fix(ui): the widgets created in the ready event handler aren't updated
1 parent 9e225e9 commit 16002e0

File tree

10 files changed

+43
-73
lines changed

10 files changed

+43
-73
lines changed

lib/ui-router/tests/test.c

+1
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,7 @@ void test_router_components(void)
619619

620620
ui_event_init(&e, "click");
621621
ui_widget_emit_event(link_foo, e, NULL);
622+
// ui_update();
622623
matched_widget = ui_router_view_get_matched_widget(view);
623624
ctest_equal_bool("[/foo] <router-view> widget should load <foo> widget",
624625
strcmp(matched_widget->type, "foo") == 0, TRUE);

lib/ui/include/ui/base.h

+7-3
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ LIBUI_PUBLIC void ui_widget_set_disabled(ui_widget_t *w, bool disabled);
7878

7979
// Tree
8080

81+
LIBUI_PUBLIC size_t ui_clear_trash(void);
8182
LIBUI_PUBLIC void ui_widget_remove(ui_widget_t *w);
8283
LIBUI_PUBLIC void ui_widget_empty(ui_widget_t *w);
8384
LIBUI_PUBLIC int ui_widget_append(ui_widget_t *parent, ui_widget_t *widget);
@@ -110,8 +111,7 @@ LIBUI_PUBLIC dict_t *ui_widget_collect_references(ui_widget_t *w);
110111
* 重置布局相关属性,以让它们在布局时被重新计算
111112
* @param rule 父级组件所使用的布局规则
112113
*/
113-
LIBUI_PUBLIC void ui_widget_reset_layout(ui_widget_t *w,
114-
ui_layout_rule_t rule);
114+
LIBUI_PUBLIC void ui_widget_reset_layout(ui_widget_t *w, ui_layout_rule_t rule);
115115

116116
LIBUI_PUBLIC void ui_widget_auto_reflow(ui_widget_t *w);
117117

@@ -128,7 +128,8 @@ LIBUI_PUBLIC size_t ui_widget_render(ui_widget_t *w, pd_context_t *paint);
128128
// Updater
129129

130130
LIBUI_PUBLIC size_t ui_widget_update(ui_widget_t *w);
131-
LIBUI_PUBLIC size_t ui_update(void);
131+
LIBUI_PUBLIC void ui_update(void);
132+
132133
LIBUI_PUBLIC void ui_refresh_style(void);
133134

134135
LIBUI_PUBLIC void ui_widget_set_rules(ui_widget_t *w,
@@ -150,6 +151,9 @@ LIBUI_INLINE void ui_widget_request_refresh_style(ui_widget_t *w)
150151

151152
LIBUI_INLINE void ui_widget_request_update_style(ui_widget_t *w)
152153
{
154+
if (!w->matched_style) {
155+
w->update.should_refresh_style = true;
156+
}
153157
w->update.should_update_style = true;
154158
ui_widget_request_update(w);
155159
}

lib/ui/src/ui.c

+1-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <pandagl.h>
1313
#include <ui/types.h>
1414
#include "ui/base.h"
15-
#include "ui_trash.h"
1615
#include "ui_root.h"
1716
#include "ui_events.h"
1817
#include "ui_image.h"
@@ -38,7 +37,7 @@ void ui_init(void)
3837
void ui_destroy(void)
3938
{
4039
pd_font_library_destroy();
41-
ui_trash_clear();
40+
ui_clear_trash();
4241
ui_destroy_root();
4342
ui_destroy_events();
4443
ui_destroy_image_loader();

lib/ui/src/ui_trash.c

-39
This file was deleted.

lib/ui/src/ui_trash.h

-13
This file was deleted.

lib/ui/src/ui_tree.c

+23-1
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,32 @@
1818
#include <ui/rect.h>
1919
#include <ui/mutation_observer.h>
2020
#include "ui_widget_observer.h"
21-
#include "ui_trash.h"
2221

2322
#define TYPE_CHILD_LIST UI_MUTATION_RECORD_TYPE_CHILD_LIST
2423

24+
static list_t ui_trash = { 0 };
25+
26+
size_t ui_clear_trash(void)
27+
{
28+
list_node_t *node = ui_trash.head.next;
29+
size_t count = ui_trash.length;
30+
31+
while (node) {
32+
list_node_t *next = node->next;
33+
list_unlink(&ui_trash, node);
34+
ui_widget_destroy(node->data);
35+
node = next;
36+
}
37+
return count;
38+
}
39+
40+
static void ui_trash_add(ui_widget_t *w)
41+
{
42+
w->state = UI_WIDGET_STATE_DELETED;
43+
w->parent = NULL;
44+
list_append_node(&ui_trash, &w->node);
45+
}
46+
2547
int ui_widget_append(ui_widget_t *parent, ui_widget_t *widget)
2648
{
2749
ui_event_t ev = { 0 };

lib/ui/src/ui_updater.c

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
#include <ui/metrics.h>
2020
#include <ui/mutation_observer.h>
2121
#include <ui/hash.h>
22+
#include <ui/image.h>
2223
#include "ui_debug.h"
2324
#include "ui_diff.h"
24-
#include "ui_trash.h"
2525
#include "ui_updater.h"
2626
#include "ui_mutation_observer.h"
2727
#include "ui_widget_style.h"
@@ -99,7 +99,7 @@ void ui_widget_set_rules(ui_widget_t* w, const ui_widget_rules_t* rules)
9999
w->extra->default_max_update_count = 2048;
100100
}
101101

102-
void ui_widget_update_stacking_context(ui_widget_t* w)
102+
static void ui_widget_update_stacking_context(ui_widget_t* w)
103103
{
104104
ui_widget_t *child, *target;
105105
css_computed_style_t *s, *ts;
@@ -470,23 +470,22 @@ static void ui_process_mutations(ui_widget_t* w)
470470
w->update.border_box_backup = w->border_box;
471471
}
472472

473-
size_t ui_update(void)
473+
void ui_update(void)
474474
{
475-
size_t count;
476-
ui_widget_t* root;
477-
478-
root = ui_root();
475+
ui_widget_t *root = ui_root();
479476
if (memcmp(&ui_metrics, &ui_updater.metrics, sizeof(ui_metrics_t))) {
480477
ui_updater.refresh_all = true;
481478
root->rendering.dirty_rect_type = UI_DIRTY_RECT_TYPE_FULL;
482479
}
483-
count = ui_widget_update(root);
480+
ui_process_image_events();
481+
ui_process_events();
482+
ui_widget_update(root);
484483
ui_updater.metrics = ui_metrics;
485484
ui_updater.refresh_all = false;
486485
ui_process_mutations(root);
487486
ui_process_mutation_observers();
488-
ui_trash_clear();
489-
return count;
487+
ui_process_events();
488+
ui_clear_trash();
490489
}
491490

492491
void ui_init_updater(void)

lib/ui/src/ui_widget.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ void ui_widget_add_state(ui_widget_t* w, ui_widget_state_t state)
113113
ui_event_t e = { 0 };
114114
e.type = UI_EVENT_READY;
115115
e.cancel_bubble = true;
116-
ui_widget_emit_event(w, e, NULL);
116+
ui_widget_post_event(w, &e, NULL, NULL);
117117
w->state = UI_WIDGET_STATE_NORMAL;
118118
}
119119
}

lib/ui/src/ui_widget_layout.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ void ui_widget_reflow(ui_widget_t *w)
103103
#endif
104104

105105
ui_widget_reflow_with_rule(w, rule);
106-
ui_widget_emit_event(w, ev, NULL);
106+
ui_widget_post_event(w, &ev, NULL, NULL);
107107
ui_widget_add_state(w, UI_WIDGET_STATE_LAYOUTED);
108108
#ifdef UI_DEBUG_ENABLED
109109
{

src/lcui_ui.c

-3
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ size_t lcui_render_ui(void)
160160

161161
void lcui_update_ui(void)
162162
{
163-
ui_process_image_events();
164-
ui_process_events();
165163
ui_update();
166-
167164
thread_mutex_lock(&lcui_ui.image_loader.mutex);
168165
ui_clear_images();
169166
thread_mutex_unlock(&lcui_ui.image_loader.mutex);

0 commit comments

Comments
 (0)