Skip to content

Commit 853b96c

Browse files
committed
fixup! feat: support canceling tasks
1 parent 2148dc7 commit 853b96c

File tree

1 file changed

+30
-28
lines changed

1 file changed

+30
-28
lines changed

lib/ui-widgets/src/anchor.c

+30-28
Original file line numberDiff line numberDiff line change
@@ -19,27 +19,27 @@
1919

2020
typedef struct xml_loader_t {
2121
/** 键,作为在视图加载完后传给事件处理器的额外参数 */
22-
char* key;
23-
char* filepath; /**< 视图文件路径 */
24-
char* target_id; /**< 目标容器部件的标识 */
25-
ui_widget_t* pack; /**< 已经加载的视图内容包 */
26-
ui_widget_t* widget; /**< 触发视图加载器的部件 */
22+
char *key;
23+
char *filepath; /**< 视图文件路径 */
24+
char *target_id; /**< 目标容器部件的标识 */
25+
ui_widget_t *pack; /**< 已经加载的视图内容包 */
26+
ui_widget_t *widget; /**< 触发视图加载器的部件 */
2727
} xml_loader_t;
2828

2929
static struct ui_anchor_module_t {
30-
ui_widget_prototype_t* proto;
31-
worker_t * worker;
30+
ui_widget_prototype_t *proto;
31+
worker_t *worker;
3232
} ui_anchor;
3333

34-
static void xml_loader_on_widget_destroy(ui_widget_t* w, ui_event_t* e,
35-
void* arg)
34+
static void xml_loader_on_widget_destroy(ui_widget_t *w, ui_event_t *e,
35+
void *arg)
3636
{
37-
xml_loader_t* loader = e->data;
37+
xml_loader_t *loader = e->data;
3838

3939
loader->widget = NULL;
4040
}
4141

42-
static void xml_loader_destroy(xml_loader_t* loader)
42+
static void xml_loader_destroy(xml_loader_t *loader)
4343
{
4444
if (loader->widget) {
4545
ui_widget_off(loader->widget, "destroy",
@@ -56,10 +56,10 @@ static void xml_loader_destroy(xml_loader_t* loader)
5656
free(loader);
5757
}
5858

59-
static xml_loader_t* xml_loader_create(ui_widget_t* w)
59+
static xml_loader_t *xml_loader_create(ui_widget_t *w)
6060
{
61-
xml_loader_t* loader;
62-
const char* key = ui_widget_get_attr(w, "key");
61+
xml_loader_t *loader;
62+
const char *key = ui_widget_get_attr(w, "key");
6363

6464
loader = malloc(sizeof(xml_loader_t));
6565
if (!loader) {
@@ -77,9 +77,9 @@ static xml_loader_t* xml_loader_create(ui_widget_t* w)
7777
return loader;
7878
}
7979

80-
static void ui_anchor_on_load(ui_widget_t* w, ui_event_t* e, void* arg)
80+
static void ui_anchor_on_load(ui_widget_t *w, ui_event_t *e, void *arg)
8181
{
82-
xml_loader_t* loader = arg;
82+
xml_loader_t *loader = arg;
8383
ui_widget_t *target, *root;
8484
ui_event_t ev = { 0 };
8585

@@ -96,9 +96,9 @@ static void ui_anchor_on_load(ui_widget_t* w, ui_event_t* e, void* arg)
9696
ui_widget_emit_event(root, ev, loader->key);
9797
}
9898

99-
static void xml_loader_load(xml_loader_t* loader)
99+
static void xml_loader_load(xml_loader_t *loader)
100100
{
101-
ui_widget_t* pack;
101+
ui_widget_t *pack;
102102
ui_event_t e;
103103
char *path, dirname[] = "assets/views/";
104104

@@ -131,10 +131,10 @@ static void xml_loader_load(xml_loader_t* loader)
131131
(ui_event_arg_destructor_t)xml_loader_destroy);
132132
}
133133

134-
static void ui_anchor_on_startload(ui_widget_t* w, ui_event_t* e, void* arg)
134+
static void ui_anchor_on_startload(ui_widget_t *w, ui_event_t *e, void *arg)
135135
{
136-
ui_widget_t* target;
137-
xml_loader_t* loader = arg;
136+
ui_widget_t *target;
137+
xml_loader_t *loader = arg;
138138

139139
target = ui_get_widget(loader->target_id);
140140
if (!target) {
@@ -144,14 +144,15 @@ static void ui_anchor_on_startload(ui_widget_t* w, ui_event_t* e, void* arg)
144144
return;
145145
}
146146
ui_widget_empty(target);
147-
worker_post_task(ui_anchor.worker, loader, xml_loader_load, NULL);
147+
worker_post_task(ui_anchor.worker, loader,
148+
(worker_task_cb)xml_loader_load, NULL);
148149
}
149150

150-
void ui_anchor_open(ui_widget_t* w)
151+
void ui_anchor_open(ui_widget_t *w)
151152
{
152153
ui_event_t e;
153-
xml_loader_t* loader;
154-
const char* attr_href = ui_widget_get_attr(w, "href");
154+
xml_loader_t *loader;
155+
const char *attr_href = ui_widget_get_attr(w, "href");
155156

156157
if (!attr_href) {
157158
logger_error("[anchor] href are required\n");
@@ -176,12 +177,13 @@ void ui_anchor_open(ui_widget_t* w)
176177
ui_post_event(&e, loader, NULL);
177178
}
178179

179-
static void ui_anchor_on_click(ui_widget_t* w, ui_event_t* e, void* arg)
180+
static void ui_anchor_on_click(ui_widget_t *w, ui_event_t *e, void *arg)
180181
{
181-
worker_post_task(ui_anchor.worker, w, ui_anchor_open, NULL);
182+
worker_post_task(ui_anchor.worker, w, (worker_task_cb)ui_anchor_open,
183+
NULL);
182184
}
183185

184-
static void ui_anchor_on_init(ui_widget_t* w)
186+
static void ui_anchor_on_init(ui_widget_t *w)
185187
{
186188
ui_widget_on(w, "click", ui_anchor_on_click, NULL);
187189
ui_widget_on(w, "startload.anchor", ui_anchor_on_startload, NULL);

0 commit comments

Comments
 (0)