Skip to content

Commit 7712b09

Browse files
committed
feat(gui): add Widget_CollectReferences()
1 parent 826695e commit 7712b09

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

include/LCUI/gui/widget_helper.h

+3
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,9 @@ LCUI_API void Widget_SetOpacity(LCUI_Widget w, float opacity);
9393

9494
LCUI_API void Widget_SetBoxSizing(LCUI_Widget w, LCUI_StyleValue sizing);
9595

96+
/** Collect all child widget that have a ref attribute specified */
97+
LCUI_API Dict *Widget_CollectReferences(LCUI_Widget w);
98+
9699
/**
97100
* Get the first widget that match the type by testing the widget itself and
98101
* traversing up through its ancestors.

src/gui/widget_helper.c

+18
Original file line numberDiff line numberDiff line change
@@ -244,3 +244,21 @@ LCUI_Widget Widget_GetClosest(LCUI_Widget w, const char *type)
244244
}
245245
return NULL;
246246
}
247+
248+
static void Widget_CollectReference(LCUI_Widget w, void *arg)
249+
{
250+
const char *ref = Widget_GetAttribute(w, "ref");
251+
252+
if (ref) {
253+
Dict_Add(arg, (void*)ref, w);
254+
}
255+
}
256+
257+
Dict *Widget_CollectReferences(LCUI_Widget w)
258+
{
259+
Dict *dict;
260+
261+
dict = Dict_Create(&DictType_StringKey, NULL);
262+
Widget_Each(w, Widget_CollectReference, dict);
263+
return dict;
264+
}

0 commit comments

Comments
 (0)