From 8bc38452b3c5ed05771fc16a4cb51b2fb996b6a4 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Sat, 2 Nov 2024 09:44:53 +0100 Subject: [PATCH] renamed elem.rect to elem.bounds --- src/ugui_button.c3 | 4 ++-- src/ugui_data.c3 | 2 +- src/ugui_impl.c3 | 18 +++++++++--------- src/ugui_layout.c3 | 16 ++++++++-------- src/ugui_slider.c3 | 32 ++++++++++++++++---------------- 5 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/ugui_button.c3 b/src/ugui_button.c3 index 87f9d0f..d601813 100644 --- a/src/ugui_button.c3 +++ b/src/ugui_button.c3 @@ -18,7 +18,7 @@ fn ElemEvents! Ctx.button(&ctx, String label, Rect size) // if the element is new or the parent was updated then redo layout if (c_elem.flags.is_new || parent.flags.updated) { // 2. Layout - c_elem.rect = ctx.position_element(parent, size, true); + c_elem.bounds = ctx.position_element(parent, size, true); // TODO: 3. Fill the button specific fields } @@ -35,7 +35,7 @@ fn ElemEvents! Ctx.button(&ctx, String label, Rect size) Cmd cmd = { .type = CMD_RECT, .rect = { - .rect = c_elem.rect, + .rect = c_elem.bounds, .color = bg_color, }, }; diff --git a/src/ugui_data.c3 b/src/ugui_data.c3 index 7abf1e7..3d9d208 100644 --- a/src/ugui_data.c3 +++ b/src/ugui_data.c3 @@ -67,7 +67,7 @@ struct Elem { Id id; ElemFlags flags; ElemEvents events; - Rect rect; + Rect bounds; ElemType type; union { Div div; diff --git a/src/ugui_impl.c3 b/src/ugui_impl.c3 index da6e210..57da04f 100644 --- a/src/ugui_impl.c3 +++ b/src/ugui_impl.c3 @@ -74,9 +74,9 @@ fn void! Ctx.frame_begin(&ctx) if (c_elem.flags.is_new || c_elem.flags.updated) { Elem def_root = { - .id = ROOT_ID, - .type = ETYPE_DIV, - .rect = { + .id = ROOT_ID, + .type = ETYPE_DIV, + .bounds = { .w = ctx.width, .h = ctx.height, }, @@ -135,20 +135,20 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size) // do layout and update flags only if the element was updated if (c_elem.flags.is_new || parent.flags.updated) { // 2. layout the element - c_elem.rect = ctx.position_element(parent, size); + c_elem.bounds = ctx.position_element(parent, size); // 3. Mark the element as updated c_elem.flags.updated = true; // 4. Fill the div fields c_elem.div.layout = parent.div.layout; c_elem.div.origin_c = Point{ - .x = c_elem.rect.x, - .y = c_elem.rect.y, + .x = c_elem.bounds.x, + .y = c_elem.bounds.y, }; c_elem.div.color_bg = uint_to_rgba(0xff0000ff); c_elem.div.origin_r = c_elem.div.origin_c; } else if (parent.flags.has_focus) { - if (point_in_rect(ctx.input.mouse.pos, c_elem.rect)) { + if (point_in_rect(ctx.input.mouse.pos, c_elem.bounds)) { c_elem.flags.has_focus = true; } } else { @@ -161,7 +161,7 @@ fn void! Ctx.div_begin(&ctx, String label, Rect size) Cmd cmd = { .type = CMD_RECT, .rect = { - .rect = c_elem.rect, + .rect = c_elem.bounds, .color = c_elem.div.color_bg, }, }; @@ -179,5 +179,5 @@ fn void! Ctx.div_end(&ctx) **/ fn bool Ctx.is_hovered(&ctx, Elem *elem) { - return point_in_rect(ctx.input.mouse.pos, elem.rect); + return point_in_rect(ctx.input.mouse.pos, elem.bounds); } diff --git a/src/ugui_layout.c3 b/src/ugui_layout.c3 index 5c38c17..5b60602 100644 --- a/src/ugui_layout.c3 +++ b/src/ugui_layout.c3 @@ -51,7 +51,7 @@ fn void! Ctx.layout_next_row(&ctx) } parent.div.origin_r = Point{ - .x = parent.rect.x, + .x = parent.bounds.x, .y = parent.div.origin_c.y, }; parent.div.origin_c = parent.div.origin_r; @@ -69,7 +69,7 @@ fn void! Ctx.layout_next_column(&ctx) parent.div.origin_c = Point{ .x = parent.div.origin_r.x, - .y = parent.rect.y, + .y = parent.bounds.y, }; parent.div.origin_r = parent.div.origin_c; } @@ -98,8 +98,8 @@ fn Rect Ctx.position_element(&ctx, Elem *parent, Rect rect, bool style = false) // 3. Calculate width & height // TODO: what about negative values? // FIXME: account for origin offset!! - elem_rect.w = rect.w > 0 ? rect.w : parent.rect.w; - elem_rect.h = rect.h > 0 ? rect.h : parent.rect.h; + elem_rect.w = rect.w > 0 ? rect.w : parent.bounds.w; + elem_rect.h = rect.h > 0 ? rect.h : parent.bounds.h; // 4. Update the origins of the parent parent.div.origin_r = Point{ @@ -139,10 +139,10 @@ fn Rect Ctx.position_element(&ctx, Elem *parent, Rect rect, bool style = false) /* printf( "positioning rect: %lx {%d %d %d %d}(%d %d %d %d) . {%d %d %d - %d}\n", parent.id, rect.x, rect.y, rect.w, rect.h, parent.rect.x, - parent.rect.y, - parent.rect.w, - parent.rect.h, + %d}\n", parent.id, rect.x, rect.y, rect.w, rect.h, parent.bounds.x, + parent.bounds.y, + parent.bounds.w, + parent.bounds.h, elem_rect.x, elem_rect.y, elem_rect.w, diff --git a/src/ugui_slider.c3 b/src/ugui_slider.c3 index 7984b2e..c88e002 100644 --- a/src/ugui_slider.c3 +++ b/src/ugui_slider.c3 @@ -20,20 +20,20 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size) // if the element is new or the parent was updated then redo layout if (c_elem.flags.is_new || parent.flags.updated) { // 2. Layout - c_elem.rect = ctx.position_element(parent, size, true); + c_elem.bounds = ctx.position_element(parent, size, true); c_elem.slider.handle = Rect{ - .x = (short)(c_elem.rect.x + (int)(c_elem.rect.w * c_elem.slider.value)), - .y = c_elem.rect.y, - .w = (short)(c_elem.rect.w * 0.25), - .h = c_elem.rect.h, + .x = (short)(c_elem.bounds.x + (int)(c_elem.bounds.w * c_elem.slider.value)), + .y = c_elem.bounds.y, + .w = (short)(c_elem.bounds.w * 0.25), + .h = c_elem.bounds.h, }; } c_elem.events = ctx.get_elem_events(c_elem); if (parent.flags.has_focus && c_elem.events.mouse_hover) { if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) { - short x = (short)clamp(ctx.input.mouse.pos.x - c_elem.slider.handle.w/2, c_elem.rect.x, c_elem.rect.x + c_elem.rect.w - c_elem.slider.handle.w); - float v = (float)(c_elem.slider.handle.x-c_elem.rect.x) / (float)(c_elem.rect.w-c_elem.slider.handle.w); + short x = (short)clamp(ctx.input.mouse.pos.x - c_elem.slider.handle.w/2, c_elem.bounds.x, c_elem.bounds.x + c_elem.bounds.w - c_elem.slider.handle.w); + float v = (float)(c_elem.slider.handle.x-c_elem.bounds.x) / (float)(c_elem.bounds.w-c_elem.slider.handle.w); c_elem.slider.handle.x = x; c_elem.slider.value = v; c_elem.events.update = true; @@ -47,7 +47,7 @@ fn ElemEvents! Ctx.slider_hor(&ctx, String label, Rect size) Cmd cmd = { .type = CMD_RECT, .rect = { - .rect = c_elem.rect, + .rect = c_elem.bounds, .color = bg_color, }, }; @@ -92,20 +92,20 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size) // if the element is new or the parent was updated then redo layout if (c_elem.flags.is_new || parent.flags.updated) { // 2. Layout - c_elem.rect = ctx.position_element(parent, size, true); + c_elem.bounds = ctx.position_element(parent, size, true); c_elem.slider.handle = Rect{ - .x = c_elem.rect.x, - .y = (short)(c_elem.rect.y + (int)(c_elem.rect.h * c_elem.slider.value)), - .w = c_elem.rect.w, - .h = (short)(c_elem.rect.h * 0.25), + .x = c_elem.bounds.x, + .y = (short)(c_elem.bounds.y + (int)(c_elem.bounds.h * c_elem.slider.value)), + .w = c_elem.bounds.w, + .h = (short)(c_elem.bounds.h * 0.25), }; } c_elem.events = ctx.get_elem_events(c_elem); if (parent.flags.has_focus && c_elem.events.mouse_hover) { if (point_in_rect(ctx.input.mouse.pos, c_elem.slider.handle) && c_elem.events.mouse_hold) { - short y = (short)clamp(ctx.input.mouse.pos.y - c_elem.slider.handle.h/2, c_elem.rect.y, c_elem.rect.y + c_elem.rect.h - c_elem.slider.handle.h); - float v = (float)(c_elem.slider.handle.y-c_elem.rect.y) / (float)(c_elem.rect.h-c_elem.slider.handle.h); + short y = (short)clamp(ctx.input.mouse.pos.y - c_elem.slider.handle.h/2, c_elem.bounds.y, c_elem.bounds.y + c_elem.bounds.h - c_elem.slider.handle.h); + float v = (float)(c_elem.slider.handle.y-c_elem.bounds.y) / (float)(c_elem.bounds.h-c_elem.slider.handle.h); c_elem.slider.handle.y = y; c_elem.slider.value = v; c_elem.events.update = true; @@ -119,7 +119,7 @@ fn ElemEvents! Ctx.slider_ver(&ctx, String label, Rect size) Cmd cmd = { .type = CMD_RECT, .rect = { - .rect = c_elem.rect, + .rect = c_elem.bounds, .color = bg_color, }, };