Skip to content

Commit

Permalink
feat(gui): add Widget_Each()
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Oct 7, 2019
1 parent 0ece333 commit 2d7d1ee
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/LCUI/gui/widget_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ LCUI_API LCUI_Widget Widget_GetNext(LCUI_Widget w);
/** 获取一个子部件 */
LCUI_API LCUI_Widget Widget_GetChild(LCUI_Widget w, size_t index);

/** Traverse the child widget tree */
LCUI_API size_t Widget_Each(LCUI_Widget w,
void (*callback)(LCUI_Widget, void *), void *arg);

/** 获取当前点命中的最上层可见部件 */
LCUI_API LCUI_Widget Widget_At(LCUI_Widget widget, int x, int y);

Expand Down
21 changes: 21 additions & 0 deletions src/gui/widget_tree.c
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,27 @@ void Widget_PrintTree(LCUI_Widget w)
_LCUIWidget_PrintTree(w, 0, " ");
}

size_t Widget_Each(LCUI_Widget w, void (*callback)(LCUI_Widget, void *),
void *arg)
{
size_t count = 0;

LCUI_Widget next;
LCUI_Widget child = LinkedList_Get(&w->children, 0);

while (child && child != w) {
callback(child, arg);
++count;
next = LinkedList_Get(&child->children, 0);
while (!next && child != w) {
next = Widget_GetNext(child);
child = child->parent;
}
child = next;
}
return count;
}

LCUI_Widget Widget_At(LCUI_Widget widget, int ix, int iy)
{
float x, y;
Expand Down

0 comments on commit 2d7d1ee

Please sign in to comment.