Archived
1

Added Function Chooser as a Popover

Improved Evaluation
Added Parenthesis Function
This commit is contained in:
Kim Wittenburg
2014-09-28 23:52:29 +02:00
parent 1c8b7e3c12
commit 19a40c2907
16 changed files with 746 additions and 32 deletions

View File

@@ -12,6 +12,10 @@
#import "MPSumFunction.h"
#import "MPSumFunctionLayout.h"
#import "MPParenthesisFunction.h"
#import "MPParenthesisFunctionLayout.h"
#import "NSIndexPath+MPAdditions.h"
@implementation MPFunctionLayout
@@ -22,6 +26,8 @@
Class class = [function class];
if (class == [MPSumFunction class]) {
return [[MPSumFunctionLayout alloc] initWithFunction:function parent:parent];
} else if (class == [MPParenthesisFunction class]) {
return [[MPParenthesisFunctionLayout alloc] initWithFunction:function parent:parent];
}
return [[self alloc] initWithFunction:function
parent:parent];
@@ -51,6 +57,13 @@
return (__bridge CTLineRef)(lineObject);
}
- (id)objectForPrivateCacheIndex:(NSUInteger)index
generator:(id (^)())generator
{
NSUInteger actualIndex = self.function.numberOfChildren + index;
return [self cachableObjectForIndex:actualIndex generator:generator];
}
- (MPLayout *)childLayoutAtIndex:(NSUInteger)index
{
return [self cachableObjectForIndex:index generator:^id{
@@ -58,11 +71,36 @@
MPExpressionLayout *layout = [[MPExpressionLayout alloc] initWithExpression:child
parent:self];
layout.flipped = self.flipped;
layout.usesSmallSize = (index == 0 || index == 1) ? YES : self.usesSmallSize;
layout.usesSmallSize = self.usesSmallSize ? YES : [self childAtIndexUsesSmallSize:index];
return layout;
}];
}
- (BOOL)childAtIndexUsesSmallSize:(NSUInteger)index
{
return NO;
}
- (NSIndexPath *)indexPathForMousePoint:(NSPoint)point
{
// A single index is used to communicate back wether the
// selection should be before or after the function.
// A 0 means before, a 1 means after.
for (NSUInteger index = 0; index < self.function.numberOfChildren; index++) {
MPLayout *childLayout = [self childLayoutAtIndex:index];
NSRect childBounds = childLayout.bounds;
NSPoint childOffset = [self offsetOfChildLayoutAtIndex:index];
childBounds.origin.x += childOffset.x;
childBounds.origin.y += childOffset.y;
if (NSMouseInRect(point, childBounds, self.flipped)) {
NSPoint pointInChild = NSMakePoint(point.x - childOffset.x, point.y - childOffset.y);
NSIndexPath *subPath = [childLayout indexPathForMousePoint:pointInChild];
return [subPath indexPathByPreceedingIndex:index];
}
}
return [self indexPathForLocalMousePoint:point];
}
- (NSUInteger)indexOfChildBeforeChildAtIndex:(NSUInteger)index
{
return NSNotFound;
@@ -73,4 +111,19 @@
return NSNotFound;
}
- (NSUInteger)indexOfChildBelowChildAtIndex:(NSUInteger)index
{
return index;
}
- (NSUInteger)indexOfChildAboveChildAtIndex:(NSUInteger)index
{
return index;
}
- (NSIndexSet *)indexesOfRemainingChildren
{
return [NSIndexSet indexSet];
}
@end