From 47584032c79cfb585e65a738c9e9b1903ea37081 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Mon, 9 Jan 2023 19:18:00 +0100 Subject: [PATCH] begin elment occlusion --- test/main.c | 2 +- ugui.c | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/test/main.c b/test/main.c index cf58627..aef02cf 100644 --- a/test/main.c +++ b/test/main.c @@ -202,7 +202,7 @@ int main(void) // ug_container_popup(ctx, "Annoying popup", (ug_div_t){.x=SIZE_MM(150), .y=SIZE_MM(150), .w=SIZE_PX(100), .h=SIZE_MM(75.0)}); - ug_container_body(ctx, "Main Body"); + //ug_container_body(ctx, "Main Body"); //if (ug_container_body(ctx, "Other Body")) // printf("No space!\n"); diff --git a/ugui.c b/ugui.c index ac139ef..eaaf7d8 100644 --- a/ugui.c +++ b/ugui.c @@ -1026,6 +1026,8 @@ int ug_frame_end(ug_ctx_t *ctx) draw_elements(ctx, c); // reset the layout to row c->flags &= ~(CNT_LAYOUT_COLUMN); + // reset used space + c->space = (ug_rect_t){0}; } ctx->input_text[0] = '\0'; @@ -1222,7 +1224,18 @@ static int position_element(ug_ctx_t *ctx, ug_container_t *cnt, ug_element_t *el rca->x = cx + rect->x; rca->y = cy + rect->y; -// printf("rca: x=%d, y=%d, w=%d, h=%d\n", rca->x, rca->y, rca->w, rca->h); + // if there is no space for the element + if (cnt->space.w + rca->w > cnt->rca.w || cnt->space.h + rca->h > cnt->rca.h) + return -1; + // or the element was put outside of the container + if (rca->x >= cnt->rca.x + cnt->rca.w || rca->y >= cnt->rca.y + cnt->rca.h) + return -1; + + // FIXME: crop element if it is partially outside, this shit introduces + // all sorts of resizing bugs + if (rca->x < cnt->rca.x + cnt->rca.w && rca->x + rca->w > cnt->rca.x + cnt->rca.w) + rca->w = rca->x + rca->w - (cnt->rca.x + cnt->rca.w); + if (TEST(cnt->flags, CNT_LAYOUT_COLUMN)) { cnt->c_orig.y += rca->h + m;