mirror of
https://gitea.nishi.boats/pyrite-dev/milsko
synced 2025-12-31 06:30:52 +00:00
fix prop and add MwNfixedSize
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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 @@
|
||||
<integer name="showArrows" />
|
||||
<integer name="padding" />
|
||||
<integer name="borderWidth" />
|
||||
<integer name="boxRatio" />
|
||||
<integer name="ratio" />
|
||||
<integer name="fixedSize" />
|
||||
|
||||
<string name="title" />
|
||||
<string name="text" />
|
||||
|
||||
@@ -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;
|
||||
|
||||
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;
|
||||
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user