Hmm, what about “context”? Is that correct? It might automatically make it darker to emphasise the rectangle. What happens when you set the rectangle directly?
Remember that NSColor contains a lot of “magic” inside that knows how to render a given color in any appearance. CGColor however doesn’t… so avoid storing the CGColor extracted from an NSColor – e.g. if you assign it to a layer’s backgroundColor, it won’t automatically switch to a dark variant when needed, even if the original NSColor would.
but it isn’t that the color being display is “wrong”… it IS the RGB color from the named Color
the problem is any other window I display doesn’t seem to use that color
Look at view hierarchy, you’ll be able to see what Apple use for the window background.
Last I checked, it wasn’t a color. It was a NSVisualEffectView, but that was a couple of years ago, so who knows what they use now.
It’s also worth mentioning that some colors are not meant to be drawn, only applied to controls. You’ll have to experiment to figure out which and to what (again, exploding the view hierarchies help here).
I went through this whole NSColor nightmare while developing a Swift app with some custom views. It seems like the new way is to use a subclass of a NSVisualEffectView and set it’s material. That’s what I ended up doing.
As you can see most window and control colors are now deprecated and I couldn’t find another way to match the OS styles particularly in Monterey.
Could it be that the lighter color is the windowBackgroundColor of an unselected window, and the darker one the color of a selected one?
I’m still on Mojave so can’t check the values on newer ones, but checking the colours of the top and sidebar on a finder window I get for an unselected window F6F6F6 (steady value) and for a selected one something around E1E1E3 (value vary depending on where I measure, but pretty close to your value).
So if you unselect your app and measure the box colour with the included Digital Color Meter app - what do you get?
Btw the Digital Color Meter app has ECECEC as window background colour whether it is selected or unselected.
The reason why the background is an NSVisualEffectView is because the Window Tinting of macOS Big Sur, that changes the background according to wallpaper predominant color:
The windowBackground is a real window’s background color, you just compare it not with real window background, but with theme view below hosting controller view
Here is a hierarchy (you can verify it yourself in view debug mode)
Is that not what I said two days ago?
Which could have been validated by simply exploring the view hierarchy.
Yeah, a lot of the colors and even color effects are NOT what Apple actually uses, those days ended long ago, Apple PJ does whatever it feels like, without giving a damn about 3rd Party Developers.
I think so - but don’t look at me … I have no clue
I’m not a top notch programmer, just pretty good at finding information …
I didn’t know about the colours etc, and certainly not about the view debugger … just trying to find an answer for a question that intrigued me (while my wife said I SHOULD mow the lawn instead) … which is now done too
Me neither mate, am not even good at finding information some times… I tend to end up reading a lot more .h files now than ever and even in those cases, they’re often incomplete or don’t explain what this key, method, property does. What’s even worse if having to read “private” API to figure out the values from a public function… I guess I should be grateful that Apple even makes private API .h files available for security researchers (not regular developers).
AFAIK, swift doesn’t use .h files, so I guess that’ll be going away one day too.
The colors have not been quite right for some time now, I had to probe the view hierarchy quite a bit when I wanted App Wrapper to be more consistent with the OS and couldn’t find these things in the documentation. I went in further while I was putting together the App Kit, and Aqua Swatch really helps (it does more than just colors, it does materials, icons and system fonts).
Good job, I’ve yet to get to my chores today. I’ve been a bit relaxed as it’s been ~35˙c for the last few days.
Trouble is with a lot of documentation and especially 3rd Party documentation, is what works on one version, may not work on anything newer
This irritates me to no end, as someone who wants to build an app that at least looks like it was created with love and care.
What makes it works its that a lot of tutorial or information on the internet don’t even give you proper context what version of the SDK, etc.
I spent days with the same issue as @DaveS while working on some custom views for a splitter and button, gave up on fill, using material was the only solution that worked properly.