mirror of
https://github.com/Airr/nim-cocoa.git
synced 2025-04-17 12:52:07 +00:00
Added support for NSTabView
This commit is contained in:
parent
3b62fb5646
commit
d1ab52dabc
@ -4,4 +4,5 @@ import NSFunctions
|
||||
|
||||
proc newTabBox*(parent: ID, label: cstring; left: cint; top: cint; width: cint; height: cint): ID {.cdecl, importc: "createTabView".}
|
||||
|
||||
proc addTab*(parent: ID, label: cstring) {.cdecl, importc: "addTab".}
|
||||
proc addTab*(parent: ID, label: cstring) {.cdecl, importc: "addTab".}
|
||||
proc getTab*(parent: ID, label: cstring): ID {.cdecl, importc: "getTab".}
|
@ -27,7 +27,8 @@ id createButton(id parent, const char* caption, int l, int t, int w, int h, ACTI
|
||||
[widget setButtonAction:func];
|
||||
[widget setAction: @selector(click:)];
|
||||
}
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
@ -12,7 +12,8 @@ id createCheckBox(id parent, const char* caption, int l, int t, int w, int h){
|
||||
[self setTitle: [NSString stringWithUTF8String:caption]];
|
||||
[self setTarget: self];
|
||||
|
||||
[[parent contentView] addSubview:self];
|
||||
addToParent(parent, self);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -580,6 +580,7 @@
|
||||
|
||||
id createSlider(id parent, int left, int top, int width, int height, ACTION callback);
|
||||
|
||||
void addToParent(id parent, id child);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
@ -37,7 +37,8 @@ id createComboBox(id parent,int l, int t, int w, int h, ACTION callback){
|
||||
// [widget setAction: @selector(click:)];
|
||||
}
|
||||
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
@ -12,6 +12,6 @@ id createBox(id parent, const char* title, int x, int y, int width, int height)
|
||||
[sv setBackgroundColor: [NSColor windowBackgroundColor]];
|
||||
[widget setContentView: sv];
|
||||
[widget setBorderType: NSLineBorder];
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
return widget;
|
||||
}
|
@ -156,3 +156,12 @@ void Notify(const char *title, const char * subtitle, const char *text) {
|
||||
|
||||
}
|
||||
|
||||
void addToParent(id parent, id child) {
|
||||
NSString *widgetClass = [[parent class] description];
|
||||
if ([widgetClass isEqualToString:@"NSTabViewItem"]) {
|
||||
[[parent view] addSubview: child];
|
||||
} else {
|
||||
[[parent contentView] addSubview: child];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,6 @@ id createLabel(id parent, const char* txt, int l, int t, int w, int h){
|
||||
[widget setAlignment: NSTextAlignmentLeft];
|
||||
[widget setDrawsBackground: NO];
|
||||
[widget setBordered: NO];
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
return widget;
|
||||
}
|
||||
|
@ -5,7 +5,7 @@
|
||||
id createLine(id parent, int x, int y, int width) {
|
||||
NSBox *widget = [[[NSBox alloc] initWithFrame:NSMakeRect(x,y,width,1)] autorelease];
|
||||
widget.boxType = NSBoxSeparator;
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
@ -80,6 +80,6 @@
|
||||
|
||||
id createListBox(id parent,int l, int t, int w, int h){
|
||||
id self = [[[CocoaListBox alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease];
|
||||
[[parent contentView] addSubview:self];
|
||||
addToParent(parent, self);
|
||||
return self;
|
||||
}
|
||||
|
@ -23,6 +23,8 @@ id createRadioButton(id parent, const char* caption, int l, int t, int w, int h,
|
||||
[self setButtonAction:func];
|
||||
[self setAction: @selector(click:)];
|
||||
}
|
||||
[[parent contentView] addSubview:self];
|
||||
|
||||
addToParent(parent, self);
|
||||
|
||||
return self;
|
||||
}
|
@ -33,6 +33,6 @@
|
||||
id createSlider(id parent, int left, int top, int width, int height, ACTION callback) {
|
||||
id widget = [[CocoaSlider alloc] initWithFrame:NSMakeRect(left, top, width, height) callBack:callback];
|
||||
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, self);
|
||||
return widget;
|
||||
}
|
||||
|
@ -11,11 +11,16 @@ id createTabView(id parent, const char *label, int x, int y, int width, int heig
|
||||
|
||||
|
||||
for(NSString *x in items) {
|
||||
id sv = [[[SaneView alloc] initWithFrame: NSZeroRect] autorelease];
|
||||
[sv setBackgroundColor: [NSColor windowBackgroundColor]];
|
||||
|
||||
|
||||
id *tabwidget = [[[NSTabViewItem alloc] initWithIdentifier: x ] autorelease];
|
||||
[tabwidget setLabel: x];
|
||||
[tabwidget setView: sv];
|
||||
[widget addTabViewItem: tabwidget];
|
||||
}
|
||||
|
||||
|
||||
[[parent contentView] addSubview:widget];
|
||||
return widget;
|
||||
}
|
||||
@ -29,4 +34,11 @@ void addTab(id parent, const char *name) {
|
||||
[widget setLabel: x];
|
||||
[parent addTabViewItem: widget];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
id getTab(id parent, const char *name) {
|
||||
NSString *str = [NSString stringWithUTF8String:name];
|
||||
NSInteger index = [parent indexOfTabViewItemWithIdentifier: str];
|
||||
// NSLog(@"%@", [[parent tabViewItemAtIndex: index] view]);
|
||||
return [parent tabViewItemAtIndex: index];
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ id createTextEdit(id parent, const char* txt, int l, int t, int w, int h) {
|
||||
[[widget documentView] setString:str];
|
||||
}
|
||||
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
return widget;
|
||||
}
|
||||
|
||||
|
@ -6,6 +6,6 @@ id createTextField(id parent, const char* txt, int l, int t, int w, int h){
|
||||
NSTextField *widget = [[[NSTextField alloc] initWithFrame:NSMakeRect( l, t, w, h )] autorelease];
|
||||
[widget setStringValue:[NSString stringWithUTF8String:txt]];
|
||||
// [widget setAutoresizingMask: NSViewWidthSizable];
|
||||
[[parent contentView] addSubview:widget];
|
||||
addToParent(parent, widget);
|
||||
return widget;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user