Wrote up the resize triggering logic for most controls. Only uiTab remains.

This commit is contained in:
Pietro Gagliardi 2015-08-18 20:15:09 -04:00
parent 2cf0707c3e
commit ca068ecaf2
7 changed files with 49 additions and 25 deletions

View File

@ -98,7 +98,7 @@ static void relayout(uiBox *b)
[b->view removeConstraints:[b->view constraints]];
// first collect the views and their fitting sizes (for non-stretchy controls)
// first lay out all children, collect the views and their fitting sizes (for non-stretchy controls)
// also figure out which is the first stretchy control, if any
metrics = [NSMutableDictionary new];
views = [NSMutableDictionary new];
@ -106,12 +106,15 @@ static void relayout(uiBox *b)
n = 0;
while (n < [b->children count]) {
uiControl *child;
uiDarwinControl *cc;
NSView *childView;
NSSize fittingSize;
child = childAt(b, n);
cc = uiDarwinControl(child);
childView = (NSView *) uiControlHandle(child);
[views setObject:childView forKey:viewName(n)];
(*(cc->Relayout))(cc);
fittingSize = fittingAlignmentSize(childView);
[metrics setObject:[NSNumber numberWithDouble:fittingSize.width]
forKey:widthMetricName(n)];
@ -190,8 +193,6 @@ static void relayout(uiBox *b)
[metrics release];
[views release];
uiDarwinControlRelayoutParent(uiDarwinControl(b));
}
static void boxRelayout(uiDarwinControl *c)

View File

@ -75,7 +75,7 @@ void uiButtonSetText(uiButton *b, const char *text)
{
[b->button setTitle:toNSString(text)];
// this may result in the size of the button changing
// fortunately Auto Layout handles this for us
uiDarwinControlTriggerRelayout(uiDarwinControl(b));
}
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)

View File

@ -75,7 +75,7 @@ void uiCheckboxSetText(uiCheckbox *c, const char *text)
{
[c->button setTitle:toNSString(text)];
// this may result in the size of the checkbox changing
// fortunately Auto Layout handles this for us
uiDarwinControlTriggerRelayout(uiDarwinControl(c));
}
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)

View File

@ -30,6 +30,22 @@ static void onDestroy(uiGroup *g)
// TODO group container update
static void groupRelayout(uiDarwinControl *c)
{
uiGroup *w = uiGroup(c);
uiDarwinControl *cc;
NSView *childView;
if (g->child == NULL)
return;
cc = uiDarwinControl(g->child);
childView = (NSView *) uiControlHandle(g->child);
// first relayout the child
(*(cc->Relayout))(cc);
// now relayout ourselves
layoutSingleView(g->box, childView, g->margined);
}
char *uiGroupTitle(uiGroup *g)
{
return PUT_CODE_HERE;
@ -39,7 +55,7 @@ void uiGroupSetTitle(uiGroup *g, const char *title)
{
[g->box setTitle:toNSString(title)];
// changing the text might necessitate a change in the groupbox's size
//TODO uiControlQueueResize(uiControl(g));
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
}
void uiGroupSetChild(uiGroup *g, uiControl *child)
@ -56,8 +72,7 @@ void uiGroupSetChild(uiGroup *g, uiControl *child)
childView = (NSView *) uiControlHandle(g->child);
uiControlSetParent(g->child, uiControl(g));
[g->box addSubview:childView];
layoutSingleView(g->box, childView, g->margined);
uiDarwinControlRelayoutParent(uiDarwinControl(g));
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
}
}
@ -68,14 +83,9 @@ int uiGroupMargined(uiGroup *g)
void uiGroupSetMargined(uiGroup *g, int margined)
{
NSView *childView;
g->margined = margined;
if (g->child != NULL) {
childView = (NSView *) uiControlHandle(g->child);
layoutSingleView(g->box, childView, g->margined);
uiDarwinControlRelayoutParent(uiDarwinControl(g));
}
if (g->child != NULL)
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
}
uiGroup *uiNewGroup(const char *title)
@ -94,6 +104,7 @@ uiGroup *uiNewGroup(const char *title)
[g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
uiDarwinFinishNewControl(g, uiGroup);
uiDarwinControl(g)->Relayout = groupRelayout;
return g;
}

View File

@ -21,7 +21,7 @@ void uiLabelSetText(uiLabel *l, const char *text)
{
[l->textfield setStringValue:toNSString(text)];
// changing the text might necessitate a change in the label's size
// fortunately Auto Layout handles this for us
uiDarwinControlTriggerRelayout(uiDarwinControl(l));
}
uiLabel *uiNewLabel(const char *text)

View File

@ -15,7 +15,7 @@ uiDarwinDefineControl(
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
{
// TODO
//TODO uiControlQueueResize(uiControl(r));
uiDarwinControlTriggerRelayout(uiDarwinControl(r));
}
uiRadioButtons *uiNewRadioButtons(void)

View File

@ -116,6 +116,22 @@ static void windowCommitHide(uiControl *c)
// TODO container update state
static void windowRelayout(uiDarwinControl *c)
{
uiWindow *w = uiWindow(c);
uiDarwinControl *cc;
NSView *childView;
if (w->child == NULL)
return;
cc = uiDarwinControl(w->child);
childView = (NSView *) uiControlHandle(w->child);
// first relayout the child
(*(cc->Relayout))(cc);
// now relayout ourselves
layoutSingleView([w->window contentView], childView, w->margined);
}
char *uiWindowTitle(uiWindow *w)
{
return uiDarwinNSStringToText([w->window title]);
@ -146,7 +162,7 @@ void uiWindowSetChild(uiWindow *w, uiControl *child)
uiControlSetParent(w->child, uiControl(w));
childView = (NSView *) uiControlHandle(w->child);
[[w->window contentView] addSubview:childView];
layoutSingleView([w->window contentView], childView, w->margined);
uiDarwinControlTriggerRelayout(uiDarwinControl(w));
}
}
@ -157,14 +173,9 @@ int uiWindowMargined(uiWindow *w)
void uiWindowSetMargined(uiWindow *w, int margined)
{
NSView *childView;
w->margined = margined;
if (w->child != NULL) {
childView = (NSView *) uiControlHandle(w->child);
[[w->window contentView] addSubview:childView];
layoutSingleView([w->window contentView], childView, w->margined);
}
if (w->child != NULL)
uiDarwinControlTriggerRelayout(uiDarwinControl(w));
}
static int defaultOnClosing(uiWindow *w, void *data)
@ -200,6 +211,7 @@ uiWindow *uiNewWindow(const char *title, int width, int height, int hasMenubar)
uiDarwinFinishNewControl(w, uiWindow);
//TODO uiControl(w)->CommitShow = windowCommitShow;
//TODO uiControl(w)->CommitHide = windowCommitHide;
uiDarwinControl(w)->Relayout = windowRelayout;
return w;
}