Wrote up the resize triggering logic for most controls. Only uiTab remains.
This commit is contained in:
parent
2cf0707c3e
commit
ca068ecaf2
|
@ -98,7 +98,7 @@ static void relayout(uiBox *b)
|
||||||
|
|
||||||
[b->view removeConstraints:[b->view constraints]];
|
[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
|
// also figure out which is the first stretchy control, if any
|
||||||
metrics = [NSMutableDictionary new];
|
metrics = [NSMutableDictionary new];
|
||||||
views = [NSMutableDictionary new];
|
views = [NSMutableDictionary new];
|
||||||
|
@ -106,12 +106,15 @@ static void relayout(uiBox *b)
|
||||||
n = 0;
|
n = 0;
|
||||||
while (n < [b->children count]) {
|
while (n < [b->children count]) {
|
||||||
uiControl *child;
|
uiControl *child;
|
||||||
|
uiDarwinControl *cc;
|
||||||
NSView *childView;
|
NSView *childView;
|
||||||
NSSize fittingSize;
|
NSSize fittingSize;
|
||||||
|
|
||||||
child = childAt(b, n);
|
child = childAt(b, n);
|
||||||
|
cc = uiDarwinControl(child);
|
||||||
childView = (NSView *) uiControlHandle(child);
|
childView = (NSView *) uiControlHandle(child);
|
||||||
[views setObject:childView forKey:viewName(n)];
|
[views setObject:childView forKey:viewName(n)];
|
||||||
|
(*(cc->Relayout))(cc);
|
||||||
fittingSize = fittingAlignmentSize(childView);
|
fittingSize = fittingAlignmentSize(childView);
|
||||||
[metrics setObject:[NSNumber numberWithDouble:fittingSize.width]
|
[metrics setObject:[NSNumber numberWithDouble:fittingSize.width]
|
||||||
forKey:widthMetricName(n)];
|
forKey:widthMetricName(n)];
|
||||||
|
@ -190,8 +193,6 @@ static void relayout(uiBox *b)
|
||||||
|
|
||||||
[metrics release];
|
[metrics release];
|
||||||
[views release];
|
[views release];
|
||||||
|
|
||||||
uiDarwinControlRelayoutParent(uiDarwinControl(b));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void boxRelayout(uiDarwinControl *c)
|
static void boxRelayout(uiDarwinControl *c)
|
||||||
|
|
|
@ -75,7 +75,7 @@ void uiButtonSetText(uiButton *b, const char *text)
|
||||||
{
|
{
|
||||||
[b->button setTitle:toNSString(text)];
|
[b->button setTitle:toNSString(text)];
|
||||||
// this may result in the size of the button changing
|
// 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)
|
void uiButtonOnClicked(uiButton *b, void (*f)(uiButton *, void *), void *data)
|
||||||
|
|
|
@ -75,7 +75,7 @@ void uiCheckboxSetText(uiCheckbox *c, const char *text)
|
||||||
{
|
{
|
||||||
[c->button setTitle:toNSString(text)];
|
[c->button setTitle:toNSString(text)];
|
||||||
// this may result in the size of the checkbox changing
|
// 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)
|
void uiCheckboxOnToggled(uiCheckbox *c, void (*f)(uiCheckbox *, void *), void *data)
|
||||||
|
|
|
@ -30,6 +30,22 @@ static void onDestroy(uiGroup *g)
|
||||||
|
|
||||||
// TODO group container update
|
// 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)
|
char *uiGroupTitle(uiGroup *g)
|
||||||
{
|
{
|
||||||
return PUT_CODE_HERE;
|
return PUT_CODE_HERE;
|
||||||
|
@ -39,7 +55,7 @@ void uiGroupSetTitle(uiGroup *g, const char *title)
|
||||||
{
|
{
|
||||||
[g->box setTitle:toNSString(title)];
|
[g->box setTitle:toNSString(title)];
|
||||||
// changing the text might necessitate a change in the groupbox's size
|
// 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)
|
void uiGroupSetChild(uiGroup *g, uiControl *child)
|
||||||
|
@ -56,8 +72,7 @@ void uiGroupSetChild(uiGroup *g, uiControl *child)
|
||||||
childView = (NSView *) uiControlHandle(g->child);
|
childView = (NSView *) uiControlHandle(g->child);
|
||||||
uiControlSetParent(g->child, uiControl(g));
|
uiControlSetParent(g->child, uiControl(g));
|
||||||
[g->box addSubview:childView];
|
[g->box addSubview:childView];
|
||||||
layoutSingleView(g->box, childView, g->margined);
|
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
|
||||||
uiDarwinControlRelayoutParent(uiDarwinControl(g));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,14 +83,9 @@ int uiGroupMargined(uiGroup *g)
|
||||||
|
|
||||||
void uiGroupSetMargined(uiGroup *g, int margined)
|
void uiGroupSetMargined(uiGroup *g, int margined)
|
||||||
{
|
{
|
||||||
NSView *childView;
|
|
||||||
|
|
||||||
g->margined = margined;
|
g->margined = margined;
|
||||||
if (g->child != NULL) {
|
if (g->child != NULL)
|
||||||
childView = (NSView *) uiControlHandle(g->child);
|
uiDarwinControlTriggerRelayout(uiDarwinControl(g));
|
||||||
layoutSingleView(g->box, childView, g->margined);
|
|
||||||
uiDarwinControlRelayoutParent(uiDarwinControl(g));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uiGroup *uiNewGroup(const char *title)
|
uiGroup *uiNewGroup(const char *title)
|
||||||
|
@ -94,6 +104,7 @@ uiGroup *uiNewGroup(const char *title)
|
||||||
[g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
[g->box setTitleFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
||||||
|
|
||||||
uiDarwinFinishNewControl(g, uiGroup);
|
uiDarwinFinishNewControl(g, uiGroup);
|
||||||
|
uiDarwinControl(g)->Relayout = groupRelayout;
|
||||||
|
|
||||||
return g;
|
return g;
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@ void uiLabelSetText(uiLabel *l, const char *text)
|
||||||
{
|
{
|
||||||
[l->textfield setStringValue:toNSString(text)];
|
[l->textfield setStringValue:toNSString(text)];
|
||||||
// changing the text might necessitate a change in the label's size
|
// 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)
|
uiLabel *uiNewLabel(const char *text)
|
||||||
|
|
|
@ -15,7 +15,7 @@ uiDarwinDefineControl(
|
||||||
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
void uiRadioButtonsAppend(uiRadioButtons *r, const char *text)
|
||||||
{
|
{
|
||||||
// TODO
|
// TODO
|
||||||
//TODO uiControlQueueResize(uiControl(r));
|
uiDarwinControlTriggerRelayout(uiDarwinControl(r));
|
||||||
}
|
}
|
||||||
|
|
||||||
uiRadioButtons *uiNewRadioButtons(void)
|
uiRadioButtons *uiNewRadioButtons(void)
|
||||||
|
|
|
@ -116,6 +116,22 @@ static void windowCommitHide(uiControl *c)
|
||||||
|
|
||||||
// TODO container update state
|
// 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)
|
char *uiWindowTitle(uiWindow *w)
|
||||||
{
|
{
|
||||||
return uiDarwinNSStringToText([w->window title]);
|
return uiDarwinNSStringToText([w->window title]);
|
||||||
|
@ -146,7 +162,7 @@ void uiWindowSetChild(uiWindow *w, uiControl *child)
|
||||||
uiControlSetParent(w->child, uiControl(w));
|
uiControlSetParent(w->child, uiControl(w));
|
||||||
childView = (NSView *) uiControlHandle(w->child);
|
childView = (NSView *) uiControlHandle(w->child);
|
||||||
[[w->window contentView] addSubview:childView];
|
[[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)
|
void uiWindowSetMargined(uiWindow *w, int margined)
|
||||||
{
|
{
|
||||||
NSView *childView;
|
|
||||||
|
|
||||||
w->margined = margined;
|
w->margined = margined;
|
||||||
if (w->child != NULL) {
|
if (w->child != NULL)
|
||||||
childView = (NSView *) uiControlHandle(w->child);
|
uiDarwinControlTriggerRelayout(uiDarwinControl(w));
|
||||||
[[w->window contentView] addSubview:childView];
|
|
||||||
layoutSingleView([w->window contentView], childView, w->margined);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int defaultOnClosing(uiWindow *w, void *data)
|
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);
|
uiDarwinFinishNewControl(w, uiWindow);
|
||||||
//TODO uiControl(w)->CommitShow = windowCommitShow;
|
//TODO uiControl(w)->CommitShow = windowCommitShow;
|
||||||
//TODO uiControl(w)->CommitHide = windowCommitHide;
|
//TODO uiControl(w)->CommitHide = windowCommitHide;
|
||||||
|
uiDarwinControl(w)->Relayout = windowRelayout;
|
||||||
|
|
||||||
return w;
|
return w;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue