Skip to content

Commit

Permalink
Updates darwin to work with upstream changes
Browse files Browse the repository at this point in the history
  • Loading branch information
emersion committed Jun 15, 2016
1 parent b817a16 commit 831fe1e
Showing 1 changed file with 36 additions and 9 deletions.
45 changes: 36 additions & 9 deletions darwin/form.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ @interface formView : NSView {
uiForm *f;
NSMutableArray *children;
int padded;
int nStretchy;

NSLayoutConstraint *first;
NSMutableArray *inBetweens;
Expand All @@ -45,6 +44,7 @@ - (int)isPadded;
- (void)setPadded:(int)p;
- (BOOL)hugsTrailing;
- (BOOL)hugsBottom;
- (int)nStretchy;
@end

struct uiForm {
Expand Down Expand Up @@ -123,7 +123,6 @@ - (id)initWithF:(uiForm *)ff
self->f = ff;
self->padded = 0;
self->children = [NSMutableArray new];
self->nStretchy = 0;

self->inBetweens = [NSMutableArray new];
self->widths = [NSMutableArray new];
Expand Down Expand Up @@ -221,6 +220,9 @@ - (void)establishOurConstraints
// first arrange the children vertically and make them the same width
prev = nil;
for (fc in self->children) {
[fc setHidden:!uiControlVisible(fc.c)];
if (!uiControlVisible(fc.c))
continue;
if (prev == nil) { // first view
self->first = mkConstraint(self, NSLayoutAttributeTop,
NSLayoutRelationEqual,
Expand Down Expand Up @@ -259,6 +261,8 @@ - (void)establishOurConstraints
prev = [fc view];
prevlabel = fc;
}
if (prev == nil) // all hidden; act as if nothing there
return;
self->last = mkConstraint(prev, NSLayoutAttributeBottom,
NSLayoutRelationEqual,
self, NSLayoutAttributeBottom,
Expand All @@ -269,6 +273,8 @@ - (void)establishOurConstraints

// now arrange the controls horizontally
for (fc in self->children) {
if (!uiControlVisible(fc.c))
continue;
c = mkConstraint(self, NSLayoutAttributeLeading,
NSLayoutRelationEqual,
fc, NSLayoutAttributeLeading,
Expand Down Expand Up @@ -313,6 +319,8 @@ - (void)establishOurConstraints
// and make all stretchy controls have the same height
prev = nil;
for (fc in self->children) {
if (!uiControlVisible(fc.c))
continue;
if (!fc.stretchy)
continue;
if (prev == nil) {
Expand Down Expand Up @@ -375,15 +383,13 @@ - (void)append:(NSString *)label c:(uiControl *)c stretchy:(int)stretchy
@"uiForm baseline constraint");
[self addConstraint:fc.baseline];

oldnStretchy = [self nStretchy];
[self->children addObject:fc];

[self establishOurConstraints];
if (fc.stretchy) {
oldnStretchy = self->nStretchy;
self->nStretchy++;
if (fc.stretchy)
if (oldnStretchy == 0)
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f));
}

[fc release]; // we don't need the initial reference now
}
Expand All @@ -408,8 +414,7 @@ - (void)delete:(int)n

[self establishOurConstraints];
if (stretchy) {
self->nStretchy--;
if (self->nStretchy == 0)
if ([self nStretchy] == 0)
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f));
}
}
Expand Down Expand Up @@ -440,7 +445,22 @@ - (BOOL)hugsTrailing
- (BOOL)hugsBottom
{
// only hug if we have stretchy
return self->nStretchy != 0;
return [self nStretchy] != 0;
}

- (int)nStretchy
{
formChild *fc;
int n;

n = 0;
for (fc in self->children) {
if (!uiControlVisible(fc.c))
continue;
if (fc.stretchy)
n++;
}
return n;
}

@end
Expand Down Expand Up @@ -500,6 +520,13 @@ static void uiFormChildEdgeHuggingChanged(uiDarwinControl *c)
uiDarwinControlDefaultHuggingPriority(uiForm, view)
uiDarwinControlDefaultSetHuggingPriority(uiForm, view)

static void uiFormChildVisibilityChanged(uiDarwinControl *c)
{
uiForm *f = uiForm(c);

[f->view establishOurConstraints];
}

void uiFormAppend(uiForm *f, const char *label, uiControl *c, int stretchy)
{
// LONGTERM on other platforms
Expand Down

0 comments on commit 831fe1e

Please # to comment.