Started to Implement Evaluation
Corrected Some Errors Cleaned Code
This commit is contained in:
@@ -51,7 +51,7 @@
|
||||
{
|
||||
NSRect expressionBounds = [self.expressionStorage.rootLayout bounds];
|
||||
CGFloat y = (self.bounds.size.height - expressionBounds.size.height) / 2 + fabs(expressionBounds.origin.y);
|
||||
return NSMakePoint(self.bounds.origin.x, self.bounds.origin.y + y);
|
||||
return NSMakePoint(0, y);
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -124,15 +124,19 @@
|
||||
|
||||
- (void)initializeExpressionView
|
||||
{
|
||||
// Setup the Expression Storage
|
||||
MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithElements:@[@"12345", [[MPSumFunction alloc] init], [[MPSumFunction alloc] init]]];
|
||||
expressionStorage.expressionView = self;
|
||||
_expressionStorage = expressionStorage;
|
||||
NSRect frame = NSMakeRect(10, 10, 500, 500);
|
||||
NSButton *button = [[NSButton alloc] initWithFrame:frame];
|
||||
|
||||
// Setup the Functions Button
|
||||
NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect];
|
||||
button.buttonType = NSSwitchButton;
|
||||
[button setTitle:@"Functions"];
|
||||
self.functionsButton = button;
|
||||
[self addSubview:self.functionsButton];
|
||||
|
||||
// Setup Selection
|
||||
self.selection = [[MPRangePath alloc] initWithRange:NSMakeRange(0, 0)];
|
||||
self.caretBlinkRate = 1.0;
|
||||
[self restartCaretTimer];
|
||||
@@ -202,7 +206,9 @@
|
||||
- (void)keyDown:(NSEvent *)theEvent
|
||||
{
|
||||
NSString *characters = theEvent.characters;
|
||||
if (characters.length == 1 && [characters stringByTrimmingCharactersInSet:[NSCharacterSet decimalDigitCharacterSet]].length == 0) {
|
||||
NSMutableCharacterSet *allowedCharacters = [NSMutableCharacterSet alphanumericCharacterSet];
|
||||
[allowedCharacters addCharactersInString:@"+-*/= "];
|
||||
if (characters.length == 1 && [characters stringByTrimmingCharactersInSet:allowedCharacters].length == 0) {
|
||||
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:[self.selection.location indexPathByRemovingLastIndex]];
|
||||
[targetExpression replaceSymbolsInRange:self.selection.rangeAtLastIndex withElements:@[characters]];
|
||||
self.selection = MPMakeRangePath([self.selection.location indexPathByIncrementingLastIndex], 0);
|
||||
@@ -277,7 +283,8 @@
|
||||
|
||||
- (void)moveToEndOfLine:(id)sender
|
||||
{
|
||||
|
||||
MPExpression *targetExpression = [self.expressionStorage elementAtIndexPath:[self.selection.location indexPathByRemovingLastIndex]];
|
||||
self.selection = MPMakeRangePath([self.selection.location indexPathByReplacingLastIndexWithIndex:targetExpression.length], 0);
|
||||
}
|
||||
|
||||
- (void)moveLeftAndModifySelection:(id)sender
|
||||
@@ -317,12 +324,12 @@
|
||||
|
||||
- (void)moveWordRightAndModifySelection:(id)sender
|
||||
{
|
||||
|
||||
#warning Unimplemented Method
|
||||
}
|
||||
|
||||
- (void)moveWordLeftAndModifySelection:(id)sender
|
||||
{
|
||||
|
||||
#warning Unimplemented Method
|
||||
}
|
||||
|
||||
- (void)selectAll:(id)sender
|
||||
@@ -361,7 +368,7 @@
|
||||
// Draw the background
|
||||
[super drawRect:dirtyRect];
|
||||
[[NSColor whiteColor] set];
|
||||
NSRectFill(self.bounds);
|
||||
NSRectFill(dirtyRect);
|
||||
|
||||
// Calculate the position of the expression (probably also forces layout of the expression the first time)
|
||||
NSPoint expressionOrigin = self.expressionOrigin;
|
||||
|
||||
Reference in New Issue
Block a user