Archived
1

Added Functions Popover Template

This commit is contained in:
Kim Wittenburg
2014-09-15 15:57:57 +02:00
parent 8ee34b639d
commit 6573cd1b5c
4 changed files with 42 additions and 8 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

View File

@@ -28,4 +28,7 @@
@property (nonatomic, weak) id target;
@property (nonatomic) SEL action;
#pragma mark Actions
- (IBAction)showFunctions:(id)sender;
@end

View File

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