Moving Toolbar Items
Posted May 18th, 2007 @ 08:19am by Erik J. Barzeski
In using an NSToolbar, we have a few items that move when the option key is held down because the name of the item changes. For example, one toolbar item changes from "Do It" to "Do It All" ((Not really - I'm being vague on purpose.)) when the option key is held down.
Currently, we're using a bit of a hack to keep the icons from moving too much - we're padding the shorter "Do It" version with spaces. This works sometimes. Other times, the spacing (because toolbars don't use a monospaced font) isn't quite right, so the icons move around just a little.
How can this be resolved? The text (unlike perhaps the example text above) goes beyond the 32 x 32 pixel size of the icon itself. Should we create an entirely new NSView for the icon or can we simply change a setting on the NSToolbarItem itself?
Posted 19 May 2007 at 10:51pm #
Don't know anything about NSToolbars or ObjC, but just want to point out that (most) fonts are designed with a variety of space glyphs e.g. figure space, em space, en space, third, quarter, sixth, hair space... which all have varying widths, so it may be possible to hack it to a pretty decent extent.
Posted 21 May 2007 at 2:37pm #
Maybe you could try calling -setMinSize: on the NSToolbarItem to keep it from getting smaller than a particular size? (perhaps calculating the size by measuring the width of the two strings in the appropriate font and passing the larger result to -setMinSize:)
Note: I don't have much experience with NSToolbarItem, so I don't know how well the sizing system works. I don't know whether it works with standard NSToolbarItems, or whether it's only there for custom views.