Can I focus NSToolbarItem on a toolbar?

That is exactly so. I want to center two buttons. My toolbar looks like this: [B] - button):

[B] <---- flexible space ---> [B] [B] <---- flexible space ---> [SearchBar]

But the search bar is larger than the button on the left, so the middle buttons are not centered. I tried adding a custom width view, but this is due to localization. Is there any way to focus them?

+4
source share
3 answers

Centering things or, indeed, controlling layout outside the button order, although using toolbars is possible, is not necessarily a good idea.

Edit: I was informed that Mail.app really uses Voodoo to do something completely similar to what you offer.

They do this by tracking toolbar items and resizing the first flexible space on the toolbar to align the toolbar.

This may work for certain use cases, but is likely to be fragile; use them with caution, and keep in mind that if users can customize the toolbar, they can remove flexible space by removing centering.

+2
source

A very belated answer, but since I also needed to do this, I just wrote a subclass that will create space to center the next toolbar item:

http://github.com/timothyarmes/TAAdaptiveSpaceItem

+10
source

Instead of this complex approach, I would let him focus it by adding extra space elements on each side until these two buttons are in the middle of the window. The toolbar should be modified accordingly.

0
source

All Articles