darlinghq / darling

Darwin/macOS emulation layer for Linux
http://www.darlinghq.org
GNU General Public License v3.0
11.53k stars 444 forks source link

Colored Tabs aren't colored #674

Open TheBrokenRail opened 4 years ago

TheBrokenRail commented 4 years ago

Screenshot from 2020-02-17 18-27-42 Example Code:

#include <Cocoa/Cocoa.h>

@interface Form : NSWindow {
  NSTabViewItem* tabPageRed;
  NSTabViewItem* tabPageGreen;
  NSTabViewItem* tabPageBlue;
  NSTabViewItem* tabPageYellow;
  NSTabView* tabControl;
}
- (instancetype)init;
- (BOOL)windowShouldClose:(id)sender;
@end

@implementation Form
- (instancetype)init {
  NSTabViewItem* tabPageRed = [[NSTabViewItem alloc] init];
  [tabPageRed setLabel:@"Red"];
  [[tabPageRed view] setWantsLayer:YES];
  [[[tabPageRed view] layer] setBackgroundColor:[NSColor redColor].CGColor];

  tabPageGreen = [[NSTabViewItem alloc] init];
  [tabPageGreen setLabel:@"Green"];
  [[tabPageGreen view] setWantsLayer:YES];
  [[[tabPageGreen view] layer] setBackgroundColor:[NSColor greenColor].CGColor];

  tabPageBlue = [[NSTabViewItem alloc] init];
  [tabPageBlue setLabel:@"Blue"];
  [[tabPageBlue view] setWantsLayer:YES];
  [[[tabPageBlue view] layer] setBackgroundColor:[NSColor blueColor].CGColor];

  tabPageYellow = [[NSTabViewItem alloc] init];
  [tabPageYellow setLabel:@"Yellow"];
  [[tabPageYellow view] setWantsLayer:YES];
  [[[tabPageYellow view] layer] setBackgroundColor:[NSColor yellowColor].CGColor];

  tabControl = [[NSTabView alloc] initWithFrame:NSMakeRect(10, 10, 370, 250)];
  [tabControl insertTabViewItem:tabPageRed atIndex:0];
  [tabControl insertTabViewItem:tabPageGreen atIndex:1];
  [tabControl insertTabViewItem:tabPageBlue atIndex:2];
  [tabControl insertTabViewItem:tabPageYellow atIndex:3];

  [super initWithContentRect:NSMakeRect(100, 100, 390, 270) styleMask:NSWindowStyleMaskTitled | NSWindowStyleMaskClosable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable backing:NSBackingStoreBuffered defer:NO];
  [self setTitle:@"TabControl example"];
  [[self contentView] addSubview:tabControl];
  [self center];
  [self setIsVisible:YES];
  return self;
}

- (BOOL)windowShouldClose:(id)sender {
  [NSApp terminate:sender];
  return YES;
}
@end

int main(int argc, char* argv[]) {
  [NSApplication sharedApplication];
  [[[[Form alloc] init] autorelease] makeMainWindow];
  [NSApp run];
}
mrolappe commented 2 years ago

The issue here is that, compared to OSX, under Darling an NSTabViewItem does not have a view assigned after having been created and initialized. The corresponding calls (setWantsLayer, layer) therefore have no effect.