Skip to content

Commit 866db51

Browse files
committedJul 22, 2013
initial commit
0 parents  commit 866db51

40 files changed

+2716
-0
lines changed
 

‎.gitignore

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Xcode
2+
build/*
3+
*.pbxuser
4+
!default.pbxuser
5+
*.mode1v3
6+
!default.mode1v3
7+
*.mode2v3
8+
!default.mode2v3
9+
*.perspectivev3
10+
!default.perspectivev3
11+
*.xcworkspace
12+
!default.xcworkspace
13+
xcuserdata
14+
profile
15+
*.moved-aside
16+
# Desktop Servies
17+
.DS_Store
18+
Podfile.lock
19+
/Pods/

‎Masonry.xcodeproj/project.pbxproj

Lines changed: 553 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Scheme
3+
LastUpgradeVersion = "0460"
4+
version = "1.3">
5+
<BuildAction
6+
parallelizeBuildables = "YES"
7+
buildImplicitDependencies = "YES">
8+
<BuildActionEntries>
9+
<BuildActionEntry
10+
buildForTesting = "YES"
11+
buildForRunning = "YES"
12+
buildForProfiling = "YES"
13+
buildForArchiving = "YES"
14+
buildForAnalyzing = "YES">
15+
<BuildableReference
16+
BuildableIdentifier = "primary"
17+
BlueprintIdentifier = "DD52F1A9179CA93B005CD195"
18+
BuildableName = "libMasonry.a"
19+
BlueprintName = "Masonry"
20+
ReferencedContainer = "container:Masonry.xcodeproj">
21+
</BuildableReference>
22+
</BuildActionEntry>
23+
</BuildActionEntries>
24+
</BuildAction>
25+
<TestAction
26+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
27+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
28+
shouldUseLaunchSchemeArgsEnv = "YES"
29+
buildConfiguration = "Debug">
30+
<Testables>
31+
<TestableReference
32+
skipped = "NO">
33+
<BuildableReference
34+
BuildableIdentifier = "primary"
35+
BlueprintIdentifier = "DD52F1BA179CA93B005CD195"
36+
BuildableName = "MasonryTests.octest"
37+
BlueprintName = "MasonryTests"
38+
ReferencedContainer = "container:Masonry.xcodeproj">
39+
</BuildableReference>
40+
</TestableReference>
41+
</Testables>
42+
</TestAction>
43+
<LaunchAction
44+
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
45+
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
46+
launchStyle = "0"
47+
useCustomWorkingDirectory = "NO"
48+
buildConfiguration = "Debug"
49+
ignoresPersistentStateOnLaunch = "NO"
50+
debugDocumentVersioning = "YES"
51+
allowLocationSimulation = "YES">
52+
<AdditionalOptions>
53+
</AdditionalOptions>
54+
</LaunchAction>
55+
<ProfileAction
56+
shouldUseLaunchSchemeArgsEnv = "YES"
57+
savedToolIdentifier = ""
58+
useCustomWorkingDirectory = "NO"
59+
buildConfiguration = "Release"
60+
debugDocumentVersioning = "YES">
61+
</ProfileAction>
62+
<AnalyzeAction
63+
buildConfiguration = "Debug">
64+
</AnalyzeAction>
65+
<ArchiveAction
66+
buildConfiguration = "Release"
67+
revealArchiveInOrganizer = "YES">
68+
</ArchiveAction>
69+
</Scheme>

‎Masonry/MASCompositeConstraint.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//
2+
// MASCompositeConstraint.h
3+
// Masonry
4+
//
5+
// Created by Jonas Budelmann on 21/07/13.
6+
// Copyright (c) 2013 cloudling. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "MASConstraint.h"
11+
12+
typedef NS_ENUM(NSInteger, MASCompositeViewConstraintType) {
13+
MASCompositeViewConstraintTypeSides,
14+
MASCompositeViewConstraintTypeSize,
15+
MASCompositeViewConstraintTypeCenter,
16+
};
17+
18+
@interface MASCompositeConstraint : NSObject <MASConstraint>
19+
20+
@property (nonatomic, weak) id<MASConstraintDelegate> delegate;
21+
@property (nonatomic, strong, readonly) UIView *view;
22+
@property (nonatomic, assign, readonly) MASCompositeViewConstraintType type;
23+
24+
- (id)initWithView:(UIView *)view type:(MASCompositeViewConstraintType)type;
25+
26+
@end

‎Masonry/MASCompositeConstraint.m

Lines changed: 177 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,177 @@
1+
//
2+
// MASCompositeConstraint.m
3+
// Masonry
4+
//
5+
// Created by Jonas Budelmann on 21/07/13.
6+
// Copyright (c) 2013 cloudling. All rights reserved.
7+
//
8+
9+
#import "MASCompositeConstraint.h"
10+
#import "UIView+MASAdditions.h"
11+
#import "MASViewConstraint.h"
12+
13+
@interface MASCompositeConstraint () <MASConstraintDelegate>
14+
15+
@property (nonatomic, strong) NSMutableArray *completedChildConstraints;
16+
@property (nonatomic, strong) NSMutableArray *currentChildConstraints;
17+
18+
@end
19+
20+
@implementation MASCompositeConstraint
21+
22+
- (id)initWithView:(UIView *)view type:(MASCompositeViewConstraintType)type {
23+
self = [super init];
24+
if (!self) return nil;
25+
26+
_view = view;
27+
_type = type;
28+
29+
self.completedChildConstraints = NSMutableArray.array;
30+
[self createChildren];
31+
32+
return self;
33+
}
34+
35+
- (void)createChildren {
36+
self.currentChildConstraints = NSMutableArray.array;
37+
38+
NSArray *viewAttributes;
39+
switch (self.type) {
40+
case MASCompositeViewConstraintTypeSides:
41+
viewAttributes = @[
42+
self.view.mas_left, self.view.mas_top,
43+
self.view.mas_bottom, self.view.mas_right
44+
];
45+
break;
46+
case MASCompositeViewConstraintTypeSize:
47+
viewAttributes = @[
48+
self.view.mas_width, self.view.mas_height
49+
];
50+
break;
51+
case MASCompositeViewConstraintTypeCenter:
52+
viewAttributes = @[
53+
self.view.mas_centerX, self.view.mas_centerY
54+
];
55+
break;
56+
}
57+
58+
for (MASViewAttribute *viewAttribute in viewAttributes) {
59+
MASViewConstraint *child = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
60+
child.delegate = self;
61+
[self.currentChildConstraints addObject:child];
62+
}
63+
}
64+
65+
#pragma mark - MASConstraintDelegate
66+
67+
- (void)addConstraint:(id<MASConstraint>)constraint {
68+
//TODO fixme
69+
if (![self.currentChildConstraints containsObject:constraint]) {
70+
[self.currentChildConstraints addObject:constraint];
71+
}
72+
}
73+
74+
#pragma mark - layout constant
75+
76+
- (id<MASConstraint> (^)(UIEdgeInsets))insets {
77+
return ^id(UIEdgeInsets insets) {
78+
for (id<MASConstraint> constraint in self.currentChildConstraints) {
79+
constraint.insets(insets);
80+
}
81+
return self;
82+
};
83+
}
84+
85+
- (id<MASConstraint> (^)(CGFloat))offset {
86+
return ^id(CGFloat offset) {
87+
for (id<MASConstraint> constraint in self.currentChildConstraints) {
88+
constraint.offset(offset);
89+
}
90+
return self;
91+
};
92+
}
93+
94+
- (id<MASConstraint> (^)(CGSize))sizeOffset {
95+
return ^id(CGSize offset) {
96+
for (id<MASConstraint> constraint in self.currentChildConstraints) {
97+
constraint.sizeOffset(offset);
98+
}
99+
return self;
100+
};
101+
}
102+
103+
- (id<MASConstraint> (^)(CGPoint))centerOffset {
104+
return ^id(CGPoint offset) {
105+
for (id<MASConstraint> constraint in self.currentChildConstraints) {
106+
constraint.centerOffset(offset);
107+
}
108+
return self;
109+
};
110+
}
111+
112+
#pragma mark - layout multiplier
113+
114+
- (id<MASConstraint> (^)(CGFloat))percent {
115+
return ^id(CGFloat percent) {
116+
for (id<MASConstraint> constraint in self.currentChildConstraints) {
117+
constraint.percent(percent);
118+
}
119+
return self;
120+
};
121+
}
122+
123+
#pragma mark - layout priority
124+
125+
- (id<MASConstraint> (^)(UILayoutPriority))priority {
126+
return ^id(UILayoutPriority priority) {
127+
for (id<MASConstraint> constraint in self.currentChildConstraints) {
128+
constraint.priority(priority);
129+
}
130+
return self;
131+
};
132+
}
133+
134+
#pragma mark - layout relation
135+
136+
- (id<MASConstraint> (^)(id))equalityWithBlock:(id<MASConstraint> (^)(id<MASConstraint> constraint, id attr))block {
137+
return ^id(id attr) {
138+
[self.delegate addConstraint:self]; //TODO make sure we dont add more than once
139+
for (id<MASConstraint> constraint in self.currentChildConstraints.copy) {
140+
//TODO fixme
141+
id<MASConstraint> newConstraint = block(constraint, attr);
142+
//if (newConstraint != constraint) { //TODO fix
143+
//[self.currentChildConstraints removeObject:constraint];
144+
[self.completedChildConstraints addObject:newConstraint];
145+
//}
146+
}
147+
return self;
148+
};
149+
}
150+
151+
- (id<MASConstraint> (^)(id))equal {
152+
return [self equalityWithBlock:^id(id<MASConstraint> constraint, id attr) {
153+
return constraint.equal(attr);
154+
}];
155+
}
156+
157+
- (id<MASConstraint> (^)(id))greaterThanOrEqual {
158+
return [self equalityWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) {
159+
return constraint.greaterThanOrEqual(attr);
160+
}];
161+
}
162+
163+
- (id<MASConstraint> (^)(id))lessThanOrEqual {
164+
return [self equalityWithBlock:^id<MASConstraint>(id<MASConstraint> constraint, id attr) {
165+
return constraint.lessThanOrEqual(attr);
166+
}];
167+
}
168+
169+
#pragma mark - MASConstraint
170+
171+
- (void)commit {
172+
for (id<MASConstraint> constraint in self.completedChildConstraints) {
173+
[constraint commit];
174+
}
175+
}
176+
177+
@end

‎Masonry/MASConstraint.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//
2+
// MASConstraint.h
3+
// Masonry
4+
//
5+
// Created by Jonas Budelmann on 22/07/13.
6+
// Copyright (c) 2013 cloudling. All rights reserved.
7+
//
8+
9+
#import <Foundation/Foundation.h>
10+
11+
@protocol MASConstraint <NSObject>
12+
13+
@property (nonatomic, strong, readonly) id<MASConstraint> (^insets)(UIEdgeInsets insets);
14+
@property (nonatomic, strong, readonly) id<MASConstraint> (^sizeOffset)(CGSize offset);
15+
@property (nonatomic, strong, readonly) id<MASConstraint> (^centerOffset)(CGPoint offset);
16+
@property (nonatomic, strong, readonly) id<MASConstraint> (^offset)(CGFloat offset);
17+
@property (nonatomic, strong, readonly) id<MASConstraint> (^percent)(CGFloat percent);
18+
@property (nonatomic, strong, readonly) id<MASConstraint> (^priority)(UILayoutPriority priority);
19+
@property (nonatomic, strong, readonly) id<MASConstraint> (^equal)(id attr);
20+
@property (nonatomic, strong, readonly) id<MASConstraint> (^greaterThanOrEqual)(id attr);
21+
@property (nonatomic, strong, readonly) id<MASConstraint> (^lessThanOrEqual)(id attr);
22+
23+
- (void)commit;
24+
25+
@end
26+
27+
@protocol MASConstraintDelegate <NSObject>
28+
29+
- (void)addConstraint:(id<MASConstraint>)constraint;
30+
31+
@end

‎Masonry/MASConstraintBuilder.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
//
2+
// MASConstraintBuilder.h
3+
// Masonry
4+
//
5+
// Created by Jonas Budelmann on 20/07/13.
6+
// Copyright (c) 2013 cloudling. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import "MASConstraint.h"
11+
12+
@interface MASConstraintBuilder : NSObject
13+
14+
@property (nonatomic, strong, readonly) id<MASConstraint> left;
15+
@property (nonatomic, strong, readonly) id<MASConstraint> top;
16+
@property (nonatomic, strong, readonly) id<MASConstraint> right;
17+
@property (nonatomic, strong, readonly) id<MASConstraint> bottom;
18+
@property (nonatomic, strong, readonly) id<MASConstraint> leading;
19+
@property (nonatomic, strong, readonly) id<MASConstraint> trailing;
20+
@property (nonatomic, strong, readonly) id<MASConstraint> width;
21+
@property (nonatomic, strong, readonly) id<MASConstraint> height;
22+
@property (nonatomic, strong, readonly) id<MASConstraint> centerX;
23+
@property (nonatomic, strong, readonly) id<MASConstraint> centerY;
24+
@property (nonatomic, strong, readonly) id<MASConstraint> baseline;
25+
26+
@property (nonatomic, strong, readonly) id<MASConstraint> sides;
27+
@property (nonatomic, strong, readonly) id<MASConstraint> size;
28+
@property (nonatomic, strong, readonly) id<MASConstraint> center;
29+
30+
- (id)initWithView:(UIView *)view;
31+
- (void)commit;
32+
33+
@end

0 commit comments

Comments
 (0)
Please sign in to comment.