Archived
1
This repository has been archived on 2022-08-08. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
mathpad/MathPad/MPFunctionLayout.m
Kim Wittenburg 60760b8b3d Internal Redesign:
- Combined MPExpression and MPMutableExpression
- Abstracted children of MPExpression into MPExpressionElement protocol
- Abstracted most of MPExpressionLayout and MPFunctionLayout into common superclass MPLayout
2014-08-11 13:57:48 +02:00

59 lines
1.6 KiB
Objective-C

//
// 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