Archived
1

Added Lots of Documentation

Added some nice to haves
Improved and Unified General Code Layout
This commit is contained in:
Kim Wittenburg
2015-01-04 02:54:27 +01:00
parent 152b981e24
commit 7438fd1f95
83 changed files with 2282 additions and 416 deletions

View File

@@ -11,20 +11,25 @@
#import "MPRangePath.h"
#import "NSIndexPath+MPAdditions.h"
@interface MPLayout ()
// Querying and Storing Caches
- (BOOL)hasCacheForElementAtIndex:(NSUInteger)index;
- (void)ensureCacheSizeForIndex:(NSUInteger)index;
@end
@implementation MPLayout {
NSMutableArray *_cache;
NSRect _cachedBounds;
}
#pragma mark Creation Methods
- (id)init
{
self = [super init];
@@ -35,6 +40,7 @@
return self;
}
- (instancetype)initWithParent:(MPLayout *)parent
{
self = [self init];
@@ -44,41 +50,51 @@
return self;
}
#pragma mark Properties
- (NSFont *)normalFontWithSize:(CGFloat)size
{
return [NSFont fontWithName:@"CMU Serif"
size:size];
}
- (NSFont *)specialFontWithSize:(CGFloat)size
{
return [NSFont fontWithName:@"CMU Serif Italic"
size:size];
}
- (CGFloat)contextInferredFontSize
{
return self.usesSmallSize ? self.smallFontSize : self.normalFontSize;
}
- (CGFloat)normalFontSize
{
return 18.0;
}
- (CGFloat)smallFontSize
{
return 12.0;
}
- (NSFont *)font
{
return [self normalFontWithSize:self.contextInferredFontSize];
}
#pragma mark Cache Tree
// Querying and Storing Caches
- (BOOL)hasCacheForElementAtIndex:(NSUInteger)index
{
if (index >= _cache.count) {
@@ -87,6 +103,7 @@
return _cache[index] != [NSNull null];
}
- (id)cachableObjectForIndex:(NSUInteger)index
generator:(id (^)())generator
{
@@ -99,6 +116,7 @@
return object;
}
- (void)ensureCacheSizeForIndex:(NSUInteger)index
{
while (index >= _cache.count) {
@@ -106,7 +124,7 @@
}
}
// Clearing Caches
- (void)clearCacheInRange:(NSRange)range
replacementLength:(NSUInteger)replacementLength
{
@@ -119,12 +137,14 @@
[self invalidate];
}
- (void)invalidate
{
_cachedBounds = NSZeroRect;
[self.parent invalidate];
}
- (MPLayout *)childLayoutAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.length == 0) {
@@ -134,19 +154,24 @@
return [child childLayoutAtIndexPath:[indexPath indexPathByRemovingFirstIndex]];
}
#pragma mark Calculation and Drawing Methods
- (CTLineRef)createLineForString:(NSString *)aString
{
return [self createLineForString:aString
usingFont:self.font];
}
- (CTLineRef)createLineForString:(NSString *)aString emphasize:(BOOL)emphasize
{
return [self createLineForString:aString
usingFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
}
- (CTLineRef)createLineForString:(NSString *)aString
usingFont:(NSFont *)font
{
@@ -158,6 +183,7 @@
return line;
}
- (NSRect)bounds
{
if (NSEqualRects(_cachedBounds, NSZeroRect)) {
@@ -166,6 +192,7 @@
return _cachedBounds;
}
- (NSRect)boundingRectForRangePath:(MPRangePath *)rangePath
{
if (rangePath.location.length == 1) {
@@ -180,11 +207,13 @@
return bounds;
}
- (BOOL)drawsChildrenManually
{
return NO;
}
- (void)drawAtPoint:(NSPoint)point
{
NSAffineTransform *transform = [NSAffineTransform transform];