Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 866db51
Showing
40 changed files
with
2,716 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Xcode | ||
build/* | ||
*.pbxuser | ||
!default.pbxuser | ||
*.mode1v3 | ||
!default.mode1v3 | ||
*.mode2v3 | ||
!default.mode2v3 | ||
*.perspectivev3 | ||
!default.perspectivev3 | ||
*.xcworkspace | ||
!default.xcworkspace | ||
xcuserdata | ||
profile | ||
*.moved-aside | ||
# Desktop Servies | ||
.DS_Store | ||
Podfile.lock | ||
/Pods/ |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<Scheme | ||
LastUpgradeVersion = "0460" | ||
version = "1.3"> | ||
<BuildAction | ||
parallelizeBuildables = "YES" | ||
buildImplicitDependencies = "YES"> | ||
<BuildActionEntries> | ||
<BuildActionEntry | ||
buildForTesting = "YES" | ||
buildForRunning = "YES" | ||
buildForProfiling = "YES" | ||
buildForArchiving = "YES" | ||
buildForAnalyzing = "YES"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "DD52F1A9179CA93B005CD195" | ||
BuildableName = "libMasonry.a" | ||
BlueprintName = "Masonry" | ||
ReferencedContainer = "container:Masonry.xcodeproj"> | ||
</BuildableReference> | ||
</BuildActionEntry> | ||
</BuildActionEntries> | ||
</BuildAction> | ||
<TestAction | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
buildConfiguration = "Debug"> | ||
<Testables> | ||
<TestableReference | ||
skipped = "NO"> | ||
<BuildableReference | ||
BuildableIdentifier = "primary" | ||
BlueprintIdentifier = "DD52F1BA179CA93B005CD195" | ||
BuildableName = "MasonryTests.octest" | ||
BlueprintName = "MasonryTests" | ||
ReferencedContainer = "container:Masonry.xcodeproj"> | ||
</BuildableReference> | ||
</TestableReference> | ||
</Testables> | ||
</TestAction> | ||
<LaunchAction | ||
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" | ||
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" | ||
launchStyle = "0" | ||
useCustomWorkingDirectory = "NO" | ||
buildConfiguration = "Debug" | ||
ignoresPersistentStateOnLaunch = "NO" | ||
debugDocumentVersioning = "YES" | ||
allowLocationSimulation = "YES"> | ||
<AdditionalOptions> | ||
</AdditionalOptions> | ||
</LaunchAction> | ||
<ProfileAction | ||
shouldUseLaunchSchemeArgsEnv = "YES" | ||
savedToolIdentifier = "" | ||
useCustomWorkingDirectory = "NO" | ||
buildConfiguration = "Release" | ||
debugDocumentVersioning = "YES"> | ||
</ProfileAction> | ||
<AnalyzeAction | ||
buildConfiguration = "Debug"> | ||
</AnalyzeAction> | ||
<ArchiveAction | ||
buildConfiguration = "Release" | ||
revealArchiveInOrganizer = "YES"> | ||
</ArchiveAction> | ||
</Scheme> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// | ||
// MASCompositeConstraint.h | ||
// Masonry | ||
// | ||
// Created by Jonas Budelmann on 21/07/13. | ||
// Copyright (c) 2013 cloudling. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "MASConstraint.h" | ||
|
||
typedef NS_ENUM(NSInteger, MASCompositeViewConstraintType) { | ||
MASCompositeViewConstraintTypeSides, | ||
MASCompositeViewConstraintTypeSize, | ||
MASCompositeViewConstraintTypeCenter, | ||
}; | ||
|
||
@interface MASCompositeConstraint : NSObject <MASConstraint> | ||
|
||
@property (nonatomic, weak) id<MASConstraintDelegate> delegate; | ||
@property (nonatomic, strong, readonly) UIView *view; | ||
@property (nonatomic, assign, readonly) MASCompositeViewConstraintType type; | ||
|
||
- (id)initWithView:(UIView *)view type:(MASCompositeViewConstraintType)type; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
// | ||
// MASCompositeConstraint.m | ||
// Masonry | ||
// | ||
// Created by Jonas Budelmann on 21/07/13. | ||
// Copyright (c) 2013 cloudling. All rights reserved. | ||
// | ||
|
||
#import "MASCompositeConstraint.h" | ||
#import "UIView+MASAdditions.h" | ||
#import "MASViewConstraint.h" | ||
|
||
@interface MASCompositeConstraint () <MASConstraintDelegate> | ||
|
||
@property (nonatomic, strong) NSMutableArray *completedChildConstraints; | ||
@property (nonatomic, strong) NSMutableArray *currentChildConstraints; | ||
|
||
@end | ||
|
||
@implementation MASCompositeConstraint | ||
|
||
- (id)initWithView:(UIView *)view type:(MASCompositeViewConstraintType)type { | ||
self = [super init]; | ||
if (!self) return nil; | ||
|
||
_view = view; | ||
_type = type; | ||
|
||
self.completedChildConstraints = NSMutableArray.array; | ||
[self createChildren]; | ||
|
||
return self; | ||
} | ||
|
||
- (void)createChildren { | ||
self.currentChildConstraints = NSMutableArray.array; | ||
|
||
NSArray *viewAttributes; | ||
switch (self.type) { | ||
case MASCompositeViewConstraintTypeSides: | ||
viewAttributes = @[ | ||
self.view.mas_left, self.view.mas_top, | ||
self.view.mas_bottom, self.view.mas_right | ||
]; | ||
break; | ||
case MASCompositeViewConstraintTypeSize: | ||
viewAttributes = @[ | ||
self.view.mas_width, self.view.mas_height | ||
]; | ||
break; | ||
case MASCompositeViewConstraintTypeCenter: | ||
viewAttributes = @[ | ||
self.view.mas_centerX, self.view.mas_centerY | ||
]; | ||
break; | ||
} | ||
|
||
for (MASViewAttribute *viewAttribute in viewAttributes) { | ||
MASViewConstraint *child = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute]; | ||
child.delegate = self; | ||
[self.currentChildConstraints addObject:child]; | ||
} | ||
} | ||
|
||
#pragma mark - MASConstraintDelegate | ||
|
||
- (void)addConstraint:(id<MASConstraint>)constraint { | ||
//TODO fixme | ||
if (![self.currentChildConstraints containsObject:constraint]) { | ||
[self.currentChildConstraints addObject:constraint]; | ||
} | ||
} | ||
|
||
#pragma mark - layout constant | ||
|
||
- (id<MASConstraint> (^)(UIEdgeInsets))insets { | ||
return ^id(UIEdgeInsets insets) { | ||
for (id<MASConstraint> constraint in self.currentChildConstraints) { | ||
constraint.insets(insets); | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
- (id<MASConstraint> (^)(CGFloat))offset { | ||
return ^id(CGFloat offset) { | ||
for (id<MASConstraint> constraint in self.currentChildConstraints) { | ||
constraint.offset(offset); | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
- (id<MASConstraint> (^)(CGSize))sizeOffset { | ||
return ^id(CGSize offset) { | ||
for (id<MASConstraint> constraint in self.currentChildConstraints) { | ||
constraint.sizeOffset(offset); | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
- (id<MASConstraint> (^)(CGPoint))centerOffset { | ||
return ^id(CGPoint offset) { | ||
for (id<MASConstraint> constraint in self.currentChildConstraints) { | ||
constraint.centerOffset(offset); | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
#pragma mark - layout multiplier | ||
|
||
- (id<MASConstraint> (^)(CGFloat))percent { | ||
return ^id(CGFloat percent) { | ||
for (id<MASConstraint> constraint in self.currentChildConstraints) { | ||
constraint.percent(percent); | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
#pragma mark - layout priority | ||
|
||
- (id<MASConstraint> (^)(UILayoutPriority))priority { | ||
return ^id(UILayoutPriority priority) { | ||
for (id<MASConstraint> constraint in self.currentChildConstraints) { | ||
constraint.priority(priority); | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
#pragma mark - layout relation | ||
|
||
- (id<MASConstraint> (^)(id))equalityWithBlock:(id<MASConstraint> (^)(id<MASConstraint> constraint, id attr))block { | ||
return ^id(id attr) { | ||
[self.delegate addConstraint:self]; //TODO make sure we dont add more than once | ||
for (id<MASConstraint> constraint in self.currentChildConstraints.copy) { | ||
//TODO fixme | ||
id<MASConstraint> newConstraint = block(constraint, attr); | ||
//if (newConstraint != constraint) { //TODO fix | ||
//[self.currentChildConstraints removeObject:constraint]; | ||
[self.completedChildConstraints addObject:newConstraint]; | ||
//} | ||
} | ||
return self; | ||
}; | ||
} | ||
|
||
- (id<MASConstraint> (^)(id))equal { | ||
return [self equalityWithBlock:^id(id<MASConstraint> constraint, id attr) { | ||
return constraint.equal(attr); | ||
}]; | ||
} | ||
|
||
- (id<MASConstraint> (^)(id))greaterThanOrEqual { | ||
return [self equalityWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) { | ||
return constraint.greaterThanOrEqual(attr); | ||
}]; | ||
} | ||
|
||
- (id<MASConstraint> (^)(id))lessThanOrEqual { | ||
return [self equalityWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) { | ||
return constraint.lessThanOrEqual(attr); | ||
}]; | ||
} | ||
|
||
#pragma mark - MASConstraint | ||
|
||
- (void)commit { | ||
for (id<MASConstraint> constraint in self.completedChildConstraints) { | ||
[constraint commit]; | ||
} | ||
} | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// | ||
// MASConstraint.h | ||
// Masonry | ||
// | ||
// Created by Jonas Budelmann on 22/07/13. | ||
// Copyright (c) 2013 cloudling. All rights reserved. | ||
// | ||
|
||
#import <Foundation/Foundation.h> | ||
|
||
@protocol MASConstraint <NSObject> | ||
|
||
@property (nonatomic, strong, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^offset)(CGFloat offset); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^percent)(CGFloat percent); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^priority)(UILayoutPriority priority); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^equal)(id attr); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^greaterThanOrEqual)(id attr); | ||
@property (nonatomic, strong, readonly) id<MASConstraint> (^lessThanOrEqual)(id attr); | ||
|
||
- (void)commit; | ||
|
||
@end | ||
|
||
@protocol MASConstraintDelegate <NSObject> | ||
|
||
- (void)addConstraint:(id<MASConstraint>)constraint; | ||
|
||
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// MASConstraintBuilder.h | ||
// Masonry | ||
// | ||
// Created by Jonas Budelmann on 20/07/13. | ||
// Copyright (c) 2013 cloudling. All rights reserved. | ||
// | ||
|
||
#import <UIKit/UIKit.h> | ||
#import "MASConstraint.h" | ||
|
||
@interface MASConstraintBuilder : NSObject | ||
|
||
@property (nonatomic, strong, readonly) id<MASConstraint> left; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> top; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> right; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> bottom; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> leading; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> trailing; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> width; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> height; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> centerX; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> centerY; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> baseline; | ||
|
||
@property (nonatomic, strong, readonly) id<MASConstraint> sides; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> size; | ||
@property (nonatomic, strong, readonly) id<MASConstraint> center; | ||
|
||
- (id)initWithView:(UIView *)view; | ||
- (void)commit; | ||
|
||
@end |
Oops, something went wrong.