diff --git a/include/Mw/TypeDefs.h b/include/Mw/TypeDefs.h index 7d2ae72..1f82cb2 100644 --- a/include/Mw/TypeDefs.h +++ b/include/Mw/TypeDefs.h @@ -27,6 +27,7 @@ typedef struct _MwListBoxEntry MwListBoxEntry; typedef struct _MwTreeViewEntry MwTreeViewEntry; typedef struct _MwDirectoryEntry MwDirectoryEntry; typedef struct _MwListBoxPacket MwListBoxPacket; +typedef struct _MwBox* MwBox; #ifdef _MILSKO typedef struct _MwWidget* MwWidget; #else @@ -200,6 +201,10 @@ struct _MwListBoxPacket { char*** names; }; +struct _MwBox { + int layout; +}; + struct _MwClass { MwHandlerWithStatus create; MwHandler destroy; diff --git a/src/widget/box.c b/src/widget/box.c index d8d4745..4d88f73 100644 --- a/src/widget/box.c +++ b/src/widget/box.c @@ -3,6 +3,11 @@ #include "../../external/stb_ds.h" static int create(MwWidget handle) { + MwBox b = malloc(sizeof(*b)); + memset(b, 0, sizeof(*b)); + + handle->internal = b; + MwSetDefault(handle); MwSetInteger(handle, MwNorientation, MwHORIZONTAL); @@ -11,25 +16,14 @@ static int create(MwWidget handle) { MwSetInteger(handle, MwNhasBorder, 0); MwSetInteger(handle, MwNinverted, 1); + b->layout = 0; + return 0; } -static void draw(MwWidget handle) { - MwRect r; - MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); - - r.x = 0; - r.y = 0; - r.width = MwGetInteger(handle, MwNwidth); - r.height = MwGetInteger(handle, MwNheight); - - if(MwGetInteger(handle, MwNhasBorder)) { - MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted), 0); - } - - MwDrawRect(handle, &r, base); - - MwLLFreeColor(base); +static void destroy(MwWidget handle){ + MwBox b = handle->internal; + free(b); } #define Margin ((i != (arrlen(handle->children) - 1)) ? MwGetInteger(handle, MwNmargin) : 0) @@ -81,27 +75,68 @@ static void layout(MwWidget handle) { } } +static void draw(MwWidget handle) { + MwRect r; + MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground)); + MwBox b = handle->internal; + + r.x = 0; + r.y = 0; + r.width = MwGetInteger(handle, MwNwidth); + r.height = MwGetInteger(handle, MwNheight); + + if(MwGetInteger(handle, MwNhasBorder)) { + MwDrawFrame(handle, &r, base, MwGetInteger(handle, MwNinverted), 0); + } + + MwDrawRect(handle, &r, base); + + MwLLFreeColor(base); + + if(b->layout){ + layout(handle); + + b->layout = 0; + } +} + static void prop_change(MwWidget handle, const char* key) { - if(strcmp(key, MwNorientation) == 0) layout(handle); + if(strcmp(key, MwNorientation) == 0){ + MwBox b = handle->internal; + b->layout = 1; + + MwForceRender(handle); + } } static void children_prop_change(MwWidget handle, MwWidget child, const char* key) { (void)child; - if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0) layout(handle); + if(strcmp(key, MwNratio) == 0 || strcmp(key, MwNfixedSize) == 0){ + MwBox b = handle->internal; + b->layout = 1; + + MwForceRender(handle); + } } static void resize(MwWidget handle) { - layout(handle); + MwBox b = handle->internal; + b->layout = 1; + + MwForceRender(handle); } static void children_update(MwWidget handle) { - layout(handle); + MwBox b = handle->internal; + b->layout = 1; + + MwForceRender(handle); } MwClassRec MwBoxClassRec = { create, /* create */ - NULL, /* destroy */ + destroy, /* destroy */ draw, /* draw */ NULL, /* click */ NULL, /* parent_resize */