Archived
1

Fundamental Redesign of the View and Controller

This commit is contained in:
Kim Wittenburg
2014-08-22 00:54:13 +02:00
parent a37d587e1f
commit c024886241
12 changed files with 255 additions and 150 deletions

View File

@@ -10,19 +10,15 @@
@interface MPLayout ()
// Querying Caches
// Querying and Storing Caches
- (BOOL)hasCacheForElementAtIndex:(NSUInteger)index;
// Storing Caches
- (void)cacheObject:(id)anObject
forElementAtIndex:(NSUInteger)index;
- (void)ensureCacheSizeForIndex:(NSUInteger)index;
@end
@implementation MPLayout {
NSMutableArray *_cache;
NSBezierPath *_cachedPath;
NSSize _cachedSize;
}
#pragma mark Creation Methods
@@ -31,8 +27,7 @@
self = [super init];
if (self) {
_cache = [[NSMutableArray alloc] init];
_cachedPath = nil;
_path = [[NSIndexPath alloc] init];
_cachedSize = NSZeroSize;
}
return self;
}
@@ -42,7 +37,6 @@
{
self = [self init];
if (self) {
_path = path;
_parent = parent;
}
return self;
@@ -54,23 +48,8 @@
return self.parent.expressionStorage;
}
- (NSLayoutManager *)layoutManager
{
return self.expressionStorage.layoutManager;
}
- (NSTextContainer *)textContainer
{
return self.expressionStorage.textContainer;
}
- (NSTextStorage *)textStorage
{
return self.expressionStorage.textStorage;
}
#pragma mark Cache Tree
// Querying Caches
// Querying and Storing Caches
- (BOOL)hasCacheForElementAtIndex:(NSUInteger)index
{
if (index >= _cache.count) {
@@ -86,17 +65,9 @@
return _cache[index];
}
id object = generator();
[self cacheObject:object
forElementAtIndex:index];
return object;
}
// Storing Caches
- (void)cacheObject:(id)anObject
forElementAtIndex:(NSUInteger)index
{
[self ensureCacheSizeForIndex:index];
_cache[index] = anObject;
_cache[index] = object;
return object;
}
- (void)ensureCacheSizeForIndex:(NSUInteger)index
@@ -121,39 +92,41 @@
- (void)invalidate
{
_cachedPath = nil;
_cachedSize = NSZeroSize;
[self.parent invalidate];
}
#pragma mark Calculation Methods
#pragma mark Calculation and Drawing Methods
- (NSSize)size
{
return self.bezierPath.bounds.size;
}
- (NSBezierPath *)bezierPath
{
if (!_cachedPath) {
_cachedPath = [self generateBezierPath];
if (NSEqualSizes(_cachedSize, NSZeroSize)) {
_cachedSize = [self generateSize];
}
return _cachedPath;
}
- (NSBezierPath *)bezierPathAtOrigin:(NSPoint)point
{
NSAffineTransform *transform = [NSAffineTransform transform];
[transform translateXBy:point.x
yBy:point.y];
NSBezierPath *path = [NSBezierPath bezierPath];
[path appendBezierPath:self.bezierPath];
[path transformUsingAffineTransform:transform];
return path;
return _cachedSize;
}
- (void)drawAtPoint:(NSPoint)point
{
NSBezierPath *path = [self bezierPathAtOrigin:point];
[path fill];
}
@end
@implementation MPLayout (MPSubclassImplement)
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
{
return nil;
}
- (NSSize)sizeForChildAtIndex:(NSUInteger)index
{
return NSZeroSize;
}
- (NSSize)generateSize
{
return NSZeroSize;
}
@end