Skip to content
This repository has been archived by the owner on Apr 25, 2018. It is now read-only.

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
davedelong committed Aug 14, 2010
0 parents commit 0878bbe
Show file tree
Hide file tree
Showing 17 changed files with 5,736 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .gitignore
@@ -0,0 +1,6 @@
build
**/*.mode1v3
**/*.perspectivev3
**/*.pbxuser
**/*.xcworkspace
**/xcuserdata
28 changes: 28 additions & 0 deletions CHLayout.h
@@ -0,0 +1,28 @@
//
// CHLayout.h
// 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 "NSView+CHLayout.h"
#import "CHLayoutManager.h"
#import "CHLayoutConstraint.h"
63 changes: 63 additions & 0 deletions CHLayoutConstraint.h
@@ -0,0 +1,63 @@
//
// CHLayoutConstraint.h
// 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 <Cocoa/Cocoa.h>

typedef enum {
CHLayoutConstraintAttributeMinY = 1, //the left edge
CHLayoutConstraintAttributeMaxY = 2, //the right edge
CHLayoutConstraintAttributeMinX = 3, //the bottom edge
CHLayoutConstraintAttributeMaxX = 4, //the top edge
CHLayoutConstraintAttributeWidth = 5, //the width
CHLayoutConstraintAttributeHeight = 6, //the height
CHLayoutConstraintAttributeMidY = 7,
CHLayoutConstraintAttributeMidX = 8
} CHLayoutConstraintAttribute;

@interface CHLayoutConstraint : NSObject {
CGFloat offset;
CGFloat scale;
CHLayoutConstraintAttribute attribute;

NSString * sourceName;
CHLayoutConstraintAttribute sourceAttribute;
}

@property (readonly) CGFloat offset;
@property (readonly) CGFloat scale;
@property (readonly) CHLayoutConstraintAttribute attribute;
@property (readonly) CHLayoutConstraintAttribute sourceAttribute;
@property (readonly) NSString * sourceName;

+ (id)constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr;
+ (id)constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr offset:(CGFloat)offset;
+ (id)constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr scale:(CGFloat)scale offset:(CGFloat)offset;

- (id)initWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr scale:(CGFloat)scale offset:(CGFloat)offset;

- (CGFloat) transformValue:(CGFloat)original;
- (void) applyToTargetView:(NSView *)target;

@end
78 changes: 78 additions & 0 deletions CHLayoutConstraint.m
@@ -0,0 +1,78 @@
//
// CHLayoutConstraint.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 "CHLayout.h"


@implementation CHLayoutConstraint
@synthesize offset, scale, attribute, sourceAttribute, sourceName;

#pragma mark Basic Initializers

+ (id)constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr {
return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:1.0 offset:0.0];
}

+ (id)constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr offset:(CGFloat)offset {
return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:1.0 offset:offset];
}

+ (id)constraintWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr scale:(CGFloat)scale offset:(CGFloat)offset {
return [[[self alloc] initWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:scale offset:offset] autorelease];
}

- (id)initWithAttribute:(CHLayoutConstraintAttribute)attr relativeTo:(NSString *)srcLayer attribute:(CHLayoutConstraintAttribute)srcAttr scale:(CGFloat)aScale offset:(CGFloat)anOffset {
if (self = [super init]) {
offset = anOffset;
scale = aScale;
attribute = attr;
sourceAttribute = srcAttr;
sourceName = [srcLayer copy];
}
return self;
}

- (void) dealloc {
[sourceName release];
[super dealloc];
}

- (CGFloat) transformValue:(CGFloat)original {
return (original * scale) + offset;
}

- (void) applyToTargetView:(NSView *)target {
NSView * source = [target relativeViewForName:[self sourceName]];
if (source == target) { return; }
if (source == nil) { return; }
if ([self sourceAttribute] == 0) { return; }

CGFloat sourceValue = [source valueForLayoutAttribute:[self sourceAttribute]];
CGFloat targetValue = [self transformValue:sourceValue];

[target setValue:targetValue forLayoutAttribute:[self attribute]];
}

@end
32 changes: 32 additions & 0 deletions CHLayoutManager-Info.plist
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIconFile</key>
<string></string>
<key>CFBundleIdentifier</key>
<string>com.yourcompany.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
<key>LSMinimumSystemVersion</key>
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
<key>NSMainNibFile</key>
<string>MainMenu</string>
<key>NSPrincipalClass</key>
<string>NSApplication</string>
</dict>
</plist>
42 changes: 42 additions & 0 deletions CHLayoutManager.h
@@ -0,0 +1,42 @@
//
// CHLayoutManager.h
// 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 <Cocoa/Cocoa.h>

@class CHLayoutConstraint;

@interface CHLayoutManager : NSObject {
BOOL hasRegistered;
BOOL isProcessingChanges;

NSMutableArray * viewsToProcess;
NSMutableSet * processedViews;
}

+ (id) sharedLayoutManager;

- (void) beginProcessingView:(NSView *)aView;

@end

0 comments on commit 0878bbe

Please sign in to comment.