Set up uiBox sizing.
This commit is contained in:
parent
d3d62c849c
commit
4714bbacd5
|
@ -39,22 +39,24 @@ static void onDestroy(uiBox *b)
|
||||||
|
|
||||||
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width, intmax_t *height)
|
||||||
{
|
{
|
||||||
/* TODO
|
|
||||||
uiBox *b = uiBox(c);
|
uiBox *b = uiBox(c);
|
||||||
struct child *bc;
|
struct child *bc;
|
||||||
int xpadding, ypadding;
|
int xpadding, ypadding;
|
||||||
uintmax_t nStretchy;
|
uintmax_t nStretchy;
|
||||||
// these two contain the largest preferred width and height of all stretchy controls in the box
|
// these two contain the largest minimum width and height of all stretchy controls in the box
|
||||||
// all stretchy controls will use this value to determine the final preferred size
|
// all stretchy controls will use this value to determine the final minimum size
|
||||||
intmax_t maxStretchyWidth, maxStretchyHeight;
|
intmax_t maxStretchyWidth, maxStretchyHeight;
|
||||||
uintmax_t i;
|
uintmax_t i;
|
||||||
intmax_t preferredWidth, preferredHeight;
|
intmax_t minimumWidth, minimumHeight;
|
||||||
|
uiWindowsSizing *dself;
|
||||||
|
|
||||||
*width = 0;
|
*width = 0;
|
||||||
*height = 0;
|
*height = 0;
|
||||||
if (b->controls->len == 0)
|
if (b->controls->len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
dself = uiWindowsNewSizing(b->hwnd);
|
||||||
|
|
||||||
// 0) get this Box's padding
|
// 0) get this Box's padding
|
||||||
xpadding = 0;
|
xpadding = 0;
|
||||||
ypadding = 0;
|
ypadding = 0;
|
||||||
|
@ -77,26 +79,26 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width
|
||||||
maxStretchyHeight = 0;
|
maxStretchyHeight = 0;
|
||||||
for (i = 0; i < b->controls->len; i++) {
|
for (i = 0; i < b->controls->len; i++) {
|
||||||
bc = ptrArrayIndex(b->controls, struct child *, i);
|
bc = ptrArrayIndex(b->controls, struct child *, i);
|
||||||
if (!uiControlContainerVisible(bc->c))
|
//TODO if (!uiControlContainerVisible(bc->c))
|
||||||
continue;
|
//TODO continue;
|
||||||
uiControlPreferredSize(bc->c, d, &preferredWidth, &preferredHeight);
|
childMinimumSize(bc, dself, &minimumWidth, &minimumHeight);
|
||||||
if (bc->stretchy) {
|
if (ctrlStretchy(bc)) {
|
||||||
nStretchy++;
|
nStretchy++;
|
||||||
if (maxStretchyWidth < preferredWidth)
|
if (maxStretchyWidth < minimumWidth)
|
||||||
maxStretchyWidth = preferredWidth;
|
maxStretchyWidth = minimumWidth;
|
||||||
if (maxStretchyHeight < preferredHeight)
|
if (maxStretchyHeight < minimumHeight)
|
||||||
maxStretchyHeight = preferredHeight;
|
maxStretchyHeight = minimumHeight;
|
||||||
}
|
}
|
||||||
if (b->vertical) {
|
if (b->vertical) {
|
||||||
if (*width < preferredWidth)
|
if (*width < minimumWidth)
|
||||||
*width = preferredWidth;
|
*width = minimumWidth;
|
||||||
if (!bc->stretchy)
|
if (!ctrlStretchy(bc))
|
||||||
*height += preferredHeight;
|
*height += minimumHeight;
|
||||||
} else {
|
} else {
|
||||||
if (!bc->stretchy)
|
if (!ctrlStretchy(bc))
|
||||||
*width += preferredWidth;
|
*width += minimumWidth;
|
||||||
if (*height < preferredHeight)
|
if (*height < minimumHeight)
|
||||||
*height = preferredHeight;
|
*height = minimumHeight;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -105,26 +107,29 @@ static void minimumSize(uiWindowsControl *c, uiWindowsSizing *d, intmax_t *width
|
||||||
*height += nStretchy * maxStretchyHeight;
|
*height += nStretchy * maxStretchyHeight;
|
||||||
else
|
else
|
||||||
*width += nStretchy * maxStretchyWidth;
|
*width += nStretchy * maxStretchyWidth;
|
||||||
*/
|
|
||||||
|
uiWindowsFreeSizing(dself);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void boxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height)
|
static void boxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t width, intmax_t height)
|
||||||
{
|
{
|
||||||
/* TODO
|
uiBox *b = uiBox(c);
|
||||||
uibox *b = uiBox(c);
|
|
||||||
struct child *bc;
|
struct child *bc;
|
||||||
int xpadding, ypadding;
|
int xpadding, ypadding;
|
||||||
uintmax_t nStretchy;
|
uintmax_t nStretchy;
|
||||||
intmax_t stretchywid, stretchyht;
|
intmax_t stretchywid, stretchyht;
|
||||||
uintmax_t i;
|
uintmax_t i;
|
||||||
intmax_t preferredWidth, preferredHeight;
|
intmax_t minimumWidth, minimumHeight;
|
||||||
uiWindowsSizing *dchild;
|
uiWindowsSizing *d;
|
||||||
|
|
||||||
(*(b->baseResize))(uiControl(b), x, y, width, height, d);
|
printf("got here %d %d %d %d\n", (int)x, (int)y, (int)width, (int)height);
|
||||||
|
uiWindowsEnsureMoveWindow(b->hwnd, x, y, width, height);
|
||||||
|
|
||||||
if (b->controls->len == 0)
|
if (b->controls->len == 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
d = uiWindowsNewSizing(b->hwnd);
|
||||||
|
|
||||||
// -1) get this Box's padding
|
// -1) get this Box's padding
|
||||||
xpadding = 0;
|
xpadding = 0;
|
||||||
ypadding = 0;
|
ypadding = 0;
|
||||||
|
@ -147,21 +152,21 @@ static void boxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t wi
|
||||||
nStretchy = 0;
|
nStretchy = 0;
|
||||||
for (i = 0; i < b->controls->len; i++) {
|
for (i = 0; i < b->controls->len; i++) {
|
||||||
bc = ptrArrayIndex(b->controls, struct child *, i);
|
bc = ptrArrayIndex(b->controls, struct child *, i);
|
||||||
if (!uiControlContainerVisible(bc->c))
|
//TODO if (!uiControlContainerVisible(bc->c))
|
||||||
continue;
|
//TODO continue;
|
||||||
if (bc->stretchy) {
|
if (ctrlStretchy(bc)) {
|
||||||
nStretchy++;
|
nStretchy++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
uiControlPreferredSize(bc->c, d, &preferredWidth, &preferredHeight);
|
childMinimumSize(bc, d, &minimumWidth, &minimumHeight);
|
||||||
if (b->vertical) { // all controls have same width
|
if (b->vertical) { // all controls have same width
|
||||||
bc->width = width;
|
ctrlSetWidth(bc, width);
|
||||||
bc->height = preferredHeight;
|
ctrlSetHeight(bc, minimumHeight);
|
||||||
stretchyht -= preferredHeight;
|
stretchyht -= minimumHeight;
|
||||||
} else { // all controls have same height
|
} else { // all controls have same height
|
||||||
bc->width = preferredWidth;
|
ctrlSetWidth(bc, minimumWidth);
|
||||||
bc->height = height;
|
ctrlSetHeight(bc, height);
|
||||||
stretchywid -= preferredWidth;
|
stretchywid -= minimumWidth;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -173,28 +178,27 @@ static void boxRelayout(uiWindowsControl *c, intmax_t x, intmax_t y, intmax_t wi
|
||||||
stretchywid /= nStretchy;
|
stretchywid /= nStretchy;
|
||||||
for (i = 0; i < b->controls->len; i++) {
|
for (i = 0; i < b->controls->len; i++) {
|
||||||
bc = ptrArrayIndex(b->controls, struct child *, i);
|
bc = ptrArrayIndex(b->controls, struct child *, i);
|
||||||
if (!uiControlContainerVisible(bc->c))
|
//TODO if (!uiControlContainerVisible(bc->c))
|
||||||
continue;
|
//TODO continue;
|
||||||
if (bc->stretchy) {
|
if (ctrlStretchy(bc)) {
|
||||||
bc->width = stretchywid;
|
ctrlSetWidth(bc, stretchywid);
|
||||||
bc->height = stretchyht;
|
ctrlSetHeight(bc, stretchyht);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) now we can position controls
|
// 3) now we can position controls
|
||||||
dchild = uiControlSizing(uiControl(b));
|
|
||||||
for (i = 0; i < b->controls->len; i++) {
|
for (i = 0; i < b->controls->len; i++) {
|
||||||
bc = ptrArrayIndex(b->controls, struct child *, i);
|
bc = ptrArrayIndex(b->controls, struct child *, i);
|
||||||
if (!uiControlContainerVisible(bc->c))
|
//TODO if (!uiControlContainerVisible(bc->c))
|
||||||
continue;
|
//TODO continue;
|
||||||
uiControlResize(bc->c, x, y, bc->width, bc->height, dchild);
|
//TODO childRelayout(bc, x, y, ctrlWidth(bc), ctrlHeight(bc));
|
||||||
if (b->vertical)
|
if (b->vertical)
|
||||||
y += bc->height + ypadding;
|
y += ctrlHeight(bc) + ypadding;
|
||||||
else
|
else
|
||||||
x += bc->width + xpadding;
|
x += ctrlWidth(bc) + xpadding;
|
||||||
}
|
}
|
||||||
uiFreeSizing(dchild);
|
|
||||||
*/
|
uiWindowsFreeSizing(d);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* TODO
|
/* TODO
|
||||||
|
|
Loading…
Reference in New Issue