diff --git a/examples/basic/box.c b/examples/basic/box.c index 517a540..0c138a0 100644 --- a/examples/basic/box.c +++ b/examples/basic/box.c @@ -16,11 +16,11 @@ void resize(MwWidget handle, void* user, void* client) { } int main() { - MwWidget box2, box3; + MwWidget box2, box3, box4; MwLibraryInit(); - window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 200, 200, + window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 600, 200, MwNtitle, "box", NULL); @@ -38,13 +38,19 @@ int main() { MwNorientation, MwVERTICAL, NULL); + box4 = MwVaCreateWidget(MwBoxClass, "box4", box, 0, 0, 0, 0, + MwNpadding, 10, + MwNorientation, MwVERTICAL, + MwNfixedSize, 40, + NULL); + MwVaCreateWidget(MwButtonClass, "btn1", box2, 0, 0, 0, 0, MwNbackground, "#a00", NULL); MwVaCreateWidget(MwButtonClass, "btn2", box2, 0, 0, 0, 0, MwNbackground, "#0a0", - MwNboxRatio, 2, + MwNratio, 2, NULL); MwVaCreateWidget(MwButtonClass, "btn3", box2, 0, 0, 0, 0, @@ -52,7 +58,11 @@ int main() { NULL); MwVaCreateWidget(MwButtonClass, "btn4", box3, 0, 0, 0, 0, - MwNbackground, "#00a", + MwNbackground, "#a0a", + NULL); + + MwVaCreateWidget(MwButtonClass, "btn5", box4, 0, 0, 0, 0, + MwNbackground, "#0aa", NULL); MwAddUserHandler(window, MwNresizeHandler, resize, NULL); diff --git a/include/Mw/StringDefs.h b/include/Mw/StringDefs.h index 238c0ba..a4e999d 100644 --- a/include/Mw/StringDefs.h +++ b/include/Mw/StringDefs.h @@ -32,7 +32,8 @@ #define MwNpadding "Ipadding" #define MwNborderWidth "IborderWidth" #define MwNfillArea "IfillArea" -#define MwNboxRatio "IboxRatio" +#define MwNratio "Iratio" +#define MwNfixedSize "IfixedSize" #define MwNtitle "Stitle" #define MwNtext "Stext" diff --git a/milsko.xml b/milsko.xml index faf0405..83ef0e3 100644 --- a/milsko.xml +++ b/milsko.xml @@ -49,7 +49,8 @@ - MwNheight - MwNborderWidth - MwNbackgroundPixmap - - MwNboxRatio + - MwNratio + - MwNfixedSize Integer properties must be prefixed with I. String properties must be prefixed with S. @@ -83,7 +84,8 @@ - + + diff --git a/src/widget/box.c b/src/widget/box.c index 31b0a07..777c32e 100644 --- a/src/widget/box.c +++ b/src/widget/box.c @@ -31,21 +31,30 @@ static void layout(MwWidget handle) { int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - MwGetInteger(handle, MwNpadding); int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - MwGetInteger(handle, MwNpadding) * 2; int sk = 0; - if(arrlen(handle->children) == 0) return; for(i = 0; i < arrlen(handle->children); i++) { - int n = MwGetInteger(handle->children[i], MwNboxRatio); + int n = MwGetInteger(handle->children[i], MwNratio); + int s = MwGetInteger(handle->children[i], MwNfixedSize); if(n == MwDEFAULT) n = 1; - sum += n; + if(s != MwDEFAULT) { + sz -= s + MwGetInteger(handle, MwNpadding); + } else { + sum += n; + } } for(i = 0; i < arrlen(handle->children); i++) { - int n = MwGetInteger(handle->children[i], MwNboxRatio); + int n = MwGetInteger(handle->children[i], MwNratio); + int s = MwGetInteger(handle->children[i], MwNfixedSize); int wsz; if(n == MwDEFAULT) n = 1; - wsz = sz * n / sum - MwGetInteger(handle, MwNpadding); + if(s != MwDEFAULT) { + wsz = s; + } else { + wsz = sz * n / sum - MwGetInteger(handle, MwNpadding); + } sk += MwGetInteger(handle, MwNpadding); MwVaApply(handle->children[i], @@ -65,7 +74,7 @@ static void prop_change(MwWidget handle, const char* key) { static void children_prop_change(MwWidget handle, MwWidget child, const char* key) { (void)child; - if(strcmp(key, MwNboxRatio) == 0) layout(handle); + if(strcmp(key, MwNratio) == 0) layout(handle); } static void resize(MwWidget handle) {