I use NSToolbarMBS.
How I can change colors of toolbars like macOS Mojave?
How I can change the window title colors?
but the standard toolbar MacOS does not change color by itself?
same thing applies to the title bar?
I thought to check if the “Dark Mode” was active and change the colors accordingly. But in this way I should hide the title and color the window pretending a title bar. And how do I change the color of the toolbar?
I have the same question. I am using CustomNSToolbarMBS and my code crashes somewhere in there, when I enable darkmode.
But I have to investigate further, before I’m going to nag Christian about it.
From the docs I cannot see anything which refers to darkmode.
https://www.monkeybreadsoftware.net/class-customnstoolbarmbs.shtml
[quote=410017:@Gabriele Marchionni]I use NSToolbarMBS.
How I can change colors of toolbars like macOS Mojave?
How I can change the window title colors?[/quote]
For the Windows Title Color to change between Dark and Light theme, you will need to turn off any Custom Color Background. The app background would automatically switch between the theme.
I do use the NSToolbarMBS, the text caption changes between the theme but for the icons, you can either provide two icons, one for each theme or just set the isTemplate = true .
For the toolbar, I use a modified version of https://www.monkeybreadsoftware.net/example-maccontrols-toolbar-toolbarcustomized.shtml
In each button’s constructor method, I removed all the codes and left this as is
Super.Constructor( 0,0,52,MainToolbarNSButtonHeight+10 )
In the itemForItemIdentifier Event, I had each button code something like this
Dim BtPlay As New NSToolbarLoadFiles
Dim BtPlayItem As New NSToolbarItemMBS("loadfiles")
BtPlayItem.label="Load Files"
BtPlayItem.paletteLabel="Load Files"
BtPlayItem.view = BtPlay
BtPlayItem.Image=New NSImageMBS( dloadfiles )
BtPlayItem.Image.setSize( 20,20 )
BtPlayItem.Image.isTemplate=True
btplayitem.tooltip = "Load Files"
myItems.Append BtPlayItem
myItems.Append BtPlay
Return BtPlayItem
If you provide two sets of Images, one for the light and other for the dark theme, you could modified the lines to read
if mainWindow.isdark = true then
BtPlayItem.Image=New NSImageMBS( Darkloadfiles )
else
BtPlayItem.Image=New NSImageMBS(Lightloadfiles )
end if
The Dark Theme switch is not automatic for some of the controls, as in some text colors are not handled correctly. For that, I added two global field isset and isdark booleans.
In the Window Active event, I would check once for which theme is being used. I tried this in the Open event but it appears the theme wasn’t applied at which time and it only keeps coming up as Light theme.
The isset boolean is used to ensure that this is only checked once otherwise the app would just suffer a hard crash.
[code]If isset = False Then
Try
Dim ab As NSAppearanceMBS = NSAppearanceMBS.currentAppearance
If InStr(ab.name,"Dark") > 0 Then
isdark = True
Else
isdark = False
End If
Exception
isdark = False
End Try
End If [/code]
From there, I can just skin the necessary controls’ color to the light or dark color.
In the Info.plist, add the following to let the app know that you support the different themes
<key>NSRequiresAquaSystemAppearance</key>
<string>false</string>
Hope that helps
In my macOS Mojave I set the dark mode.
But when I check name of currentAppearance is ever “NSAppearanceNameAqua” and never “NSAppearanceNameDarkAqua”
Then in this code…
Dim ab As NSAppearanceMBS = NSAppearanceMBS.currentAppearance
If InStr(ab.name,"Dark") > 0 Then
isdark = True
Else
isdark = False
End If
…isDark is ever False.
This thing happens both in debug and in compiled.
P.S. I use Xojo 2018r2 Pro
[quote=410356:@Gabriele Marchionni]In my macOS Mojave I set the dark mode.
But when I check name of currentAppearance is ever “NSAppearanceNameAqua” and never “NSAppearanceNameDarkAqua”
Then in this code…
Dim ab As NSAppearanceMBS = NSAppearanceMBS.currentAppearance
If InStr(ab.name,"Dark") > 0 Then
isdark = True
Else
isdark = False
End If
…isDark is ever False.
This thing happens both in debug and in compiled.
P.S. I use Xojo 2018r2 Pro[/quote]
The key is to set the following key in the info.plist as I stated in my post or else it would always be aqua.
NSRequiresAquaSystemAppearance
false
Yes Edwin! I forgot the Info.plist file
Thanks!