Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,13 @@
|
|||
#include <Foundation/Foundation.h>
|
||||
#include <AppKit/AppKit.h>
|
||||
|
||||
@interface ClickMe : NSWindow
|
||||
{
|
||||
NSButton *_button;
|
||||
NSTextField *_text;
|
||||
int _counter;
|
||||
}
|
||||
- (void)applicationDidFinishLaunching: (NSNotification *)notification;
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification;
|
||||
- (void)advanceCounter: (id)sender;
|
||||
@end
|
||||
|
|
@ -0,0 +1,71 @@
|
|||
@implementation ClickMe : NSWindow
|
||||
-(instancetype) init
|
||||
{
|
||||
NSButton *button = [[NSButton alloc] init];
|
||||
[button setButtonType: NSToggleButton];
|
||||
[button setTitle: @"Click Me"];
|
||||
[button sizeToFit];
|
||||
[button setTarget: self];
|
||||
[button setAction: @selector(advanceCounter:)];
|
||||
NSRect buttonRect = [button frame];
|
||||
|
||||
NSTextField *text = [[NSTextField alloc]
|
||||
initWithFrame: NSMakeRect(buttonRect.origin.x, buttonRect.size.height,
|
||||
buttonRect.size.width, buttonRect.size.height)];
|
||||
[text setAlignment: NSCenterTextAlignment];
|
||||
[text setEditable: NO];
|
||||
[text setStringValue: @"There have been no clicks yet"];
|
||||
[text sizeToFit];
|
||||
|
||||
// reset size of button according to size of (larger...?) text
|
||||
[button
|
||||
setFrameSize: NSMakeSize( [text frame].size.width, buttonRect.size.height ) ];
|
||||
|
||||
int totalWindowHeight = buttonRect.size.height + [text frame].size.height;
|
||||
|
||||
if ((self = [super initWithContentRect: NSMakeRect(100, 100,
|
||||
[text frame].size.width, totalWindowHeight)
|
||||
styleMask: (NSTitledWindowMask | NSClosableWindowMask)
|
||||
backing: NSBackingStoreBuffered
|
||||
defer: NO])) {
|
||||
_counter = 0;
|
||||
_button = button;
|
||||
_text = text;
|
||||
|
||||
[[self contentView] addSubview: _text];
|
||||
[[self contentView] addSubview: _button];
|
||||
|
||||
[self setTitle: @"Click Me!"];
|
||||
[self center];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
|
||||
- (void)applicationDidFinishLaunching: (NSNotification *)notification
|
||||
{
|
||||
[self orderFront: self];
|
||||
}
|
||||
|
||||
- (BOOL)applicationShouldTerminateAfterLastWindowClosed: (NSNotification *)notification
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
|
||||
- (void)advanceCounter: (id)sender
|
||||
{
|
||||
[_text setStringValue: [NSString stringWithFormat: @"Clicked %d times", ++_counter]];
|
||||
}
|
||||
@end
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
@autoreleasepool {
|
||||
NSApplication *app = [NSApplication sharedApplication];
|
||||
ClickMe *clickme = [[ClickMe alloc] init];
|
||||
[app setDelegate: clickme];
|
||||
[app run];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue