forked from davedelong/CHLayoutManager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CHLayoutManagerAppDelegate.m
98 lines (73 loc) · 5.21 KB
/
CHLayoutManagerAppDelegate.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
//
// CHLayoutManagerAppDelegate.m
// CHLayoutManager
/**
Copyright (c) 2010 Dave DeLong
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
**/
#import "CHLayoutManagerAppDelegate.h"
#import "CHLayout.h"
#import "SinTransformer.h"
@implementation CHLayoutManagerAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification {
// Insert code here to initialize your application
[button1 setLayoutName:@"button1"];
[button2 addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMinX relativeTo:@"button1" attribute:CHLayoutConstraintAttributeMaxX]];
[button2 addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMaxY relativeTo:@"button1" attribute:CHLayoutConstraintAttributeMaxY]];
[button2 addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeWidth relativeTo:@"button1" attribute:CHLayoutConstraintAttributeWidth]];
[progress startAnimation:nil];
CHLayoutConstraint * centerHorizontal = [CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMidX relativeTo:@"superview" attribute:CHLayoutConstraintAttributeMidX];
CHLayoutConstraint * centerVertical = [CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMidY relativeTo:@"superview" attribute:CHLayoutConstraintAttributeMidY];
[progress addLayoutConstraint:centerHorizontal];
[progress addLayoutConstraint:centerVertical];
[progress addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMidXMidY relativeTo:@"superview" attribute:CHLayoutConstraintAttributeBoundsCenter]];
[leftVerticalButton setLayoutName:@"leftVertical"];
[leftVerticalButton addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMinX relativeTo:@"superview" attribute:CHLayoutConstraintAttributeMinX offset:37]];
[rightVerticalButton addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMaxX relativeTo:@"superview" attribute:CHLayoutConstraintAttributeMaxX offset:-13]];
[rightVerticalButton addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMinY relativeTo:@"leftVertical" attribute:CHLayoutConstraintAttributeMinY]];
#if NS_BLOCKS_AVAILABLE
CHLayoutTransformer transformer = ^(CGFloat source) {
CGFloat superViewHeight = [[rightVerticalButton superview] frame].size.height;
return (superViewHeight - source);
};
[rightVerticalButton addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMaxY relativeTo:@"leftVertical" attribute:CHLayoutConstraintAttributeMinY blockTransformer:transformer]];
#endif
// [helpButton addConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMinX relativeTo:@"leftVertical" attribute:CHLayoutConstraintAttributeMinY scale:2.0 offset:0.0]];
[helpButton addLayoutConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMidXMidY relativeTo:@"button1" attribute:CHLayoutConstraintAttributeBoundsCenter]];
SinTransformer * sinTransformer = [[SinTransformer alloc] init];
// [helpButton addConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMinY relativeTo:@"button1" attribute:CHLayoutConstraintAttributeMinY valueTransformer:sinTransformer]];
[sinTransformer release];
// [helpButton addConstraint:[CHLayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeCenter relativeTo:@"superview" attribute:CHLayoutConstraintAttributeFrame]];
[self sliderChanged:nil];
// [[CHLayoutManager sharedLayoutManager] beginProcessingView:[window contentView]];
}
- (IBAction) sliderChanged:(id)sender {
CGFloat sliderValue = [widthSlider floatValue];
NSRect button1Frame = [button1 frame];
button1Frame.size.width = sliderValue;
button1Frame.origin.y = sliderValue;
[button1 setFrame:button1Frame];
CGFloat range = ([widthSlider maxValue] - [widthSlider minValue]);
CGFloat percentage = ((sliderValue - range)/range) * 0.9;
NSRect leftVerticalFrame = [leftVerticalButton frame];
leftVerticalFrame.origin.y = ([[window contentView] frame].size.height * percentage);
[leftVerticalButton setFrame:leftVerticalFrame];
}
- (IBAction) clickButton1:(id)sender {
}
@end