2020-05-10 06:26:06 +00:00
|
|
|
/* Implementation of class NSLayoutConstraint
|
|
|
|
Copyright (C) 2020 Free Software Foundation, Inc.
|
|
|
|
|
2020-05-10 10:38:06 +00:00
|
|
|
By: Gregory Casamento <greg.casamento@gmail.com>
|
2020-05-10 06:26:06 +00:00
|
|
|
Date: Sat May 9 16:30:22 EDT 2020
|
|
|
|
|
|
|
|
This file is part of the GNUstep Library.
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free
|
|
|
|
Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
Boston, MA 02110 USA.
|
|
|
|
*/
|
|
|
|
|
2020-05-10 12:22:12 +00:00
|
|
|
#import <Foundation/NSArray.h>
|
|
|
|
#import <Foundation/NSDictionary.h>
|
2020-05-10 18:49:06 +00:00
|
|
|
#import <Foundation/NSKeyedArchiver.h>
|
2020-05-10 12:22:12 +00:00
|
|
|
|
|
|
|
#import "AppKit/NSControl.h"
|
|
|
|
#import "AppKit/NSView.h"
|
|
|
|
#import "AppKit/NSAnimation.h"
|
2020-05-10 06:26:06 +00:00
|
|
|
#import "AppKit/NSLayoutConstraint.h"
|
2020-06-03 11:12:31 +00:00
|
|
|
#import "AppKit/NSWindow.h"
|
2020-05-10 06:26:06 +00:00
|
|
|
|
2020-06-14 03:45:08 +00:00
|
|
|
static NSMutableArray *activeConstraints = nil;
|
2020-05-10 12:22:12 +00:00
|
|
|
|
2020-05-10 06:26:06 +00:00
|
|
|
@implementation NSLayoutConstraint
|
2020-05-10 12:41:10 +00:00
|
|
|
|
2020-06-01 06:27:49 +00:00
|
|
|
+ (void) initialize
|
|
|
|
{
|
|
|
|
if (self == [NSLayoutConstraint class])
|
|
|
|
{
|
|
|
|
[self setVersion: 1];
|
2020-06-14 03:45:08 +00:00
|
|
|
if (nil == activeConstraints)
|
|
|
|
{
|
|
|
|
activeConstraints = [[NSMutableArray alloc] initWithCapacity: 10];
|
|
|
|
}
|
2020-06-01 06:27:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:04:42 +00:00
|
|
|
+ (NSString *) _attributeToString: (NSLayoutAttribute)attr
|
|
|
|
{
|
|
|
|
NSString *name = nil;
|
|
|
|
|
|
|
|
switch (attr)
|
|
|
|
{
|
|
|
|
case NSLayoutAttributeLeft:
|
|
|
|
name = @"Left";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeRight:
|
|
|
|
name = @"Right";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeTop:
|
|
|
|
name = @"Top";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeBottom:
|
|
|
|
name = @"Bottom";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeLeading:
|
|
|
|
name = @"Leading";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeTrailing:
|
|
|
|
name = @"Trailing";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeWidth:
|
|
|
|
name = @"Width";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeHeight:
|
|
|
|
name = @"Height";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeCenterX:
|
|
|
|
name = @"CenterX";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeCenterY:
|
|
|
|
name = @"CenterY";
|
|
|
|
break;
|
|
|
|
//case NSLayoutAttributeLastBaseline:
|
|
|
|
//name = @"LastBaseline";
|
|
|
|
//break;
|
|
|
|
case NSLayoutAttributeBaseline:
|
|
|
|
name = @"Baseline";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeFirstBaseline:
|
|
|
|
name = @"FirstBaseline";
|
|
|
|
break;
|
|
|
|
case NSLayoutAttributeNotAnAttribute:
|
|
|
|
name = @"NotAnAttribute";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:40:16 +00:00
|
|
|
+ (NSLayoutAttribute) _stringToAttribute: (NSString *)str
|
|
|
|
{
|
|
|
|
NSLayoutAttribute a = 0;
|
|
|
|
|
|
|
|
if ([@"Left" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeLeft;
|
|
|
|
}
|
|
|
|
else if ([@"Right" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeRight;
|
|
|
|
}
|
|
|
|
else if ([@"Top" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeTop;
|
|
|
|
}
|
|
|
|
else if ([@"Bottom" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeBottom;
|
|
|
|
}
|
|
|
|
else if ([@"Leading" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeLeading;
|
|
|
|
}
|
|
|
|
else if ([@"Trailing" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeTrailing;
|
|
|
|
}
|
|
|
|
else if ([@"Width" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeWidth;
|
|
|
|
}
|
|
|
|
else if ([@"Height" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeHeight;
|
|
|
|
}
|
|
|
|
else if ([@"CenterX" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeCenterX;
|
|
|
|
}
|
|
|
|
else if ([@"CenterY" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeCenterY;
|
|
|
|
}
|
|
|
|
else if ([@"Baseline" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeBaseline;
|
|
|
|
}
|
|
|
|
else if ([@"FirstBaseline" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeFirstBaseline;
|
|
|
|
}
|
|
|
|
else if ([@"NotAnAttribute" isEqualToString: str])
|
|
|
|
{
|
|
|
|
a = NSLayoutAttributeNotAnAttribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
return a;
|
|
|
|
}
|
|
|
|
|
2020-05-27 23:04:42 +00:00
|
|
|
+ (NSString *) _relationToString: (NSLayoutRelation)rel
|
|
|
|
{
|
|
|
|
NSString *relation = nil;
|
|
|
|
|
|
|
|
switch (rel)
|
|
|
|
{
|
|
|
|
case NSLayoutRelationLessThanOrEqual:
|
|
|
|
relation = @"<=";
|
|
|
|
break;
|
|
|
|
case NSLayoutRelationEqual:
|
|
|
|
relation = @"=";
|
|
|
|
break;
|
|
|
|
case NSLayoutRelationGreaterThanOrEqual:
|
|
|
|
relation = @">=";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return relation;
|
|
|
|
}
|
|
|
|
|
2020-05-30 10:40:16 +00:00
|
|
|
+ (NSLayoutRelation) _stringToRelation: (NSString *)str
|
|
|
|
{
|
|
|
|
NSLayoutRelation r = 0;
|
|
|
|
|
|
|
|
if ([@"<=" isEqualToString: str])
|
|
|
|
{
|
|
|
|
r = NSLayoutRelationLessThanOrEqual;
|
|
|
|
}
|
|
|
|
else if ([@"=" isEqualToString: str])
|
|
|
|
{
|
|
|
|
r = NSLayoutRelationEqual;
|
|
|
|
}
|
|
|
|
else if ([@">=" isEqualToString: str])
|
|
|
|
{
|
|
|
|
r = NSLayoutRelationGreaterThanOrEqual;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2020-06-14 03:45:08 +00:00
|
|
|
+ (void) _addActiveConstraint: (NSLayoutConstraint *)constraint
|
|
|
|
{
|
|
|
|
NSUInteger idx = 0;
|
|
|
|
NSEnumerator *en = [activeConstraints objectEnumerator];
|
|
|
|
NSLayoutConstraint *c = nil;
|
2020-06-14 06:31:18 +00:00
|
|
|
|
2020-06-14 03:45:08 +00:00
|
|
|
while ((c = [en nextObject]) != nil)
|
|
|
|
{
|
2020-06-14 06:31:18 +00:00
|
|
|
if ([activeConstraints containsObject: c])
|
|
|
|
break; // if it contains the current constraint, skip...
|
|
|
|
|
2020-06-14 03:45:08 +00:00
|
|
|
if ([c priority] < [constraint priority])
|
|
|
|
{
|
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
[activeConstraints insertObject: constraint
|
|
|
|
atIndex: idx];
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:35:49 +00:00
|
|
|
+ (NSArray *) constraintsWithVisualFormat: (NSString *)fmt
|
|
|
|
options: (NSLayoutFormatOptions)opt
|
|
|
|
metrics: (NSDictionary *)metrics
|
|
|
|
views: (NSDictionary *)views
|
2020-05-10 12:22:12 +00:00
|
|
|
{
|
2020-06-01 06:27:49 +00:00
|
|
|
NSMutableArray *array = [NSMutableArray arrayWithCapacity: 10];
|
|
|
|
return array;
|
2020-05-10 12:22:12 +00:00
|
|
|
}
|
|
|
|
|
2020-06-14 06:31:18 +00:00
|
|
|
// 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];
|
|
|
|
}
|
|
|
|
|
2020-05-10 18:49:06 +00:00
|
|
|
- (instancetype) initWithItem: (id)firstItem
|
|
|
|
attribute: (NSLayoutAttribute)firstAttribute
|
2020-05-10 12:35:49 +00:00
|
|
|
relatedBy: (NSLayoutRelation)relation
|
2020-05-10 18:49:06 +00:00
|
|
|
toItem: (id)secondItem
|
|
|
|
attribute: (NSLayoutAttribute)secondAttribute
|
|
|
|
multiplier: (CGFloat)multiplier
|
|
|
|
constant: (CGFloat)constant;
|
2020-05-10 12:35:49 +00:00
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
2020-05-10 18:49:06 +00:00
|
|
|
_firstItem = firstItem;
|
|
|
|
_secondItem = secondItem;
|
|
|
|
_firstAttribute = firstAttribute;
|
|
|
|
_secondAttribute = secondAttribute;
|
2020-05-10 12:35:49 +00:00
|
|
|
_relation = relation;
|
2020-05-10 18:49:06 +00:00
|
|
|
_multiplier = multiplier;
|
|
|
|
_constant = constant;
|
2020-06-02 08:58:13 +00:00
|
|
|
|
2020-06-03 11:12:31 +00:00
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
|
|
|
selector: @selector(_handleWindowResize:)
|
|
|
|
name: NSWindowDidResizeNotification
|
|
|
|
object: [_firstItem window]];
|
2020-06-14 03:45:08 +00:00
|
|
|
|
|
|
|
NSLog(@"init");
|
|
|
|
[NSLayoutConstraint _addActiveConstraint: self];
|
2020-05-10 12:35:49 +00:00
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:22:12 +00:00
|
|
|
// Active
|
|
|
|
- (BOOL) isActive
|
|
|
|
{
|
|
|
|
return [activeConstraints containsObject: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setActive: (BOOL)flag
|
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
{
|
2020-06-14 03:45:08 +00:00
|
|
|
[NSLayoutConstraint _addActiveConstraint: self];
|
2020-05-10 12:22:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[activeConstraints removeObject: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-14 06:31:18 +00:00
|
|
|
// compare and isEqual...
|
|
|
|
- (NSComparisonResult) compare: (NSLayoutConstraint *)constraint
|
2020-06-14 03:45:08 +00:00
|
|
|
{
|
|
|
|
if ([self priority] < [constraint priority])
|
|
|
|
{
|
|
|
|
return NSOrderedAscending;
|
|
|
|
}
|
|
|
|
else if ([self priority] > [constraint priority])
|
|
|
|
{
|
|
|
|
return NSOrderedDescending;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NSOrderedSame;
|
|
|
|
}
|
|
|
|
|
2020-06-14 06:31:18 +00:00
|
|
|
- (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;
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:22:12 +00:00
|
|
|
// Items
|
|
|
|
- (id) firstItem
|
|
|
|
{
|
|
|
|
return _firstItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLayoutAttribute) firstAttribute
|
|
|
|
{
|
|
|
|
return _firstAttribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLayoutRelation) relation
|
|
|
|
{
|
|
|
|
return _relation;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) secondItem
|
|
|
|
{
|
|
|
|
return _secondItem;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLayoutAttribute) secondAttribute
|
|
|
|
{
|
|
|
|
return _secondAttribute;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat) multiplier
|
|
|
|
{
|
|
|
|
return _multiplier;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (CGFloat) constant
|
|
|
|
{
|
|
|
|
return _constant;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLayoutAnchor *) firstAnchor
|
|
|
|
{
|
|
|
|
return _firstAnchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLayoutAnchor *) secondAnchor
|
|
|
|
{
|
|
|
|
return _secondAnchor;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSLayoutPriority) priority
|
|
|
|
{
|
|
|
|
return _priority;
|
|
|
|
}
|
2020-05-10 06:26:06 +00:00
|
|
|
|
2020-06-09 11:34:40 +00:00
|
|
|
- (void) setPriority: (NSLayoutPriority)priority
|
|
|
|
{
|
|
|
|
_priority = priority;
|
|
|
|
}
|
|
|
|
|
2020-05-10 18:49:06 +00:00
|
|
|
// Coding...
|
|
|
|
- (instancetype) initWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
if ([coder allowsKeyedCoding])
|
|
|
|
{
|
|
|
|
if ([coder containsValueForKey: @"NSConstant"])
|
|
|
|
{
|
|
|
|
_constant = [coder decodeFloatForKey: @"NSConstant"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([coder containsValueForKey: @"NSFirstAttribute"])
|
|
|
|
{
|
|
|
|
_firstAttribute = [coder decodeIntegerForKey: @"NSFirstAttribute"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([coder containsValueForKey: @"NSFirstItem"])
|
|
|
|
{
|
|
|
|
_firstItem = [coder decodeObjectForKey: @"NSFirstItem"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([coder containsValueForKey: @"NSSecondAttribute"])
|
|
|
|
{
|
|
|
|
_secondAttribute = [coder decodeIntegerForKey: @"NSSecondAttribute"];
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([coder containsValueForKey: @"NSSecondItem"])
|
|
|
|
{
|
|
|
|
_secondItem = [coder decodeObjectForKey: @"NSSecondItem"];
|
|
|
|
}
|
2020-06-09 11:27:06 +00:00
|
|
|
|
|
|
|
if ([coder containsValueForKey: @"NSPriority"])
|
|
|
|
{
|
2020-06-09 11:34:40 +00:00
|
|
|
_priority = [coder decodeFloatForKey: @"NSPriority"];
|
2020-06-09 11:27:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-06-09 11:34:40 +00:00
|
|
|
_priority = NSLayoutPriorityRequired; // if it is not present, this defaults to 1000... per testing with Cocoa.
|
2020-06-09 11:27:06 +00:00
|
|
|
}
|
2020-05-10 18:49:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-10 19:03:31 +00:00
|
|
|
[coder decodeValueOfObjCType: @encode(float)
|
|
|
|
at: &_constant];
|
|
|
|
[coder decodeValueOfObjCType: @encode(NSUInteger)
|
|
|
|
at: &_firstAttribute];
|
|
|
|
_firstItem = [coder decodeObject];
|
2020-06-09 11:34:40 +00:00
|
|
|
[coder decodeValueOfObjCType: @encode(NSUInteger)
|
2020-05-10 19:03:31 +00:00
|
|
|
at: &_secondAttribute];
|
|
|
|
_secondItem = [coder decodeObject];
|
2020-06-09 11:34:40 +00:00
|
|
|
[coder decodeValueOfObjCType: @encode(float)
|
2020-06-09 11:27:06 +00:00
|
|
|
at: &_priority];
|
2020-05-10 18:49:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-06-03 11:12:31 +00:00
|
|
|
|
|
|
|
[[NSNotificationCenter defaultCenter] addObserver: self
|
|
|
|
selector: @selector(_handleWindowResize:)
|
|
|
|
name: NSWindowDidResizeNotification
|
|
|
|
object: [_firstItem window]];
|
2020-06-14 03:45:08 +00:00
|
|
|
[NSLayoutConstraint _addActiveConstraint: self];
|
2020-06-01 06:27:49 +00:00
|
|
|
|
2020-05-10 18:49:06 +00:00
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
- (void) encodeWithCoder: (NSCoder *)coder
|
|
|
|
{
|
|
|
|
if ([coder allowsKeyedCoding])
|
|
|
|
{
|
2020-05-10 19:03:31 +00:00
|
|
|
[coder encodeFloat: _constant
|
|
|
|
forKey: @"NSConstant"];
|
|
|
|
[coder encodeInteger: _firstAttribute
|
|
|
|
forKey: @"NSFirstAttribute"];
|
|
|
|
[coder encodeObject: _firstItem
|
|
|
|
forKey: @"NSFirstItem"];
|
|
|
|
[coder encodeInteger: _secondAttribute
|
|
|
|
forKey: @"NSSecondAttribute"];
|
|
|
|
[coder encodeObject: _secondItem
|
|
|
|
forKey: @"NSSecondItem"];
|
2020-06-09 11:34:40 +00:00
|
|
|
[coder encodeFloat: _priority
|
2020-06-09 11:27:06 +00:00
|
|
|
forKey: @"NSPriority"];
|
2020-05-10 18:49:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2020-05-10 19:03:31 +00:00
|
|
|
[coder encodeValueOfObjCType: @encode(float)
|
|
|
|
at: &_constant];
|
|
|
|
[coder encodeValueOfObjCType: @encode(NSUInteger)
|
|
|
|
at: &_firstAttribute];
|
|
|
|
[coder encodeObject: _firstItem];
|
2020-06-09 11:34:40 +00:00
|
|
|
[coder encodeValueOfObjCType: @encode(NSUInteger)
|
2020-05-10 19:03:31 +00:00
|
|
|
at: &_secondAttribute];
|
|
|
|
[coder encodeObject: _secondItem];
|
2020-06-09 11:34:40 +00:00
|
|
|
[coder encodeValueOfObjCType: @encode(float)
|
2020-06-09 11:27:06 +00:00
|
|
|
at: &_priority];
|
2020-05-10 18:49:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (id) copyWithZone: (NSZone *)z
|
|
|
|
{
|
|
|
|
NSLayoutConstraint *constraint = [[NSLayoutConstraint allocWithZone: z]
|
|
|
|
initWithItem: _firstItem
|
|
|
|
attribute: _firstAttribute
|
|
|
|
relatedBy: _relation
|
|
|
|
toItem: _secondItem
|
|
|
|
attribute: _secondAttribute
|
|
|
|
multiplier: _multiplier
|
|
|
|
constant: _constant];
|
2020-06-09 11:34:40 +00:00
|
|
|
[constraint setPriority: [self priority]];
|
2020-05-10 18:49:06 +00:00
|
|
|
return constraint;
|
|
|
|
}
|
|
|
|
|
2020-06-01 06:27:49 +00:00
|
|
|
- (void) dealloc
|
|
|
|
{
|
|
|
|
[activeConstraints removeObject: self];
|
|
|
|
[super dealloc];
|
|
|
|
}
|
|
|
|
|
2020-05-26 19:06:28 +00:00
|
|
|
- (NSString *) description
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat: @"%@ <firstItem = %@, firstAttribute = %ld, relation = %ld, secondItem = %@, "
|
2020-06-14 03:45:08 +00:00
|
|
|
"secondAttribute = %ld, multiplier = %f, constant = %f, priority = %f>",
|
2020-05-26 19:06:28 +00:00
|
|
|
[super description],
|
|
|
|
_firstItem,
|
|
|
|
_firstAttribute,
|
|
|
|
_relation,
|
|
|
|
_secondItem,
|
|
|
|
_secondAttribute,
|
|
|
|
_multiplier,
|
2020-06-14 03:45:08 +00:00
|
|
|
_constant,
|
|
|
|
_priority];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _applyConstraint
|
|
|
|
{
|
|
|
|
NSLog(@"activeConstraints = %@", activeConstraints);
|
2020-05-26 19:06:28 +00:00
|
|
|
}
|
|
|
|
|
2020-06-03 11:12:31 +00:00
|
|
|
- (void) _handleWindowResize: (NSNotification *)notification
|
|
|
|
{
|
2020-06-14 03:45:08 +00:00
|
|
|
NSLayoutConstraint *c = nil;
|
|
|
|
NSEnumerator *en = [activeConstraints objectEnumerator];
|
|
|
|
|
|
|
|
while ((c = [en nextObject]) != nil)
|
|
|
|
{
|
|
|
|
[c _applyConstraint];
|
|
|
|
}
|
2020-06-03 11:12:31 +00:00
|
|
|
}
|
|
|
|
|
2020-05-10 06:26:06 +00:00
|
|
|
@end
|
|
|
|
|