mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 20:01:11 +00:00
Implement isEqual: so that we don't have any repeat constraints in the array
This commit is contained in:
parent
474e87d2ad
commit
027cb95650
3 changed files with 61 additions and 41 deletions
|
@ -35,7 +35,6 @@
|
|||
{
|
||||
GSXibElement *_IBObjectContainer;
|
||||
GSXibElement *_connectionRecords;
|
||||
GSXibElement *_constraints;
|
||||
GSXibElement *_objectRecords;
|
||||
GSXibElement *_orderedObjects;
|
||||
GSXibElement *_flattenedProperties;
|
||||
|
|
|
@ -670,10 +670,6 @@ static NSArray *XmlBoolDefaultYes = nil;
|
|||
andAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"connectionRecords", @"key",
|
||||
nil]];
|
||||
_constraints = [[GSXibElement alloc] initWithType: @"array"
|
||||
andAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"constraints", @"key",
|
||||
nil]];
|
||||
_flattenedProperties = [[GSXibElement alloc] initWithType: @"dictionary"
|
||||
andAttributes: [NSDictionary dictionaryWithObjectsAndKeys:
|
||||
@"NSMutableDictionary", @"class",
|
||||
|
@ -699,7 +695,6 @@ static NSArray *XmlBoolDefaultYes = nil;
|
|||
// Create the linked set of XIB elements...
|
||||
[_IBObjectContainer setElement: _connectionRecords forKey: @"connectionRecords"];
|
||||
[_IBObjectContainer setElement: _objectRecords forKey: @"objectRecords"];
|
||||
[_IBObjectContainer setElement: _constraints forKey: @"constraints"];
|
||||
[_IBObjectContainer setElement: _flattenedProperties forKey: @"flattenedProperties"];
|
||||
}
|
||||
|
||||
|
@ -707,7 +702,6 @@ static NSArray *XmlBoolDefaultYes = nil;
|
|||
{
|
||||
RELEASE(_IBObjectContainer);
|
||||
RELEASE(_connectionRecords);
|
||||
RELEASE(_constraints);
|
||||
RELEASE(_objectRecords);
|
||||
RELEASE(_flattenedProperties);
|
||||
RELEASE(_runtimeAttributes);
|
||||
|
|
|
@ -210,9 +210,12 @@ static NSMutableArray *activeConstraints = nil;
|
|||
NSUInteger idx = 0;
|
||||
NSEnumerator *en = [activeConstraints objectEnumerator];
|
||||
NSLayoutConstraint *c = nil;
|
||||
NSLog(@"Adding %@", constraint);
|
||||
|
||||
while ((c = [en nextObject]) != nil)
|
||||
{
|
||||
if ([activeConstraints containsObject: c])
|
||||
break; // if it contains the current constraint, skip...
|
||||
|
||||
if ([c priority] < [constraint priority])
|
||||
{
|
||||
idx++;
|
||||
|
@ -236,6 +239,38 @@ static NSMutableArray *activeConstraints = nil;
|
|||
return array;
|
||||
}
|
||||
|
||||
// Designated initializer...
|
||||
+ (instancetype) constraintWithItem: (id)view1
|
||||
attribute: (NSLayoutAttribute)attr1
|
||||
relatedBy: (NSLayoutRelation)relation
|
||||
toItem: (id)view2
|
||||
attribute: (NSLayoutAttribute)attr2
|
||||
multiplier: (CGFloat)mult
|
||||
constant: (CGFloat)c
|
||||
{
|
||||
NSLayoutConstraint *constraint =
|
||||
[[NSLayoutConstraint alloc] initWithItem: view1
|
||||
attribute: attr1
|
||||
relatedBy: relation
|
||||
toItem: view2
|
||||
attribute: attr2
|
||||
multiplier: mult
|
||||
constant: c];
|
||||
|
||||
AUTORELEASE(constraint);
|
||||
return constraint;
|
||||
}
|
||||
|
||||
+ (void) activateConstraints: (NSArray *)constraints
|
||||
{
|
||||
[activeConstraints addObjectsFromArray: [constraints sortedArrayUsingSelector: @selector(compare:)]];
|
||||
}
|
||||
|
||||
+ (void) deactivateConstraints: (NSArray *)constraints
|
||||
{
|
||||
[activeConstraints removeObjectsInArray: constraints];
|
||||
}
|
||||
|
||||
- (instancetype) initWithItem: (id)firstItem
|
||||
attribute: (NSLayoutAttribute)firstAttribute
|
||||
relatedBy: (NSLayoutRelation)relation
|
||||
|
@ -266,28 +301,6 @@ static NSMutableArray *activeConstraints = nil;
|
|||
return self;
|
||||
}
|
||||
|
||||
// Designated initializer...
|
||||
+ (instancetype) constraintWithItem: (id)view1
|
||||
attribute: (NSLayoutAttribute)attr1
|
||||
relatedBy: (NSLayoutRelation)relation
|
||||
toItem: (id)view2
|
||||
attribute: (NSLayoutAttribute)attr2
|
||||
multiplier: (CGFloat)mult
|
||||
constant: (CGFloat)c
|
||||
{
|
||||
NSLayoutConstraint *constraint =
|
||||
[[NSLayoutConstraint alloc] initWithItem: view1
|
||||
attribute: attr1
|
||||
relatedBy: relation
|
||||
toItem: view2
|
||||
attribute: attr2
|
||||
multiplier: mult
|
||||
constant: c];
|
||||
|
||||
AUTORELEASE(constraint);
|
||||
return constraint;
|
||||
}
|
||||
|
||||
// Active
|
||||
- (BOOL) isActive
|
||||
{
|
||||
|
@ -306,17 +319,8 @@ static NSMutableArray *activeConstraints = nil;
|
|||
}
|
||||
}
|
||||
|
||||
+ (void) activateConstraints: (NSArray *)constraints
|
||||
{
|
||||
[activeConstraints addObjectsFromArray: [constraints sortedArrayUsingSelector: @selector(_compare:)]];
|
||||
}
|
||||
|
||||
+ (void) deactivateConstraints: (NSArray *)constraints
|
||||
{
|
||||
[activeConstraints removeObjectsInArray: constraints];
|
||||
}
|
||||
|
||||
- (NSComparisonResult) _compare: (NSLayoutConstraint *)constraint
|
||||
// compare and isEqual...
|
||||
- (NSComparisonResult) compare: (NSLayoutConstraint *)constraint
|
||||
{
|
||||
if ([self priority] < [constraint priority])
|
||||
{
|
||||
|
@ -330,6 +334,29 @@ static NSMutableArray *activeConstraints = nil;
|
|||
return NSOrderedSame;
|
||||
}
|
||||
|
||||
- (BOOL) isEqual: (NSLayoutConstraint *)constraint
|
||||
{
|
||||
BOOL result = NO;
|
||||
|
||||
if (YES == [super isEqual: constraint])
|
||||
{
|
||||
result = YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
result = (_firstItem == [constraint firstItem] &&
|
||||
_secondItem == [constraint secondItem] &&
|
||||
_firstAttribute == [constraint firstAttribute] &&
|
||||
_secondAttribute == [constraint secondAttribute] &&
|
||||
_relation == [constraint relation] &&
|
||||
_multiplier == [constraint multiplier] &&
|
||||
_constant == [constraint constant] &&
|
||||
_priority == [constraint priority]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// Items
|
||||
- (id) firstItem
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue