fix prop and add MwNfixedSize

This commit is contained in:
NishiOwO
2025-12-15 14:30:59 +09:00
parent 1a95ddce94
commit a1ce1b56e4
4 changed files with 35 additions and 13 deletions

View File

@@ -16,11 +16,11 @@ void resize(MwWidget handle, void* user, void* client) {
} }
int main() { int main() {
MwWidget box2, box3; MwWidget box2, box3, box4;
MwLibraryInit(); MwLibraryInit();
window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 200, 200, window = MwVaCreateWidget(MwWindowClass, "main", NULL, MwDEFAULT, MwDEFAULT, 600, 200,
MwNtitle, "box", MwNtitle, "box",
NULL); NULL);
@@ -38,13 +38,19 @@ int main() {
MwNorientation, MwVERTICAL, MwNorientation, MwVERTICAL,
NULL); 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, MwVaCreateWidget(MwButtonClass, "btn1", box2, 0, 0, 0, 0,
MwNbackground, "#a00", MwNbackground, "#a00",
NULL); NULL);
MwVaCreateWidget(MwButtonClass, "btn2", box2, 0, 0, 0, 0, MwVaCreateWidget(MwButtonClass, "btn2", box2, 0, 0, 0, 0,
MwNbackground, "#0a0", MwNbackground, "#0a0",
MwNboxRatio, 2, MwNratio, 2,
NULL); NULL);
MwVaCreateWidget(MwButtonClass, "btn3", box2, 0, 0, 0, 0, MwVaCreateWidget(MwButtonClass, "btn3", box2, 0, 0, 0, 0,
@@ -52,7 +58,11 @@ int main() {
NULL); NULL);
MwVaCreateWidget(MwButtonClass, "btn4", box3, 0, 0, 0, 0, MwVaCreateWidget(MwButtonClass, "btn4", box3, 0, 0, 0, 0,
MwNbackground, "#00a", MwNbackground, "#a0a",
NULL);
MwVaCreateWidget(MwButtonClass, "btn5", box4, 0, 0, 0, 0,
MwNbackground, "#0aa",
NULL); NULL);
MwAddUserHandler(window, MwNresizeHandler, resize, NULL); MwAddUserHandler(window, MwNresizeHandler, resize, NULL);

View File

@@ -32,7 +32,8 @@
#define MwNpadding "Ipadding" #define MwNpadding "Ipadding"
#define MwNborderWidth "IborderWidth" #define MwNborderWidth "IborderWidth"
#define MwNfillArea "IfillArea" #define MwNfillArea "IfillArea"
#define MwNboxRatio "IboxRatio" #define MwNratio "Iratio"
#define MwNfixedSize "IfixedSize"
#define MwNtitle "Stitle" #define MwNtitle "Stitle"
#define MwNtext "Stext" #define MwNtext "Stext"

View File

@@ -49,7 +49,8 @@
- MwNheight - MwNheight
- MwNborderWidth - MwNborderWidth
- MwNbackgroundPixmap - MwNbackgroundPixmap
- MwNboxRatio - MwNratio
- MwNfixedSize
Integer properties must be prefixed with I. Integer properties must be prefixed with I.
String properties must be prefixed with S. String properties must be prefixed with S.
@@ -83,7 +84,8 @@
<integer name="showArrows" /> <integer name="showArrows" />
<integer name="padding" /> <integer name="padding" />
<integer name="borderWidth" /> <integer name="borderWidth" />
<integer name="boxRatio" /> <integer name="ratio" />
<integer name="fixedSize" />
<string name="title" /> <string name="title" />
<string name="text" /> <string name="text" />

View File

@@ -31,21 +31,30 @@ static void layout(MwWidget handle) {
int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - MwGetInteger(handle, MwNpadding); int sz = MwGetInteger(handle, horiz ? MwNwidth : MwNheight) - MwGetInteger(handle, MwNpadding);
int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - MwGetInteger(handle, MwNpadding) * 2; int fsz = MwGetInteger(handle, horiz ? MwNheight : MwNwidth) - MwGetInteger(handle, MwNpadding) * 2;
int sk = 0; int sk = 0;
if(arrlen(handle->children) == 0) return;
for(i = 0; i < arrlen(handle->children); i++) { 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; 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++) { 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; int wsz;
if(n == MwDEFAULT) n = 1; 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); sk += MwGetInteger(handle, MwNpadding);
MwVaApply(handle->children[i], 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) { static void children_prop_change(MwWidget handle, MwWidget child, const char* key) {
(void)child; (void)child;
if(strcmp(key, MwNboxRatio) == 0) layout(handle); if(strcmp(key, MwNratio) == 0) layout(handle);
} }
static void resize(MwWidget handle) { static void resize(MwWidget handle) {