From 67c45eab1f8464fad787a7b57bfbd60231469e37 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Thu, 11 Oct 2018 21:55:29 +0100 Subject: [PATCH] auto select a suitable titlebar foreground based on background text. --- src/Avalonia.Native.OSX/window.mm | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Avalonia.Native.OSX/window.mm b/src/Avalonia.Native.OSX/window.mm index debc8d7e1a..f61c2b42bc 100644 --- a/src/Avalonia.Native.OSX/window.mm +++ b/src/Avalonia.Native.OSX/window.mm @@ -981,6 +981,17 @@ private: auto nscolor = [NSColor colorWithSRGBRed:r green:g blue:b alpha:a]; + // Based on the titlebar color we have to choose either light or dark + // OSX doesnt let you set a foreground color for titlebar. + if ((r*0.299 + g*0.587 + b*0.114) > 186.0f / 255.0f) + { + [Window setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameVibrantLight]]; + } + else + { + [Window setAppearance:[NSAppearance appearanceNamed:NSAppearanceNameVibrantDark]]; + } + [Window setTitlebarAppearsTransparent:true]; [Window setBackgroundColor:nscolor]; }