// // MPFunctionLayout.m // MathPad // // Created by Kim Wittenburg on 07.08.14. // Copyright (c) 2014 Kim Wittenburg. All rights reserved. // #import "MPFunctionLayout.h" #import "MPFunction.h" #import "MPExpressionLayout.h" #import "MPSumFunction.h" #import "MPSumFunctionLayout.h" @implementation MPFunctionLayout #pragma mark Creation Methods + (MPFunctionLayout *)functionLayoutForFunctionAtIndexPath:(NSIndexPath *)path parent:(MPExpressionLayout *)parent { MPFunction *function = [parent.expressionStorage elementAtIndexPath:path]; Class class = [function class]; if (class == [MPSumFunction class]) { return [[MPSumFunctionLayout alloc] initWithPath:path parent:parent]; } return [[self alloc] initWithPath:path parent:parent]; } #pragma mark Properties - (MPFunction *)function { return [self.expressionStorage elementAtIndexPath:self.path]; } #pragma mark Cache Methods - (MPLayout *)childLayoutAtIndex:(NSUInteger)index { return [self cachableObjectForIndex:index generator:^id{ NSIndexPath *childPath = [self.path indexPathByAddingIndex:index]; MPExpressionLayout *layout = [[MPExpressionLayout alloc] initWithPath:childPath parent:self]; return layout; }]; } - (NSSize)sizeForChildAtIndex:(NSUInteger)index { MPLayout *childLayout = [self childLayoutAtIndex:index]; return [childLayout size]; } - (NSBezierPath *)generateBezierPath { return [NSBezierPath bezierPath]; } @end