Fixed hiding on OS X uiBox.
This commit is contained in:
parent
d54f7dd682
commit
44b4fa9c68
46
darwin/box.m
46
darwin/box.m
|
@ -1,6 +1,8 @@
|
||||||
// 15 august 2015
|
// 15 august 2015
|
||||||
#import "uipriv_darwin.h"
|
#import "uipriv_darwin.h"
|
||||||
|
|
||||||
|
// TODO hiding all stretchy controls still hugs trailing edge
|
||||||
|
|
||||||
@interface boxChild : NSObject
|
@interface boxChild : NSObject
|
||||||
@property uiControl *c;
|
@property uiControl *c;
|
||||||
@property BOOL stretchy;
|
@property BOOL stretchy;
|
||||||
|
@ -14,7 +16,6 @@
|
||||||
NSMutableArray *children;
|
NSMutableArray *children;
|
||||||
BOOL vertical;
|
BOOL vertical;
|
||||||
int padded;
|
int padded;
|
||||||
int nStretchy;
|
|
||||||
|
|
||||||
NSLayoutConstraint *first;
|
NSLayoutConstraint *first;
|
||||||
NSMutableArray *inBetweens;
|
NSMutableArray *inBetweens;
|
||||||
|
@ -41,6 +42,7 @@
|
||||||
- (void)setPadded:(int)p;
|
- (void)setPadded:(int)p;
|
||||||
- (BOOL)hugsTrailing;
|
- (BOOL)hugsTrailing;
|
||||||
- (BOOL)hugsBottom;
|
- (BOOL)hugsBottom;
|
||||||
|
- (int)nStretchy;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
struct uiBox {
|
struct uiBox {
|
||||||
|
@ -68,7 +70,6 @@ struct uiBox {
|
||||||
self->vertical = vert;
|
self->vertical = vert;
|
||||||
self->padded = 0;
|
self->padded = 0;
|
||||||
self->children = [NSMutableArray new];
|
self->children = [NSMutableArray new];
|
||||||
self->nStretchy = 0;
|
|
||||||
|
|
||||||
self->inBetweens = [NSMutableArray new];
|
self->inBetweens = [NSMutableArray new];
|
||||||
self->otherConstraints = [NSMutableArray new];
|
self->otherConstraints = [NSMutableArray new];
|
||||||
|
@ -163,6 +164,8 @@ struct uiBox {
|
||||||
// first arrange in the primary direction
|
// first arrange in the primary direction
|
||||||
prev = nil;
|
prev = nil;
|
||||||
for (bc in self->children) {
|
for (bc in self->children) {
|
||||||
|
if (!uiControlVisible(bc.c))
|
||||||
|
continue;
|
||||||
if (prev == nil) { // first view
|
if (prev == nil) { // first view
|
||||||
self->first = mkConstraint(self, self->primaryStart,
|
self->first = mkConstraint(self, self->primaryStart,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
|
@ -184,6 +187,8 @@ struct uiBox {
|
||||||
[self->inBetweens addObject:c];
|
[self->inBetweens addObject:c];
|
||||||
prev = [bc view];
|
prev = [bc view];
|
||||||
}
|
}
|
||||||
|
if (prev == nil) // no control visible; act as if no controls
|
||||||
|
return;
|
||||||
self->last = mkConstraint(prev, self->primaryEnd,
|
self->last = mkConstraint(prev, self->primaryEnd,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
self, self->primaryEnd,
|
self, self->primaryEnd,
|
||||||
|
@ -197,6 +202,8 @@ struct uiBox {
|
||||||
if (!self->vertical)
|
if (!self->vertical)
|
||||||
hugsSecondary = uiDarwinControlHugsBottom;
|
hugsSecondary = uiDarwinControlHugsBottom;
|
||||||
for (bc in self->children) {
|
for (bc in self->children) {
|
||||||
|
if (!uiControlVisible(bc.c))
|
||||||
|
continue;
|
||||||
c = mkConstraint(self, self->secondaryStart,
|
c = mkConstraint(self, self->secondaryStart,
|
||||||
NSLayoutRelationEqual,
|
NSLayoutRelationEqual,
|
||||||
[bc view], self->secondaryStart,
|
[bc view], self->secondaryStart,
|
||||||
|
@ -225,10 +232,12 @@ struct uiBox {
|
||||||
}
|
}
|
||||||
|
|
||||||
// and make all stretchy controls the same size
|
// and make all stretchy controls the same size
|
||||||
if (self->nStretchy == 0)
|
if ([self nStretchy] == 0)
|
||||||
return;
|
return;
|
||||||
prev = nil; // first stretchy view
|
prev = nil; // first stretchy view
|
||||||
for (bc in self->children) {
|
for (bc in self->children) {
|
||||||
|
if (!uiControlVisible(bc.c))
|
||||||
|
continue;
|
||||||
if (!bc.stretchy)
|
if (!bc.stretchy)
|
||||||
continue;
|
continue;
|
||||||
if (prev == nil) {
|
if (prev == nil) {
|
||||||
|
@ -272,15 +281,13 @@ struct uiBox {
|
||||||
// make sure controls don't hug their secondary direction so they fill the width of the view
|
// make sure controls don't hug their secondary direction so they fill the width of the view
|
||||||
uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
uiDarwinControlSetHuggingPriority(uiDarwinControl(bc.c), NSLayoutPriorityDefaultLow, self->secondaryOrientation);
|
||||||
|
|
||||||
|
oldnStretchy = [self nStretchy];
|
||||||
[self->children addObject:bc];
|
[self->children addObject:bc];
|
||||||
|
|
||||||
[self establishOurConstraints];
|
[self establishOurConstraints];
|
||||||
if (bc.stretchy) {
|
if (bc.stretchy)
|
||||||
oldnStretchy = self->nStretchy;
|
|
||||||
self->nStretchy++;
|
|
||||||
if (oldnStretchy == 0)
|
if (oldnStretchy == 0)
|
||||||
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b));
|
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b));
|
||||||
}
|
|
||||||
|
|
||||||
[bc release]; // we don't need the initial reference now
|
[bc release]; // we don't need the initial reference now
|
||||||
}
|
}
|
||||||
|
@ -302,11 +309,9 @@ struct uiBox {
|
||||||
[self->children removeObjectAtIndex:n];
|
[self->children removeObjectAtIndex:n];
|
||||||
|
|
||||||
[self establishOurConstraints];
|
[self establishOurConstraints];
|
||||||
if (stretchy) {
|
if (stretchy)
|
||||||
self->nStretchy--;
|
if ([self nStretchy] == 0)
|
||||||
if (self->nStretchy == 0)
|
|
||||||
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b));
|
uiDarwinNotifyEdgeHuggingChanged(uiDarwinControl(self->b));
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (int)isPadded
|
- (int)isPadded
|
||||||
|
@ -329,14 +334,29 @@ struct uiBox {
|
||||||
{
|
{
|
||||||
if (self->vertical) // always hug if vertical
|
if (self->vertical) // always hug if vertical
|
||||||
return YES;
|
return YES;
|
||||||
return self->nStretchy != 0;
|
return [self nStretchy] != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)hugsBottom
|
- (BOOL)hugsBottom
|
||||||
{
|
{
|
||||||
if (!self->vertical) // always hug if horizontal
|
if (!self->vertical) // always hug if horizontal
|
||||||
return YES;
|
return YES;
|
||||||
return self->nStretchy != 0;
|
return [self nStretchy] != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (int)nStretchy
|
||||||
|
{
|
||||||
|
boxChild *bc;
|
||||||
|
int n;
|
||||||
|
|
||||||
|
n = 0;
|
||||||
|
for (bc in self->children) {
|
||||||
|
if (!uiControlVisible(bc.c))
|
||||||
|
continue;
|
||||||
|
if (bc.stretchy)
|
||||||
|
n++;
|
||||||
|
}
|
||||||
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue