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>
|
|
|
|
|
|
|
|
#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-05-10 12:22:12 +00:00
|
|
|
static NSMutableArray *activeConstraints;
|
|
|
|
|
2020-05-10 06:26:06 +00:00
|
|
|
@implementation NSLayoutConstraint
|
2020-05-10 12:41:10 +00:00
|
|
|
|
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
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
2020-05-10 12:35:49 +00:00
|
|
|
- (instancetype) initWithItem: (id)view1
|
|
|
|
attribute: (NSLayoutAttribute)attr1
|
|
|
|
relatedBy: (NSLayoutRelation)relation
|
|
|
|
toItem: (id)view2
|
|
|
|
attribute: (NSLayoutAttribute)attr2
|
|
|
|
multiplier: (CGFloat)mult
|
|
|
|
constant: (CGFloat)c;
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
_firstItem = view1;
|
|
|
|
_secondItem = view2;
|
|
|
|
_firstAttribute = attr1;
|
|
|
|
_secondAttribute = attr2;
|
|
|
|
_relation = relation;
|
|
|
|
_multiplier = mult;
|
|
|
|
_constant = c;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Designated initializer...
|
2020-05-10 12:22:12 +00:00
|
|
|
+ (instancetype) constraintWithItem: (id)view1
|
|
|
|
attribute: (NSLayoutAttribute)attr1
|
|
|
|
relatedBy: (NSLayoutRelation)relation
|
|
|
|
toItem: (id)view2
|
|
|
|
attribute: (NSLayoutAttribute)attr2
|
|
|
|
multiplier: (CGFloat)mult
|
|
|
|
constant: (CGFloat)c
|
|
|
|
{
|
2020-05-10 12:35:49 +00:00
|
|
|
NSLayoutConstraint *constraint =
|
|
|
|
[[NSLayoutConstraint alloc] initWithItem: view1
|
|
|
|
attribute: attr1
|
|
|
|
relatedBy: relation
|
|
|
|
toItem: view2
|
|
|
|
attribute: attr2
|
|
|
|
multiplier: mult
|
|
|
|
constant: c];
|
|
|
|
AUTORELEASE(constraint);
|
|
|
|
return constraint;
|
2020-05-10 12:22:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Active
|
|
|
|
- (BOOL) isActive
|
|
|
|
{
|
|
|
|
return [activeConstraints containsObject: self];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setActive: (BOOL)flag
|
|
|
|
{
|
|
|
|
if (flag)
|
|
|
|
{
|
|
|
|
[activeConstraints addObject: self];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[activeConstraints removeObject: self];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) activateConstraints: (NSArray *)constraints
|
|
|
|
{
|
|
|
|
[activeConstraints addObjectsFromArray: constraints];
|
|
|
|
}
|
|
|
|
|
|
|
|
+ (void) deactivateConstraints: (NSArray *)constraints
|
|
|
|
{
|
|
|
|
[activeConstraints removeObjectsInArray: constraints];
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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
|
|
|
|
|
|
|
@end
|
|
|
|
|