Subscribe to
Posts
Comments
NSLog(); Header Image

Moving Toolbar Items

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"1 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?

Footnotes

  1. Not really - I'm being vague on purpose.

2 Responses to "Moving Toolbar Items"

  1. 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.

  2. 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.


Trackback URI | Comments RSS

Leave a Reply

Please abide by the comment policy. Valid HTML includes: <blockquote><p>, <em>, <strong>, <ul>, <ol>, and <a href>. Please use the "Quote Me" functionality to quote comments.