diff options
| author | Pietro Gagliardi <[email protected]> | 2015-04-07 16:12:28 -0400 |
|---|---|---|
| committer | Pietro Gagliardi <[email protected]> | 2015-04-07 16:12:28 -0400 |
| commit | 3969095a33a518023564ec32f8373bbad913b6c3 (patch) | |
| tree | 70151d144d7bb03bc7e7f51edb915e6142c06d5b | |
| parent | 96e25cf50293d2c8f33bbd4d2578a4e2b63441f9 (diff) | |
Implemented uiButton on Mac OS X. Now to fix build issues and test...
| -rw-r--r-- | new/button_darwin.m | 57 | ||||
| -rw-r--r-- | new/uipriv_darwin.h | 3 | ||||
| -rw-r--r-- | new/util_darwin.m | 8 |
3 files changed, 68 insertions, 0 deletions
diff --git a/new/button_darwin.m b/new/button_darwin.m new file mode 100644 index 0000000..85d25fa --- /dev/null +++ b/new/button_darwin.m @@ -0,0 +1,57 @@ +// 7 april 2015 +#import "uipriv_darwin.h" + +@interface button : NSObject +@property uiControl *c; +@property void (*onClicked)(uiControl *, void *); +@property void *onClickedData; +@end + +@implementation button + +- (IBAction)buttonClicked:(id)sender +{ + (*(self.onClicked))(self.c, self.onClickedData); +} + +@end + +static void defaultOnClicked(uiControl *c, void *data) +{ + // do nothing +} + +// TODO destruction +uiControl *uiNewButton(const char *text) +{ + button *b; + NSButton *bb; + + b = [button new]; + b->c = uiDarwinNewControl([NSButton class], NO, NO, b); + + bb = (NSButton *) uiDarwinControlData(b->c); + [bb setTitle:toNSString(text)]; + [bb setButtonType:NSMomentaryPushInButton]; + [bb setBordered:YES]; + [bb setBezelStyle:NSRoundedBezelStyle]; + setStandardControlFont((NSControl *) bb); + + [bb setTarget:b]; + [bb setAction:@selector(buttonClicked:)]; + + b->onClicked = defaultOnClicked; + + return b->c; +} + +// TODO text + +void uiButtonOnClicked(uiControl *c, void (*f)(uiControl *, void *), void *data) +{ + button *b; + + b = (button *) uiDarwinControlData(c); + b->onClicked = f; + b->onClickedData = data; +} diff --git a/new/uipriv_darwin.h b/new/uipriv_darwin.h index f45b8e6..c613810 100644 --- a/new/uipriv_darwin.h +++ b/new/uipriv_darwin.h @@ -12,6 +12,9 @@ extern void *uiAlloc(size_t); extern void *uiRealloc(void *, size_t); extern void uiFree(void *); +// util_darwin.m +extern void setStandardControlFont(NSControl *); + // container_darwin.m @interface uiContainer : NSView @property uiControl *child; diff --git a/new/util_darwin.m b/new/util_darwin.m new file mode 100644 index 0000000..d8166e9 --- /dev/null +++ b/new/util_darwin.m @@ -0,0 +1,8 @@ +// 7 april 2015 +#import "uipriv_darwin.h" + +// also fine for NSCells and NSTexts (NSTextViews) +void setStandardControlFont(NSControl *control) +{ + [control setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSRegularControlSize]]]; +} |
