Added Functions Popover Template
This commit is contained in:
BIN
MathKit/FunctionsButtonDisclosure.png
Normal file
BIN
MathKit/FunctionsButtonDisclosure.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.8 KiB |
BIN
MathKit/FunctionsButtonDisclosure@2x.png
Normal file
BIN
MathKit/FunctionsButtonDisclosure@2x.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 3.9 KiB |
@@ -28,4 +28,7 @@
|
|||||||
@property (nonatomic, weak) id target;
|
@property (nonatomic, weak) id target;
|
||||||
@property (nonatomic) SEL action;
|
@property (nonatomic) SEL action;
|
||||||
|
|
||||||
|
#pragma mark Actions
|
||||||
|
- (IBAction)showFunctions:(id)sender;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -68,7 +68,7 @@
|
|||||||
{
|
{
|
||||||
NSRect expressionBounds = [self.expressionStorage.rootLayout bounds];
|
NSRect expressionBounds = [self.expressionStorage.rootLayout bounds];
|
||||||
CGFloat y = (self.bounds.size.height - expressionBounds.size.height) / 2 + fabs(expressionBounds.origin.y);
|
CGFloat y = (self.bounds.size.height - expressionBounds.size.height) / 2 + fabs(expressionBounds.origin.y);
|
||||||
return NSMakePoint(0, y);
|
return NSMakePoint(10, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
@@ -303,14 +303,25 @@
|
|||||||
- (void)initializeExpressionView
|
- (void)initializeExpressionView
|
||||||
{
|
{
|
||||||
// Setup the Expression Storage
|
// 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.expressionView = self;
|
||||||
_expressionStorage = expressionStorage;
|
_expressionStorage = expressionStorage;
|
||||||
|
|
||||||
|
NSBundle *frameworkBundle = [NSBundle bundleForClass:[self class]];
|
||||||
|
NSImage *image = [frameworkBundle imageForResource:@"FunctionsButtonDisclosure"];
|
||||||
|
[image setName:@"FunctionsButtonDisclosure"];
|
||||||
// Setup the Functions Button
|
// Setup the Functions Button
|
||||||
NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect];
|
NSButton *button = [[NSButton alloc] initWithFrame:NSZeroRect];
|
||||||
button.buttonType = NSSwitchButton;
|
button.target = self;
|
||||||
[button setTitle:@"Functions"];
|
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.functionsButton = button;
|
||||||
[self addSubview:self.functionsButton];
|
[self addSubview:self.functionsButton];
|
||||||
|
|
||||||
@@ -336,6 +347,20 @@
|
|||||||
self.needsDisplay = YES;
|
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
|
#pragma mark NSView Stuff
|
||||||
- (BOOL)acceptsFirstResponder
|
- (BOOL)acceptsFirstResponder
|
||||||
{
|
{
|
||||||
@@ -357,10 +382,16 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)setFrame:(NSRect)frameRect
|
||||||
|
{
|
||||||
|
[self setNeedsLayout:YES];
|
||||||
|
[super setFrame:frameRect];
|
||||||
|
}
|
||||||
|
|
||||||
- (void)layout
|
- (void)layout
|
||||||
{
|
{
|
||||||
NSSize buttonSize = [self.functionsButton fittingSize];
|
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,
|
(self.bounds.size.height - buttonSize.height) / 2,
|
||||||
buttonSize.width,
|
buttonSize.width,
|
||||||
buttonSize.height);
|
buttonSize.height);
|
||||||
@@ -369,9 +400,9 @@
|
|||||||
|
|
||||||
- (NSSize)intrinsicContentSize
|
- (NSSize)intrinsicContentSize
|
||||||
{
|
{
|
||||||
// return NSMakeSize(500, 500);
|
NSSize size = self.expressionStorage.rootLayout.bounds.size;
|
||||||
// return self.bounds.size;
|
size.width += 100;
|
||||||
return self.expressionStorage.rootLayout.bounds.size;
|
return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)resetCursorRects
|
- (void)resetCursorRects
|
||||||
|
|||||||
Reference in New Issue
Block a user