Archived
1

Improved Code Style

This commit is contained in:
Kim Wittenburg
2014-09-16 20:08:25 +02:00
parent af8f26dee9
commit 9a8893796c
9 changed files with 36 additions and 58 deletions

View File

@@ -41,36 +41,23 @@
@implementation MPExpressionLayout
# pragma mark Creation Methods
- (instancetype)initRootLayoutWithExpression:(MPExpression *)expression
- (instancetype)initWithExpression:(MPExpression *)expression
parent:(MPFunctionLayout *)parent
{
self = [super init];
self = [super initWithParent:parent];
if (self) {
_expression = expression;
}
return self;
}
- (instancetype)initWithElementAtPath:(NSIndexPath *)path
inRootExpression:(MPExpression *)rootExpression
parent:(MPLayout *)parent
{
self = [super initWithElementAtPath:path
inRootExpression:rootExpression
parent:parent];
if (self) {
_expression = [rootExpression elementAtIndexPath:path];
}
return self;
}
#pragma mark Cache Methods
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
{
id cachedObject = [self cachableObjectForIndex:index generator:^id{
NSIndexPath *indexPath = [self.expression.indexPath indexPathByAddingIndex:index];
MPFunctionLayout *layout = [MPFunctionLayout functionLayoutForFunctionAtIndexPath:indexPath
inRootExpression:self.expression.rootExpression
parent:self];
MPFunction *function = (MPFunction *)[self.expression elementAtIndex:index];
MPFunctionLayout *layout = [MPFunctionLayout functionLayoutForFunction:function
parent:self];
layout.flipped = self.flipped;
layout.usesSmallSize = self.usesSmallSize;
return layout;
@@ -114,7 +101,7 @@
- (NSRect)boundingRectForRange:(NSRange)range
{
NSUInteger startOffset;
NSUInteger startElementIndex = [self.expression indexOfElementAtSymbolLocation:range.location
NSUInteger startElementIndex = [self.expression indexOfElementAtLocation:range.location
offset:&startOffset];
// Calculate x position
CGFloat x = 0, width = 0;
@@ -139,7 +126,7 @@
}
NSUInteger endOffset;
NSUInteger endElementIndex = [self.expression indexOfElementAtSymbolLocation:NSMaxRange(range)
NSUInteger endElementIndex = [self.expression indexOfElementAtLocation:NSMaxRange(range)
offset:&endOffset];
// Selection is inside of one string element