Skip to content

Commit

Permalink
feat(gui): add rule for limit the number of children rendered
Browse files Browse the repository at this point in the history
  • Loading branch information
lc-soft committed Mar 4, 2019
1 parent 50cc6b2 commit ec5e0d6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
3 changes: 3 additions & 0 deletions include/LCUI/gui/widget_base.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,9 @@ typedef struct LCUI_WidgetRulesRec_ {
*/
int max_update_children_count;

/** Limit the number of children rendered */
unsigned max_render_children_count;

/** A callback function on update progress */
void (*on_update_progress)(LCUI_Widget, size_t);
} LCUI_WidgetRulesRec, *LCUI_WidgetRules;
Expand Down
15 changes: 12 additions & 3 deletions src/gui/widget_paint.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ static void Widget_ComputeActualContentBox(LCUI_Widget w,

static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
{
size_t count = 0;
size_t total = 0, count = 0;
LCUI_Widget child;
LCUI_Rect paint_rect;
LinkedListNode *node;
Expand All @@ -476,6 +476,11 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
child->state != LCUI_WSTATE_NORMAL) {
continue;
}
if (that->target->rules &&
that->target->rules->max_render_children_count &&
count > that->target->rules->max_render_children_count) {
break;
}
style.x = that->x + that->content_left;
style.y = that->y + that->content_top;
Widget_ComputeActualBorderBox(child, &style);
Expand All @@ -490,8 +495,12 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
style.canvas_box.width, style.canvas_box.height);
if (!LCUIRect_GetOverlayRect(&that->content_rect,
&style.canvas_box, &paint_rect)) {
if (count > 0) {
++count;
}
continue;
}
++count;
Widget_ComputeActualPaddingBox(child, &style);
Widget_ComputeActualContentBox(child, &style);
if (that->has_content_graph) {
Expand All @@ -515,10 +524,10 @@ static size_t WidgetRenderer_RenderChildren(LCUI_WidgetRenderer that)
Graph_Quote(&paint.canvas, &that->root_paint->canvas,
&paint_rect);
renderer = WidgetRenderer(child, &paint, &style, that);
count += WidgetRenderer_Render(renderer);
total += WidgetRenderer_Render(renderer);
WidgetRenderer_Delete(renderer);
}
return count;
return total;
}

static size_t WidgetRenderer_RenderContent(LCUI_WidgetRenderer that)
Expand Down

0 comments on commit ec5e0d6

Please sign in to comment.