Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSToolbarFlexibleSpaceItem is constraint to NSSplitViewItem in Swift

enter image description here

Almost all macOS official apps have this toolbar's feature which the NSToolbarItem flexible space is constraint to NSSplitViewItem view. I first thought maybe there are 3 different sections on NSToolbar. But it just ONE toolbar. You can open Notes app and customize the toolbar.

  • The first flexible space is detected and moved along with first split view item.
  • The second flexible space is detected and moved along with the second split item.
  • The rest will be just normal flexible spaces.
  • If there only two flexible spaces, the second will act as normal flexible space. The same thing applies to one and or flexible space.

I guess this is how Apple configure the flexible space items.

I found this JWToolbarAdaptiveSpaceItem but it's removable and it cannot be replaced with flexible space item like Note apps does.

There is another stackoverflow's question (I couldn't find it now) asked about this but the answer is adding fake views and buttons which is not NSToolbar.

Thus, does anyone know how to achieve this?

(Sorry about my English)

like image 866
João Oliveira Avatar asked Sep 21 '16 20:09

João Oliveira


1 Answers

As of macOS 11 Big Sur, this is handled by NSTrackingSeparatorToolbarItem, which interacts with the dividers of an NSSplitView. There is also a new navigational property on NSToolbarItem that can influence item locations.

I do not think there is a built-in way to do this on previous macOS versions.

like image 178
Kevin Grant Avatar answered Oct 13 '22 10:10

Kevin Grant