From 831fe1e73bd07be2523630c5056208a6efa17da8 Mon Sep 17 00:00:00 2001 From: emersion Date: Wed, 15 Jun 2016 16:39:23 +0200 Subject: [PATCH] Updates darwin to work with upstream changes --- darwin/form.m | 45 ++++++++++++++++++++++++++++++++++++--------- 1 file changed, 36 insertions(+), 9 deletions(-) diff --git a/darwin/form.m b/darwin/form.m index 08a3b6da..614c6114 100644 --- a/darwin/form.m +++ b/darwin/form.m @@ -23,7 +23,6 @@ uiForm *f; NSMutableArray *children; int padded; - int nStretchy; NSLayoutConstraint *first; NSMutableArray *inBetweens; @@ -45,6 +44,7 @@ - (void)setPadded:(int)p; - (BOOL)hugsTrailing; - (BOOL)hugsBottom; +- (int)nStretchy; @end struct uiForm { @@ -123,7 +123,6 @@ struct uiForm { self->f = ff; self->padded = 0; self->children = [NSMutableArray new]; - self->nStretchy = 0; self->inBetweens = [NSMutableArray new]; self->widths = [NSMutableArray new]; @@ -221,6 +220,9 @@ struct uiForm { // 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, @@ -259,6 +261,8 @@ struct uiForm { prev = [fc view]; prevlabel = fc; } + if (prev == nil) // all hidden; act as if nothing there + return; self->last = mkConstraint(prev, NSLayoutAttributeBottom, NSLayoutRelationEqual, self, NSLayoutAttributeBottom, @@ -269,6 +273,8 @@ struct uiForm { // now arrange the controls horizontally for (fc in self->children) { + if (!uiControlVisible(fc.c)) + continue; c = mkConstraint(self, NSLayoutAttributeLeading, NSLayoutRelationEqual, fc, NSLayoutAttributeLeading, @@ -313,6 +319,8 @@ struct uiForm { // 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) { @@ -375,15 +383,13 @@ struct uiForm { @"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 } @@ -408,8 +414,7 @@ struct uiForm { [self establishOurConstraints]; if (stretchy) { - self->nStretchy--; - if (self->nStretchy == 0) + if ([self nStretchy] == 0) uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->f)); } } @@ -440,7 +445,22 @@ struct uiForm { - (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 @@ -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