Started some Auto Layout utility functions.

This commit is contained in:
Pietro Gagliardi 2015-08-15 17:05:48 -04:00
parent cfd50c16d9
commit f8fbcb3dfb
1 changed files with 33 additions and 0 deletions

View File

@ -0,0 +1,33 @@
// 15 august 2015
#import "uipriv_darwin.h"
void addConstraint(NSView *view, NSString *constraint, NSDictionary *metrics, NSDictionary *views)
{
NSArray *constraints;
constraints = [NSLayoutConstraint constraintsWithVisualFormat:constraint
options:0
metrics:metrics
views:views];
[view addConstraints:constraints];
}
void layoutSingleView(NSView *superview, NSView *subview, int margined)
{
NSDictionary *views;
NSString *constraint;
[superview removeConstraints:[superview constraints]];
views = NSDictionaryOfVariableBindings(subview);
constraint = @"H:|[subview]|";
if (margined)
constraint = @"H:|-[subview]-|";
addConstraint(superview, constraint, nil, views);
constraint = @"V:|[subview]|";
if (margined)
constraint = @"V:|-[subview]-|";
addConstraint(superview, constraint, nil, views);
}