Mira
Mira

Reputation: 171

How can I limit the "pop-up" size of NSPopUpButton?

I have a large list - over 200 items - managed by an NSPopUpButton. When clicked, the list extends all the way to the top or bottom of the screen and beyond.

How can I limit the open size, so that at most 20 or so items are shown at once?

Upvotes: 2

Views: 1461

Answers (2)

Mira
Mira

Reputation: 171

The solution I found was the following:

I subclassed NSPopUpButton, and in my subclass defined confinementRectForMenu:onScreen: (part of the NSMenuDelegate protocol). This limits the space that the list takes up. Unfortunately, you can't just specify a size but must do the work to determine the position. You can take [self frame] origin, use [[self superview] convertPointToBase:], nudge it over a bit and do whatever other calculations, then do a final conversion with [[self window] convertBaseToScreen:].

Upvotes: 6

Rob Keniger
Rob Keniger

Reputation: 46020

200 items is too many for a pop-up menu. The Mac Human Interface Guidelines recommend that a pop-up menu should contain a maximum of 12 items.

You need to rethink your design. I suggest that instead of the pop-up menu, you create a single-column NSTableView with no header and let your users select an item from a scrollable list of options.

Upvotes: 4

Related Questions