Implemented hidden controls properly on Windows uiForm.
This commit is contained in:
parent
b6cb429d1a
commit
8ae0823eee
|
@ -43,6 +43,7 @@ static void formRelayout(uiForm *f)
|
||||||
int minimumWidth, minimumHeight;
|
int minimumWidth, minimumHeight;
|
||||||
uiWindowsSizing sizing;
|
uiWindowsSizing sizing;
|
||||||
int labelht, labelyoff;
|
int labelht, labelyoff;
|
||||||
|
int nVisible;
|
||||||
|
|
||||||
if (f->controls->size() == 0)
|
if (f->controls->size() == 0)
|
||||||
return;
|
return;
|
||||||
|
@ -53,22 +54,22 @@ static void formRelayout(uiForm *f)
|
||||||
width = r.right - r.left;
|
width = r.right - r.left;
|
||||||
height = r.bottom - r.top;
|
height = r.bottom - r.top;
|
||||||
|
|
||||||
// -1) get this Form's padding
|
// 0) get this Form's padding
|
||||||
formPadding(f, &xpadding, &ypadding);
|
formPadding(f, &xpadding, &ypadding);
|
||||||
|
|
||||||
// 0) inset the available rect by the needed padding
|
|
||||||
// TODO this is incorrect if any controls are hidden
|
|
||||||
width -= xpadding;
|
|
||||||
height -= (f->controls->size() - 1) * ypadding;
|
|
||||||
|
|
||||||
// 1) get width of labels and height of non-stretchy controls
|
// 1) get width of labels and height of non-stretchy controls
|
||||||
// this will tell us how much space will be left for controls
|
// this will tell us how much space will be left for controls
|
||||||
labelwid = 0;
|
labelwid = 0;
|
||||||
stretchyht = height;
|
stretchyht = height;
|
||||||
nStretchy = 0;
|
nStretchy = 0;
|
||||||
|
nVisible = 0;
|
||||||
for (struct formChild &fc : *(f->controls)) {
|
for (struct formChild &fc : *(f->controls)) {
|
||||||
if (!uiControlVisible(fc.c))
|
if (!uiControlVisible(fc.c)) {
|
||||||
|
ShowWindow(fc.label, SW_HIDE);
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
ShowWindow(fc.label, SW_SHOW);
|
||||||
|
nVisible++;
|
||||||
thiswid = uiWindowsWindowTextWidth(fc.label);
|
thiswid = uiWindowsWindowTextWidth(fc.label);
|
||||||
if (labelwid < thiswid)
|
if (labelwid < thiswid)
|
||||||
labelwid = thiswid;
|
labelwid = thiswid;
|
||||||
|
@ -80,8 +81,15 @@ static void formRelayout(uiForm *f)
|
||||||
fc.height = minimumHeight;
|
fc.height = minimumHeight;
|
||||||
stretchyht -= minimumHeight;
|
stretchyht -= minimumHeight;
|
||||||
}
|
}
|
||||||
|
if (nVisible == 0) // nothing to do
|
||||||
|
return;
|
||||||
|
|
||||||
// 2) now get the width of controls and the height of stretchy controls
|
// 2) inset the available rect by the needed padding
|
||||||
|
width -= xpadding;
|
||||||
|
height -= (nVisible - 1) * ypadding;
|
||||||
|
stretchyht -= (nVisible - 1) * ypadding;
|
||||||
|
|
||||||
|
// 3) now get the width of controls and the height of stretchy controls
|
||||||
width -= labelwid;
|
width -= labelwid;
|
||||||
if (nStretchy != 0) {
|
if (nStretchy != 0) {
|
||||||
stretchyht /= nStretchy;
|
stretchyht /= nStretchy;
|
||||||
|
@ -93,12 +101,12 @@ static void formRelayout(uiForm *f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 3) get the y offset
|
// 4) get the y offset
|
||||||
labelyoff = labelYOffset;
|
labelyoff = labelYOffset;
|
||||||
uiWindowsGetSizing(f->hwnd, &sizing);
|
uiWindowsGetSizing(f->hwnd, &sizing);
|
||||||
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &labelyoff);
|
uiWindowsSizingDlgUnitsToPixels(&sizing, NULL, &labelyoff);
|
||||||
|
|
||||||
// 4) now we can position controls
|
// 5) now we can position controls
|
||||||
// first, make relative to the top-left corner of the container
|
// first, make relative to the top-left corner of the container
|
||||||
// also prefer left alignment on Windows
|
// also prefer left alignment on Windows
|
||||||
x = labelwid + xpadding;
|
x = labelwid + xpadding;
|
||||||
|
@ -164,6 +172,7 @@ static void uiFormMinimumSize(uiWindowsControl *c, int *width, int *height)
|
||||||
int labelwid;
|
int labelwid;
|
||||||
int i;
|
int i;
|
||||||
int minimumWidth, minimumHeight;
|
int minimumWidth, minimumHeight;
|
||||||
|
int nVisible;
|
||||||
uiWindowsSizing sizing;
|
uiWindowsSizing sizing;
|
||||||
|
|
||||||
*width = 0;
|
*width = 0;
|
||||||
|
@ -174,20 +183,17 @@ static void uiFormMinimumSize(uiWindowsControl *c, int *width, int *height)
|
||||||
// 0) get this Form's padding
|
// 0) get this Form's padding
|
||||||
formPadding(f, &xpadding, &ypadding);
|
formPadding(f, &xpadding, &ypadding);
|
||||||
|
|
||||||
// 1) initialize the desired rect with the needed padding
|
// 1) determine the longest width of all controls and labels; add in the height of non-stretchy controls and get (but not add in) the largest heights of stretchy controls
|
||||||
// TODO this is wrong if any controls are hidden
|
|
||||||
*width = xpadding;
|
|
||||||
*height = (f->controls->size() - 1) * ypadding;
|
|
||||||
|
|
||||||
// 2) determine the longest width of all controls and labels; add in the height of non-stretchy controls and get (but not add in) the largest heights of stretchy controls
|
|
||||||
// we still add in like direction of stretchy controls
|
// we still add in like direction of stretchy controls
|
||||||
nStretchy = 0;
|
nStretchy = 0;
|
||||||
maxLabelWidth = 0;
|
maxLabelWidth = 0;
|
||||||
maxControlWidth = 0;
|
maxControlWidth = 0;
|
||||||
maxStretchyHeight = 0;
|
maxStretchyHeight = 0;
|
||||||
|
nVisible = 0;
|
||||||
for (const struct formChild &fc : *(f->controls)) {
|
for (const struct formChild &fc : *(f->controls)) {
|
||||||
if (!uiControlVisible(fc.c))
|
if (!uiControlVisible(fc.c))
|
||||||
continue;
|
continue;
|
||||||
|
nVisible++;
|
||||||
labelwid = uiWindowsWindowTextWidth(fc.label);
|
labelwid = uiWindowsWindowTextWidth(fc.label);
|
||||||
if (maxLabelWidth < labelwid)
|
if (maxLabelWidth < labelwid)
|
||||||
maxLabelWidth = labelwid;
|
maxLabelWidth = labelwid;
|
||||||
|
@ -202,8 +208,14 @@ static void uiFormMinimumSize(uiWindowsControl *c, int *width, int *height)
|
||||||
if (!fc.stretchy)
|
if (!fc.stretchy)
|
||||||
*height += minimumHeight;
|
*height += minimumHeight;
|
||||||
}
|
}
|
||||||
|
if (nVisible == 0) // nothing to show; return 0x0
|
||||||
|
return;
|
||||||
*width += maxLabelWidth + maxControlWidth;
|
*width += maxLabelWidth + maxControlWidth;
|
||||||
|
|
||||||
|
// 2) outset the desired rect with the needed padding
|
||||||
|
*width += xpadding;
|
||||||
|
*height += (nVisible - 1) * ypadding;
|
||||||
|
|
||||||
// 3) and now we can add in stretchy controls
|
// 3) and now we can add in stretchy controls
|
||||||
*height += nStretchy * maxStretchyHeight;
|
*height += nStretchy * maxStretchyHeight;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue