Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Tons and tons of fixes/aesthetic updates.

  • Loading branch information...
commit 8b8c231fe6a3339cd2ba289a6e4e3736aaa581b5 1 parent 4c12722
galaxas0 galaxas0 authored
6 TwUI.xcodeproj/project.pbxproj
View
@@ -9,12 +9,12 @@
/* Begin PBXBuildFile section */
30D399C9156D8ADD006ECDAE /* TUIProgressBar.m in Sources */ = {isa = PBXBuildFile; fileRef = 30D399C7156D8ADD006ECDAE /* TUIProgressBar.m */; };
30D39A0D156D8F71006ECDAE /* TUIProgressBar.h in Headers */ = {isa = PBXBuildFile; fileRef = 30D399C6156D8ADD006ECDAE /* TUIProgressBar.h */; settings = {ATTRIBUTES = (Public, ); }; };
- 48A10E8115B7769A007F9EE3 /* TUILayoutConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E7D15B7769A007F9EE3 /* TUILayoutConstraint.h */; };
+ 48A10E8115B7769A007F9EE3 /* TUILayoutConstraint.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E7D15B7769A007F9EE3 /* TUILayoutConstraint.h */; settings = {ATTRIBUTES = (Public, ); }; };
48A10E8215B7769A007F9EE3 /* TUILayoutConstraint.m in Sources */ = {isa = PBXBuildFile; fileRef = 48A10E7E15B7769A007F9EE3 /* TUILayoutConstraint.m */; };
- 48A10E8315B7769A007F9EE3 /* TUILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E7F15B7769A007F9EE3 /* TUILayoutManager.h */; };
+ 48A10E8315B7769A007F9EE3 /* TUILayoutManager.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E7F15B7769A007F9EE3 /* TUILayoutManager.h */; settings = {ATTRIBUTES = (Public, ); }; };
48A10E8415B7769A007F9EE3 /* TUILayoutManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 48A10E8015B7769A007F9EE3 /* TUILayoutManager.m */; };
48A10E8915B778E8007F9EE3 /* TUIView+Layout.m in Sources */ = {isa = PBXBuildFile; fileRef = 48A10E8715B778E8007F9EE3 /* TUIView+Layout.m */; };
- 48A10E8B15B77A46007F9EE3 /* TUIView+Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E8A15B77A46007F9EE3 /* TUIView+Layout.h */; };
+ 48A10E8B15B77A46007F9EE3 /* TUIView+Layout.h in Headers */ = {isa = PBXBuildFile; fileRef = 48A10E8A15B77A46007F9EE3 /* TUIView+Layout.h */; settings = {ATTRIBUTES = (Public, ); }; };
5E6ECEB313BE791600109598 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE9839C13BE7650005F430D /* ApplicationServices.framework */; };
5E6ECEB413BE791600109598 /* QuartzCore.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = CB5E31B613BE6F49004B7899 /* QuartzCore.framework */; };
5E6ECEB613BE791C00109598 /* ApplicationServices.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5EE9839C13BE7650005F430D /* ApplicationServices.framework */; };
26 lib/UIKit/TUILayoutConstraint.h
View
@@ -1,14 +1,14 @@
@class TUIView;
-typedef enum {
- TUILayoutConstraintAttributeMinY = 1,
- TUILayoutConstraintAttributeMaxY = 2,
- TUILayoutConstraintAttributeMinX = 3,
- TUILayoutConstraintAttributeMaxX = 4,
- TUILayoutConstraintAttributeWidth = 5,
- TUILayoutConstraintAttributeHeight = 6,
- TUILayoutConstraintAttributeMidY = 7,
- TUILayoutConstraintAttributeMidX = 8,
+typedef enum : NSUInteger {
+ TUILayoutConstraintAttributeMinY = 1,
+ TUILayoutConstraintAttributeMaxY = 2,
+ TUILayoutConstraintAttributeMinX = 3,
+ TUILayoutConstraintAttributeMaxX = 4,
+ TUILayoutConstraintAttributeWidth = 5,
+ TUILayoutConstraintAttributeHeight = 6,
+ TUILayoutConstraintAttributeMidY = 7,
+ TUILayoutConstraintAttributeMidX = 8,
TUILayoutConstraintAttributeMinXMinY = 101,
TUILayoutConstraintAttributeMinXMidY = 102,
@@ -24,8 +24,8 @@ typedef enum {
TUILayoutConstraintAttributeBoundsCenter = 110,
- TUILayoutConstraintAttributeFrame = 1000,
- TUILayoutConstraintAttributeBounds = 1001
+ TUILayoutConstraintAttributeFrame = 1000,
+ TUILayoutConstraintAttributeBounds = 1001
} TUILayoutConstraintAttribute;
typedef CGFloat (^TUILayoutTransformer)(CGFloat);
@@ -58,8 +58,4 @@ typedef CGFloat (^TUILayoutTransformer)(CGFloat);
attribute:(TUILayoutConstraintAttribute)srcAttr
valueTransformer:(NSValueTransformer *)transformer;
-- (CGFloat)transformValue:(CGFloat)original;
-- (void)applyToTargetView:(TUIView *)target;
-- (void)applyToTargetView:(TUIView *)target sourceView:(TUIView *)source;
-
@end
114 lib/UIKit/TUILayoutConstraint.m
View
@@ -1,71 +1,39 @@
#import "TUILayoutConstraint.h"
#import "TUILayoutManager.h"
-@interface TUILayoutValueTransformer : NSValueTransformer {
- CGFloat offset;
- CGFloat scale;
-}
+@interface TUIView (Layout_Private)
-+ (id)transformerWithOffset:(CGFloat)anOffset scale:(CGFloat)aScale;
-- (id)initWithOffset:(CGFloat)anOffset scale:(CGFloat)aScale;
+- (NSRect)valueForLayoutAttribute:(TUILayoutConstraintAttribute)attribute;
+- (void)setValue:(NSRect)newValue forLayoutAttribute:(TUILayoutConstraintAttribute)attribute;
@end
-@implementation TUILayoutValueTransformer
-+ (id)transformerWithOffset:(CGFloat)anOffset scale:(CGFloat)aScale {
- return [[self alloc] initWithOffset:anOffset scale:aScale];
-}
+@interface TUILayoutConstraint ()
-- (id)initWithOffset:(CGFloat)anOffset scale:(CGFloat)aScale {
- if((self = [super init])) {
- offset = anOffset;
- scale = aScale;
- } return self;
-}
+@property (nonatomic, copy) NSValueTransformer *valueTransformer;
-- (id)transformedValue:(id)value {
- CGFloat source = [value floatValue];
- CGFloat transformed = (source * scale) + offset;
- return [NSNumber numberWithFloat:transformed];
-}
+- (CGFloat)transformValue:(CGFloat)original;
+- (void)applyToTargetView:(TUIView *)target;
+- (void)applyToTargetView:(TUIView *)target sourceView:(TUIView *)source;
@end
-@interface TUILayoutBlockValueTransformer : NSValueTransformer {
- TUILayoutTransformer transformer;
-}
+@interface TUILayoutBlockValueTransformer : NSValueTransformer
+
+@property (nonatomic, copy) TUILayoutTransformer transformer;
+ (id)transformerWithBlock:(TUILayoutTransformer)block;
- (id)initWithBlock:(TUILayoutTransformer)block;
@end
-@implementation TUILayoutBlockValueTransformer
-
-+ (id)transformerWithBlock:(TUILayoutTransformer)block {
- return [[self alloc] initWithBlock:block];
-}
-
-- (id)initWithBlock:(TUILayoutTransformer)block {
- if((self = [super init])) {
- transformer = [block copy];
- } return self;
-}
-
-- (id) transformedValue:(id)value {
- CGFloat source = [value floatValue];
- CGFloat transformed = transformer(source);
- return [NSNumber numberWithFloat:transformed];
-}
-
-@end
-
-@implementation TUILayoutConstraint {
- NSValueTransformer *valueTransformer;
-}
+@implementation TUILayoutConstraint
-@synthesize attribute, sourceAttribute, sourceName;
+@synthesize attribute = _attribute;
+@synthesize sourceAttribute = _sourceAttribute;
+@synthesize sourceName = _sourceName;
+@synthesize valueTransformer = _valueTransformer;
+ (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
relativeTo:(NSString *)srcLayer
@@ -81,12 +49,11 @@ + (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
}
+ (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
- relativeTo:(NSString *)srcLayer
+ relativeTo:(NSString *)source
attribute:(TUILayoutConstraintAttribute)srcAttr
scale:(CGFloat)scale
offset:(CGFloat)offset {
- TUILayoutValueTransformer *t = [TUILayoutValueTransformer transformerWithOffset:offset scale:scale];
- return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr valueTransformer:t];
+ return [[self alloc] initWithAttribute:attr relativeTo:source attribute:srcAttr scale:scale offset:offset];
}
+ (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
@@ -111,22 +78,21 @@ - (id)initWithAttribute:(TUILayoutConstraintAttribute)attr
double attributeRange = floor(log10(attr));
double sourceAttributeRange = floor(log10(srcAttr));
- if(attributeRange != sourceAttributeRange) {
- [NSException raise:NSInvalidArgumentException format:@"Invalid source and target attributes"];
- return nil;
- }
+
+ NSAssert(fabs(attributeRange - sourceAttributeRange) < 0.001, @"Invalid source and target attributes: %f, %f", sourceAttributeRange, attributeRange);
if((self = [super init])) {
- attribute = attr;
- sourceAttribute = srcAttr;
+ _attribute = attr;
+ _sourceAttribute = srcAttr;
- sourceName = [srcLayer copy];
- valueTransformer = transformer;
- } return self;
+ _sourceName = [srcLayer copy];
+ _valueTransformer = transformer;
+ }
+ return self;
}
- (CGFloat)transformValue:(CGFloat)original {
- id transformed = [valueTransformer transformedValue:[NSNumber numberWithFloat:original]];
+ id transformed = [self.valueTransformer transformedValue:[NSNumber numberWithFloat:original]];
return [transformed floatValue];
}
@@ -143,10 +109,34 @@ - (void)applyToTargetView:(TUIView *)target sourceView:(TUIView *)source {
NSRect sourceValue = [source valueForLayoutAttribute:[self sourceAttribute]];
NSRect targetValue = sourceValue;
- if(attribute >= TUILayoutConstraintAttributeMinY && attribute <= TUILayoutConstraintAttributeMidX)
+ if(self.attribute >= TUILayoutConstraintAttributeMinY && self.attribute <= TUILayoutConstraintAttributeMidX)
targetValue.origin.x = [self transformValue:sourceValue.origin.x];
[target setValue:targetValue forLayoutAttribute:[self attribute]];
}
@end
+
+@implementation TUILayoutBlockValueTransformer
+
+@synthesize transformer = _transformer;
+
++ (id)transformerWithBlock:(TUILayoutTransformer)block {
+ return [[self alloc] initWithBlock:block];
+}
+
+- (id)initWithBlock:(TUILayoutTransformer)block {
+ if((self = [super init])) {
+ _transformer = [block copy];
+ }
+ return self;
+}
+
+- (id)transformedValue:(id)value {
+ if(!self.transformer) return nil;
+ CGFloat source = [value floatValue];
+ CGFloat transformed = self.transformer(source);
+ return [NSNumber numberWithFloat:transformed];
+}
+
+@end
156 lib/UIKit/TUILayoutManager.m
View
@@ -2,17 +2,27 @@
#import "TUILayoutManager.h"
#import "TUIView+Layout.h"
+@interface TUILayoutConstraint ()
+
+@property (nonatomic, copy) NSValueTransformer *valueTransformer;
+
+- (CGFloat)transformValue:(CGFloat)original;
+- (void)applyToTargetView:(TUIView *)target;
+- (void)applyToTargetView:(TUIView *)target sourceView:(TUIView *)source;
+
+@end
+
@interface TUILayoutContainer : NSObject
@property (nonatomic, copy) NSString *layoutName;
-@property (readonly) NSMutableArray *layoutConstraints;
+@property (nonatomic, strong, readonly) NSMutableArray *layoutConstraints;
@end
@implementation TUILayoutContainer
-@synthesize layoutName;
-@synthesize layoutConstraints;
+@synthesize layoutName = _layoutName;
+@synthesize layoutConstraints = _layoutConstraints;
+ (id)container {
return [[self alloc] init];
@@ -20,79 +30,78 @@ + (id)container {
- (id)init {
if((self = [super init])) {
- layoutConstraints = [[NSMutableArray alloc] init];
+ _layoutConstraints = [[NSMutableArray alloc] init];
} return self;
}
@end
-static TUILayoutManager *_sharedLayoutManager = nil;
-@implementation TUILayoutManager {
- BOOL hasRegistered;
- BOOL isProcessingChanges;
-
- NSMapTable *constraints;
- NSMutableArray *viewsToProcess;
- NSMutableSet *processedViews;
-}
+@interface TUILayoutManager ()
+
+@property (nonatomic, assign) BOOL isProcessingChanges;
+
+@property (nonatomic, strong) NSMapTable *constraints;
+@property (nonatomic, strong) NSMutableArray *viewsToProcess;
+@property (nonatomic, strong) NSMutableSet *processedViews;
+
+@end
+
+@implementation TUILayoutManager
+
+@synthesize isProcessingChanges = _isProcessingChanges;
+@synthesize constraints = _constraints;
+@synthesize viewsToProcess = _viewsToProcess;
+@synthesize processedViews = _processedViews;
+ (id)sharedLayoutManager {
+ static TUILayoutManager *_sharedLayoutManager = nil;
+ static dispatch_once_t onceToken;
+
+ dispatch_once(&onceToken, ^{
+ _sharedLayoutManager = [[TUILayoutManager alloc] init];
+ });
+
return _sharedLayoutManager;
}
-+ (id)allocWithZone:(NSZone *)zone {
- if(_sharedLayoutManager)
- return _sharedLayoutManager;
- else return [super allocWithZone:zone];
-}
-
- (id)init {
- if(!_sharedLayoutManager) {
- if((self = [super init])) {
- isProcessingChanges = NO;
- viewsToProcess = [[NSMutableArray alloc] init];
- processedViews = [[NSMutableSet alloc] init];
-
- constraints = [NSMapTable mapTableWithWeakToStrongObjects];
- hasRegistered = NO;
- }
- } else if (self != _sharedLayoutManager) {
- self = _sharedLayoutManager;
- } return self;
+ if((self = [super init])) {
+ [[NSNotificationCenter defaultCenter] addObserver:self
+ selector:@selector(frameChanged:)
+ name:TUIViewFrameDidChangeNotification
+ object:nil];
+ _isProcessingChanges = NO;
+
+ _constraints = [NSMapTable mapTableWithWeakToStrongObjects];
+ _viewsToProcess = [[NSMutableArray alloc] init];
+ _processedViews = [[NSMutableSet alloc] init];
+ }
+ return self;
}
- (void)dealloc {
[[NSNotificationCenter defaultCenter] removeObserver:self];
- [self removeAllLayoutConstraints];
}
- (void)removeAllLayoutConstraints {
- [constraints removeAllObjects];
+ [self.constraints removeAllObjects];
}
- (void)processView:(TUIView *)aView {
- if(hasRegistered == NO) {
- [[NSNotificationCenter defaultCenter] addObserver:self
- selector:@selector(frameChanged:)
- name:TUIViewFrameDidChangeNotification
- object:nil];
- hasRegistered = YES;
- }
-
- [processedViews addObject:aView];
+ [self.processedViews addObject:aView];
- NSArray *viewConstraints = [self layoutConstraintsOnView:aView];
- for(TUILayoutConstraint * constraint in viewConstraints)
- [constraint applyToTargetView:aView];
+ NSArray *viewConstraints = [self layoutConstraintsOnView:aView];
+ for(TUILayoutConstraint * constraint in viewConstraints)
+ [constraint applyToTargetView:aView];
// Order of Operations:
// 1. Siblings with constraints to this view.
// 2. Children with constraints to superview.
if([self layoutNameForView:aView] != nil) {
- NSArray *superSubviews = [[aView superview] subviews];
- for(TUIView *subview in superSubviews) {
+ NSArray *siblings = [[aView superview] subviews];
+ for(TUIView *subview in siblings) {
if(subview == aView) continue;
NSArray *subviewConstraints = [self layoutConstraintsOnView:subview];
@@ -116,26 +125,27 @@ - (void)processView:(TUIView *)aView {
}
- (void)beginProcessingView:(TUIView *)view {
- if(isProcessingChanges == NO) {
- isProcessingChanges = YES;
+ if(self.isProcessingChanges == NO) {
+ self.isProcessingChanges = YES;
@autoreleasepool {
- [viewsToProcess removeAllObjects];
- [processedViews removeAllObjects];
- [viewsToProcess addObject:view];
+ [self.viewsToProcess addObject:view];
- while([viewsToProcess count] > 0) {
- TUIView *currentView = [viewsToProcess objectAtIndex:0];
- [viewsToProcess removeObjectAtIndex:0];
- if([viewsToProcess containsObject:currentView] == NO)
+ while([self.viewsToProcess count] > 0) {
+ TUIView *currentView = [self.viewsToProcess objectAtIndex:0];
+ [self.viewsToProcess removeObjectAtIndex:0];
+ if([self.viewsToProcess containsObject:currentView] == NO)
[self processView:currentView];
}
+
+ [self.viewsToProcess removeAllObjects];
+ [self.processedViews removeAllObjects];
}
- isProcessingChanges = NO;
+ self.isProcessingChanges = NO;
} else {
- if([processedViews containsObject:view] == NO)
- [viewsToProcess addObject:view];
+ if([self.processedViews containsObject:view] == NO)
+ [self.viewsToProcess addObject:view];
}
}
@@ -145,10 +155,10 @@ - (void)frameChanged:(NSNotification *)notification {
}
- (void)addLayoutConstraint:(TUILayoutConstraint *)constraint toView:(TUIView *)view {
- TUILayoutContainer *viewContainer = [constraints objectForKey:view];
+ TUILayoutContainer *viewContainer = [self.constraints objectForKey:view];
if(viewContainer == nil) {
viewContainer = [TUILayoutContainer container];
- [constraints setObject:viewContainer forKey:view];
+ [self.constraints setObject:viewContainer forKey:view];
}
[[viewContainer layoutConstraints] addObject:constraint];
@@ -156,34 +166,34 @@ - (void)addLayoutConstraint:(TUILayoutConstraint *)constraint toView:(TUIView *)
}
- (void)removeLayoutConstraintsFromView:(TUIView *)view {
- TUILayoutContainer *viewContainer = [constraints objectForKey:view];
+ TUILayoutContainer *viewContainer = [self.constraints objectForKey:view];
[[viewContainer layoutConstraints] removeAllObjects];
-
- if([[viewContainer layoutConstraints] count] == 0 && [viewContainer layoutName] == nil)
- [constraints removeObjectForKey:view];
+ [self.constraints removeObjectForKey:view];
}
- (NSArray *)layoutConstraintsOnView:(TUIView *)view {
- TUILayoutContainer *container = [constraints objectForKey:view];
- if (container == nil) return [NSArray array];
- return [[container layoutConstraints] copy];
+ TUILayoutContainer *container = [self.constraints objectForKey:view];
+
+ if(!container) return nil;
+ else return [[container layoutConstraints] copy];
}
- (NSString *)layoutNameForView:(TUIView *)view {
- TUILayoutContainer *container = [constraints objectForKey:view];
+ TUILayoutContainer *container = [self.constraints objectForKey:view];
return [container layoutName];
}
- (void)setLayoutName:(NSString *)name forView:(TUIView *)view {
- TUILayoutContainer *viewContainer = [constraints objectForKey:view];
+ TUILayoutContainer *viewContainer = [self.constraints objectForKey:view];
if(name == nil && [[viewContainer layoutConstraints] count] == 0)
- [constraints removeObjectForKey:view];
+ [self.constraints removeObjectForKey:view];
else {
if(viewContainer == nil) {
viewContainer = [TUILayoutContainer container];
- [constraints setObject:viewContainer forKey:view];
- } [viewContainer setLayoutName:name];
+ [self.constraints setObject:viewContainer forKey:view];
+ }
+ [viewContainer setLayoutName:name];
}
}
3  lib/UIKit/TUIView+Layout.h
View
@@ -9,9 +9,6 @@
- (NSArray *)layoutConstraints;
- (void)removeAllLayoutConstraints;
-- (NSRect)valueForLayoutAttribute:(TUILayoutConstraintAttribute)attribute;
-- (void)setValue:(NSRect)newValue forLayoutAttribute:(TUILayoutConstraintAttribute)attribute;
-
- (TUIView *)relativeViewForName:(NSString *)name;
@end
25 lib/UIKit/TUIView+Layout.m
View
@@ -14,6 +14,13 @@
#define TUISetMaxX(_r,_v) ((_r).origin.x = (_v) - (_r).size.width)
#define TUISetMaxY(_r,_v) ((_r).origin.y = (_v) - (_r).size.height)
+@interface TUIView (Layout_Private)
+
+- (NSRect)valueForLayoutAttribute:(TUILayoutConstraintAttribute)attribute;
+- (void)setValue:(NSRect)newValue forLayoutAttribute:(TUILayoutConstraintAttribute)attribute;
+
+@end
+
@implementation TUIView (Layout)
- (void)setLayoutName:(NSString *)newLayoutName {
@@ -82,6 +89,7 @@ - (CGRect)valueForLayoutAttribute:(TUILayoutConstraintAttribute)attribute {
case TUILayoutConstraintAttributeBounds:
return bounds;
default:
+ NSAssert(NO, @"Invalid constraint attribute.");
return NSZeroRect;
}
}
@@ -142,6 +150,7 @@ - (void)setValue:(CGRect)newValue forLayoutAttribute:(TUILayoutConstraintAttribu
case TUILayoutConstraintAttributeBoundsCenter:
TUISetMidX(bounds, pointValue.x);
TUISetMidY(bounds, pointValue.y);
+ [self setBounds:bounds];
break;
case TUILayoutConstraintAttributeMidXMaxY:
TUISetMidX(frame, pointValue.x);
@@ -164,21 +173,23 @@ - (void)setValue:(CGRect)newValue forLayoutAttribute:(TUILayoutConstraintAttribu
break;
case TUILayoutConstraintAttributeBounds:
bounds = rectValue;
+ [self setBounds:bounds];
break;
+ default:
+ NSAssert(NO, @"Invalid constraint attribute.");
+ break;
}
-
- if(attribute != TUILayoutConstraintAttributeBounds && attribute != TUILayoutConstraintAttributeBoundsCenter)
- [self setFrame:frame];
- else [self setBounds:bounds];
+
+ [self setFrame:frame];
}
- (TUIView *)relativeViewForName:(NSString *)name {
if([name isEqual:@"superview"])
return [self superview];
- NSArray * superSubviews = [[self superview] subviews];
- for(TUIView *view in superSubviews)
- if([[view layoutName] isEqual:name])
+ NSArray *siblings = [[self superview] subviews];
+ for(TUIView *view in siblings)
+ if([view.layoutName isEqual:name])
return (view == self ? nil : view);
return nil;
}
4 lib/UIKit/TUIView.m
View
@@ -111,8 +111,8 @@ + (Class)layerClass
- (void)dealloc
{
- [[TUILayoutManager sharedLayoutManager] removeLayoutConstraintsFromView:(TUIView *)self];
- [[TUILayoutManager sharedLayoutManager] setLayoutName:nil forView:(TUIView *)self];
+ [[TUILayoutManager sharedLayoutManager] removeLayoutConstraintsFromView:self];
+ [[TUILayoutManager sharedLayoutManager] setLayoutName:nil forView:self];
[self setTextRenderers:nil];
_layer.delegate = nil;
Please sign in to comment.
Something went wrong with that request. Please try again.