diff --git a/MathKit/FunctionsButtonDisclosure.png b/MathKit/FunctionsButtonDisclosure.png new file mode 100644 index 0000000..ec4a662 Binary files /dev/null and b/MathKit/FunctionsButtonDisclosure.png differ diff --git a/MathKit/FunctionsButtonDisclosure@2x.png b/MathKit/FunctionsButtonDisclosure@2x.png new file mode 100644 index 0000000..8e14517 Binary files /dev/null and b/MathKit/FunctionsButtonDisclosure@2x.png differ diff --git a/MathPad/MPExpressionView.h b/MathPad/MPExpressionView.h index 97f6cc3..3da1ec9 100644 --- a/MathPad/MPExpressionView.h +++ b/MathPad/MPExpressionView.h @@ -28,4 +28,7 @@ @property (nonatomic, weak) id target; @property (nonatomic) SEL action; +#pragma mark Actions +- (IBAction)showFunctions:(id)sender; + @end diff --git a/MathPad/MPExpressionView.m b/MathPad/MPExpressionView.m index 747b241..79e2183 100644 --- a/MathPad/MPExpressionView.m +++ b/MathPad/MPExpressionView.m @@ -68,7 +68,7 @@ { NSRect expressionBounds = [self.expressionStorage.rootLayout bounds]; CGFloat y = (self.bounds.size.height - expressionBounds.size.height) / 2 + fabs(expressionBounds.origin.y); - return NSMakePoint(0, y); + return NSMakePoint(10, y); } @end @@ -303,14 +303,25 @@ - (void)initializeExpressionView { // Setup the Expression Storage - MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithElements:@[@"12345", [[MPSumFunction alloc] init]]]; + MPExpressionStorage *expressionStorage = [[MPExpressionStorage alloc] initWithElements:@[@"12345", [[MPSumFunction alloc] init], [[MPSumFunction alloc] init]]]; expressionStorage.expressionView = self; _expressionStorage = expressionStorage; + NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]]; + NSImage *image = [frameworkBundle imageForResource:@"FunctionsButtonDisclosure"]; + [image setName:@"FunctionsButtonDisclosure"]; // Setup the Functions Button NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect]; - button.buttonType = NSSwitchButton; - [button setTitle:@"Functions"]; + button.target = self; + button.action = @selector(showFunctions:); + button.buttonType = NSMomentaryChangeButton; + button.bezelStyle = NSShadowlessSquareBezelStyle; + button.bordered = NO; + NSFont *font = [NSFont fontWithName:@"Times New Roman" size:25.0]; + NSAttributedString *attributedTitle = [[NSAttributedString alloc] initWithString:@"Σ" attributes:@{NSFontAttributeName: font, NSForegroundColorAttributeName: [NSColor colorWithWhite:.61 alpha:1]}]; + button.attributedTitle = attributedTitle; + button.imagePosition = NSImageLeft; + button.image = image; self.functionsButton = button; [self addSubview:self.functionsButton]; @@ -336,6 +347,20 @@ self.needsDisplay = YES; } +#pragma mark Actions +- (void)showFunctions:(id)sender +{ + NSViewController *controller = [[NSViewController alloc] initWithNibName:nil + bundle:nil]; + controller.view = [[NSView alloc] init]; + NSPopover *popover = [[NSPopover alloc] init]; + popover.contentSize = NSMakeSize(100.0, 100.0); + popover.contentViewController = controller; + popover.animates = YES; + popover.behavior = NSPopoverBehaviorSemitransient; + [popover showRelativeToRect:[sender bounds] ofView:sender preferredEdge:NSMaxYEdge]; +} + #pragma mark NSView Stuff - (BOOL)acceptsFirstResponder { @@ -357,10 +382,16 @@ return YES; } +- (void)setFrame:(NSRect)frameRect +{ + [self setNeedsLayout:YES]; + [super setFrame:frameRect]; +} + - (void)layout { NSSize buttonSize = [self.functionsButton fittingSize]; - self.functionsButton.frame = NSMakeRect(self.bounds.size.width - buttonSize.width, + self.functionsButton.frame = NSMakeRect(self.bounds.size.width - buttonSize.width - 10, (self.bounds.size.height - buttonSize.height) / 2, buttonSize.width, buttonSize.height); @@ -369,9 +400,9 @@ - (NSSize)intrinsicContentSize { -// return NSMakeSize(500, 500); -// return self.bounds.size; - return self.expressionStorage.rootLayout.bounds.size; + NSSize size = self.expressionStorage.rootLayout.bounds.size; + size.width += 100; + return size; } - (void)resetCursorRects