Added MPExpressionLayout, MPFunctionLayout and MPExpressionStorage as Rendering System for Expressions
This commit is contained in:
@@ -7,23 +7,73 @@
|
||||
//
|
||||
|
||||
#import "MPExpressionView.h"
|
||||
#import "MPExpressionLayout.h"
|
||||
#import "MPExpressionStorage.h"
|
||||
|
||||
#import "NSObject+MPStringTest.h"
|
||||
|
||||
#import "MPSumFunction.h"
|
||||
|
||||
@interface MPExpressionView ()
|
||||
@end
|
||||
|
||||
@implementation MPExpressionView
|
||||
|
||||
#pragma mark Creation Methods
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[self initializeObjects];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithFrame:(NSRect)frame
|
||||
{
|
||||
self = [super initWithFrame:frame];
|
||||
if (self) {
|
||||
// Initialization code here.
|
||||
[self initializeObjects];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (id)initWithCoder:(NSCoder *)aDecoder
|
||||
{
|
||||
self = [super initWithCoder:aDecoder];
|
||||
if (self) {
|
||||
[self initializeObjects];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)initializeObjects
|
||||
{
|
||||
MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithSymbols:@[@"12345", [[MPSumFunction alloc] init]]];
|
||||
_expressionStorage = expressionStorage;
|
||||
}
|
||||
|
||||
#pragma mark Properties
|
||||
|
||||
- (MPExpressionLayout *)expressionLayout
|
||||
{
|
||||
return self.expressionStorage.expressionLayout;
|
||||
}
|
||||
|
||||
#pragma mark Drawing Methods
|
||||
|
||||
- (void)drawRect:(NSRect)dirtyRect
|
||||
{
|
||||
[super drawRect:dirtyRect];
|
||||
|
||||
// Drawing code here.
|
||||
[[NSColor whiteColor] set];
|
||||
NSRectFill(self.bounds);
|
||||
[[NSColor blackColor] set];
|
||||
NSSize expressionSize = [self.expressionLayout sizeForAllSymbols];
|
||||
CGFloat y = (self.bounds.size.height - expressionSize.height) / 2;
|
||||
NSLog(@"%f", self.bounds.origin.y);
|
||||
NSPoint point = NSMakePoint(self.bounds.origin.x, self.bounds.origin.y + y);
|
||||
[self.expressionLayout drawAllSymbolsAtPoint:point];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
Reference in New Issue
Block a user