Preliminary Cocoa Bindings Support

dev
Armando Rivera 3 years ago
parent 1e1baf56b3
commit ac9ab914b9
  1. 3
      src/cocoa/NSFunctions.nim
  2. 6
      src/cocoa/widgets/bind.m
  3. 35
      src/cocoa/widgets/checkbox.m
  4. 15
      src/cocoa/widgets/col.h
  5. 63
      src/cocoa/widgets/colordialog.m

@ -1,4 +1,5 @@
{.compile: "widgets/functions.m".}
{.compile: "widgets/bind.m".}
type
ID* = pointer
@ -75,3 +76,5 @@ proc hexColor*(cPanel: ID): cstring {.cdecl, importc: "hexColor".}
proc Notify*(title: cstring; subtitle: cstring; text: cstring) {.cdecl, importc: "Notify".}
proc newSeparator*(parent: ID; x: cint; y: cint; width: cint): ID {.cdecl, importc: "createLine".}
proc link*( widget: ID, widgetIvar: cstring, target: ID, targetIvar: cstring) {.cdecl, importc:"bind".}

@ -0,0 +1,6 @@
#import <Cocoa/Cocoa.h>
void bind( id widget, const char * widgetIvar, id target, const char *targetIvar) {
[widget bind: [NSString stringWithUTF8String: widgetIvar] toObject: target withKeyPath:[NSString stringWithUTF8String: targetIvar] options:nil];
}

@ -2,15 +2,38 @@
#import "col.h"
@interface CocoaCheckbox : NSButton
{
int state;
}
@property int state;
- (void) click:(id)sender;
@end
@implementation CocoaCheckbox
@synthesize state;
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self setButtonType:NSSwitchButton];
[self setBezelStyle: 0];
[self setTarget: self];
[self setAction: @selector(click:)];
}
return self;
}
- (void) click:(id)sender {
self.state = [self intValue];
}
@end
id createCheckBox(id parent, const char* caption, int l, int t, int w, int h){
NSButton *self = [[[NSButton alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease];
[self setButtonType:NSSwitchButton];
[self setBezelStyle: 0];
id self = [[[CocoaCheckbox alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease];
[self setTitle: [NSString stringWithUTF8String:caption]];
[self setTarget: self];
addToParent(parent, self);

@ -110,6 +110,8 @@
- (void)colorUpdate:(NSColorPanel*)colorPanel;
-(void)changeColor:(id)sender;
- (const char *) hexColor;
@end
@ -524,7 +526,9 @@
*/
id createColorDialog();
const char *getColor(id panel);
id getColor(id panel);
void setColor(id target, id source);
const char* hexColor(id cPanel);
id createLabel(id parent, const char* txt, int l, int t, int w, int h);
@ -581,6 +585,15 @@
id createSlider(id parent, int left, int top, int width, int height, ACTION callback);
void addToParent(id parent, id child);
id createBox(id parent, const char* title, int x, int y, int width, int height);
id createRadioButton(id parent, const char* caption, int l, int t, int w, int h, ACTION func);
id createTabView(id parent, const char *label, int x, int y, int width, int height);
void addTab(id parent, const char *name);
id getTab(id parent, const char *name);
#ifdef __cplusplus
}
#endif

@ -37,62 +37,11 @@ id createColorDialog() {
const char* hexColor(awColorPanel* cPanel) {
return [cPanel hexColor];
}
// @interface NSColorPanel (CPL)
//
// - (void)disablePanel;
// - (void)enablePanel;
// + (NSString *)strColor;
//
// @end
//
// #include <tgmath.h>
//
// static BOOL colorPanelEnabled = YES;
//
//
// @implementation NSColorPanel (CPL)
//
// - (void)disablePanel {
// colorPanelEnabled = NO;
// }
//
// - (void)enablePanel {
// colorPanelEnabled = YES;
// }
// - (void)orderFront:(id)sender {
// if (colorPanelEnabled) {
// NSColorPanel *panel = [BFColorPickerPopover sharedPopover].colorPanel;
// if (panel) {
// self.contentView = panel.contentView;
// }
// [super orderFront:sender];
// } else {
// // Don't do anything.
// }
// }
// + (NSString *)strColor {
// NSColorPanel *panel = [NSColorPanel sharedColorPanel];
// [panel orderFront:nil];
// NSColor *color = [panel.color colorUsingColorSpaceName: NSDeviceRGBColorSpace];
// return [NSString stringWithFormat:@"r: %d, g: %d, b: %d, a: %d",
// (int)round([color redComponent]*255),
// (int)round([color greenComponent]*255),
// (int)round([color blueComponent]*255),
// (int)round([color alphaComponent]*255)];
// // return @"";
// }
// @end
id getColor(id panel) {
return theColor;
}
// const char* ColorDialog() {
// NSColorPanel *panel = [NSColorPanel sharedColorPanel];
// [panel orderFront:nil];
// NSString *aColor = [NSColorPanel strColor];
// return [[NSString stringWithFormat:@"r: %d, g: %d, b: %d, a: %d",
// (int)round([color redComponent]*255),
// (int)round([color greenComponent]*255),
// (int)round([color blueComponent]*255),
// (int)round([color alphaComponent]*255)] UTF8String];
// return [aColor UTF8String];
// }
void setColor(id target, id source) {
[target setBackgroundColor: [source color]];
}
Loading…
Cancel
Save