From e8c7a65f520f40803cf02459172151f7186d2cc6 Mon Sep 17 00:00:00 2001 From: Alessandro Mauri Date: Tue, 13 Dec 2022 11:59:44 +0100 Subject: [PATCH] add container margin the margin also counts for resizing allowing for small borders --- ugui.c | 80 +++++++++++++++++++++++++++++++++------------------------- ugui.h | 5 ++++ 2 files changed, 51 insertions(+), 34 deletions(-) diff --git a/ugui.c b/ugui.c index ac3a187..53f4e16 100644 --- a/ugui.c +++ b/ugui.c @@ -59,13 +59,14 @@ static const ug_style_t default_style = { }, .cnt = { .bg_color = RGB_FORMAT(0x0000ff), - .border.t = SIZE_PX(3), - .border.b = SIZE_PX(3), - .border.l = SIZE_PX(3), - .border.r = SIZE_PX(3), + .border.t = SIZE_PX(1), + .border.b = SIZE_PX(1), + .border.l = SIZE_PX(1), + .border.r = SIZE_PX(1), .border.color = RGB_FORMAT(0x00ff00), .titlebar.height = SIZE_PX(20), .titlebar.bg_color = RGB_FORMAT(0xbababa), + .margin = SIZE_PX(3), }, }; @@ -402,36 +403,47 @@ static int position_container(ug_ctx_t *ctx, ug_container_t *cnt) * Container style: * * rca - * v - * +-----------------------------------------------+ - * | Titlebar | - * +-----------------------------------------------+ - * |+---------------------------------------------+| - * ||\ ^ Border Top ^ || - * || \_ rect(0,0) || - * || || - * || || - * || || - * || || - * || || - * || || - * || || - * || < Border Left || - * || Border Right > || - * || || - * || || - * || || - * || || - * |+---------------------------------------------+| - * +-----------------------------------------------+ + * v v Border Top v + * +--------------------------------------------------------+ + * +--------------------------------------------------------+ + * | Titlebar | + * +--------------------------------------------------------+ + * |+------------------------------------------------------+| + * || .................................................... || + * || .\ ^ Border Top ^ . || + * || . \_ rect(0,0) . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . < Border Left . || + * || . + Margin Border Right >. || + * || . + Margin . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || . . || + * || .................................................... || + * |+------------------------------------------------------+| + * +--------------------------------------------------------+ * ^ Border Bottom ^ */ const ug_style_t *s = ctx->style_px; - int bl = s->cnt.border.l.size.i; - int br = s->cnt.border.r.size.i; - int bt = s->cnt.border.t.size.i; - int bb = s->cnt.border.b.size.i; + int bl = s->cnt.border.l.size.i + s->cnt.margin.size.i; + int br = s->cnt.border.r.size.i + s->cnt.margin.size.i; + int bt = s->cnt.border.t.size.i + s->cnt.margin.size.i; + int bb = s->cnt.border.b.size.i + s->cnt.margin.size.i; int hh = s->cnt.titlebar.height.size.i; int cx = ctx->origin.x; int cy = ctx->origin.y; @@ -496,10 +508,10 @@ static int handle_container(ug_ctx_t *ctx, ug_container_t *cnt) rca = &cnt->rca; const ug_style_t *s = ctx->style_px; - int bl = s->cnt.border.l.size.i; - int br = s->cnt.border.r.size.i; - int bt = s->cnt.border.t.size.i; - int bb = s->cnt.border.b.size.i; + int bl = s->cnt.border.l.size.i + s->cnt.margin.size.i; + int br = s->cnt.border.r.size.i + s->cnt.margin.size.i; + int bt = s->cnt.border.t.size.i + s->cnt.margin.size.i; + int bb = s->cnt.border.b.size.i + s->cnt.margin.size.i; int hh = s->cnt.titlebar.height.size.i; ug_vec2_t mpos = ctx->mouse.pos; diff --git a/ugui.h b/ugui.h index 81a62a9..8d0d152 100644 --- a/ugui.h +++ b/ugui.h @@ -74,6 +74,7 @@ typedef struct { ug_size_t t, b, l, r; ug_color_t color; } border; + ug_size_t margin; // titlebar only gets applied to movable containers struct { ug_size_t height; @@ -231,6 +232,10 @@ int ug_container_body(ug_ctx_t *ctx, const char *name); int ug_container_remove(ug_ctx_t *ctx, const char *name); +// layouts + + + // Input functions int ug_input_mousemove(ug_ctx_t *ctx, int x, int y); int ug_input_mousedown(ug_ctx_t *ctx, unsigned int mask);