From 4eaf087bf3db0faf8edb25045907841252261071 Mon Sep 17 00:00:00 2001 From: Ian Bastos Date: Sun, 12 Jan 2020 02:33:19 +0000 Subject: [PATCH 1/4] ignore build folder --- .gitignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file From 544987f19a59a0e2d419e0a1c01472cba67d11f1 Mon Sep 17 00:00:00 2001 From: Ian Bastos Date: Sun, 12 Jan 2020 03:17:26 +0000 Subject: [PATCH 2/4] render multiline text white on dark mode - darwin --- darwin/multilineentry.m | 19 +++++++++++++++++-- darwin/util.h | 2 ++ darwin/util.m | 6 ++++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 darwin/util.h diff --git a/darwin/multilineentry.m b/darwin/multilineentry.m index d57284a05..a03c73e88 100644 --- a/darwin/multilineentry.m +++ b/darwin/multilineentry.m @@ -1,10 +1,11 @@ // 8 december 2015 #import "uipriv_darwin.h" +#include "util.h" // NSTextView has no intrinsic content size by default, which wreaks havoc on a pure-Auto Layout system // we'll have to take over to get it to work // see also http://stackoverflow.com/questions/24210153/nstextview-not-properly-resizing-with-auto-layout and http://stackoverflow.com/questions/11237622/using-autolayout-with-expanding-nstextviews -@interface intrinsicSizeTextView : NSTextView { +@interface intrinsicSizeTextView : NSTextView { uiMultilineEntry *libui_e; } - (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e; @@ -25,11 +26,19 @@ @implementation intrinsicSizeTextView - (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e { self = [super initWithFrame:r]; + self.delegate = self; if (self) self->libui_e = e; return self; } +- (void)textDidChange:(NSNotification *)aNotification { + NSTextView *tv = (NSTextView *)[aNotification object]; + if (isDarkMode()) { + [tv setTextColor:[NSColor whiteColor]]; + } +} + - (NSSize)intrinsicContentSize { NSTextContainer *textContainer; @@ -130,7 +139,6 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) // NSText properties: // this is what Interface Builder sets the background color to - [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; [e->tv setDrawsBackground:YES]; [e->tv setEditable:YES]; [e->tv setSelectable:YES]; @@ -139,6 +147,13 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) [e->tv setImportsGraphics:NO]; [e->tv setUsesFontPanel:NO]; [e->tv setRulerVisible:NO]; + + if (isDarkMode()) { + [e->tv setBackgroundColor:[NSColor windowBackgroundColor]]; + } else { + [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; + } + // we'll handle font last // while setAlignment: has been around since 10.0, the named constant "NSTextAlignmentNatural" seems to have only been introduced in 10.11 #define ourNSTextAlignmentNatural 4 diff --git a/darwin/util.h b/darwin/util.h new file mode 100644 index 000000000..1b539370c --- /dev/null +++ b/darwin/util.h @@ -0,0 +1,2 @@ + +bool isDarkMode(); diff --git a/darwin/util.m b/darwin/util.m index 418d958e0..be392731b 100644 --- a/darwin/util.m +++ b/darwin/util.m @@ -14,3 +14,9 @@ void uiprivDisableAutocorrect(NSTextView *tv) [tv setAutomaticLinkDetectionEnabled:NO]; [tv setSmartInsertDeleteEnabled:NO]; } + +bool isDarkMode() +{ + NSString *osxMode = [[NSUserDefaults standardUserDefaults] stringForKey:@"AppleInterfaceStyle"]; + return [osxMode isEqualToString:@"Dark"]; +} From 14288b9b0cff5ff0dcbfa3d13db8d8a92d17300f Mon Sep 17 00:00:00 2001 From: Ian Bastos Date: Sun, 12 Jan 2020 15:07:36 +0000 Subject: [PATCH 3/4] performance improvement on textDidChange method --- darwin/multilineentry.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/darwin/multilineentry.m b/darwin/multilineentry.m index a03c73e88..6613a84e0 100644 --- a/darwin/multilineentry.m +++ b/darwin/multilineentry.m @@ -32,11 +32,13 @@ - (id)initWithFrame:(NSRect)r e:(uiMultilineEntry *)e return self; } +// [e->tv setTextColor:[NSColor textColor]] in finishMultilineentry +// does not work due to an cocoa bug which stops the text +// from changing pre control initialization so we resort +// to changing the text on the delegate method instead - (void)textDidChange:(NSNotification *)aNotification { NSTextView *tv = (NSTextView *)[aNotification object]; - if (isDarkMode()) { - [tv setTextColor:[NSColor whiteColor]]; - } + [tv setTextColor:[NSColor textColor]]; } - (NSSize)intrinsicContentSize @@ -149,7 +151,7 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) [e->tv setRulerVisible:NO]; if (isDarkMode()) { - [e->tv setBackgroundColor:[NSColor windowBackgroundColor]]; + [e->tv setBackgroundColor:[NSColor controlBackgroundColor]]; } else { [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; } From 0316998e1c68ba44907289183d785433a3384a72 Mon Sep 17 00:00:00 2001 From: Ian Bastos Date: Sun, 12 Jan 2020 17:56:36 +0000 Subject: [PATCH 4/4] set dark mode background for multiline control --- darwin/multilineentry.m | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/darwin/multilineentry.m b/darwin/multilineentry.m index 6613a84e0..88b35661b 100644 --- a/darwin/multilineentry.m +++ b/darwin/multilineentry.m @@ -151,7 +151,7 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) [e->tv setRulerVisible:NO]; if (isDarkMode()) { - [e->tv setBackgroundColor:[NSColor controlBackgroundColor]]; + e->tv.backgroundColor = NSColor.textBackgroundColor; } else { [e->tv setBackgroundColor:[NSColor colorWithCalibratedWhite:1.0 alpha:1.0]]; } @@ -234,6 +234,11 @@ void uiMultilineEntrySetReadOnly(uiMultilineEntry *e, int readonly) p.VScroll = YES; e->sv = uiprivMkScrollView(&p, &(e->d)); + if (isDarkMode()) { + e->sv.drawsBackground= YES; + e->sv.backgroundColor = NSColor.textBackgroundColor; + } + uiMultilineEntryOnChanged(e, defaultOnChanged, NULL); return e;