Restrict popup menu height


#1

Hi !

I am working on an interface containing combo boxes with a lot of items in it. When one of the combo box's popup menu is deployed, it takes most of the time a huge part of the screen. What I would like to do is to restrict the number of items displayed by the popup menu and enable the scrolling.

There’s apparently no way to do this using a custom lookandfeel or a custom combo box as the popup menu display is computed in an inline class called MenuWindow in juce_PopupMenu.cpp.

 


#2

Can you add a listbox as a custom item to your popup menu?

http://klangfreund.github.io/jucedoc/doc/classPopupMenu_1_1CustomComponent.html

 

 


#3

That would be a very clunky way to do it! Not recommended!


#4

Yeah, I don't think anyone's asked for control over that before. Not a bad request, I'll backlog it..


#5

..actually, just thinking about it, you can probably already do this.

If you override the ComboBox::showPopup method, you can tweak the options, and could use the Options::withTargetScreenArea to limit the space it can occupy.


#6

My bad ! Thanks ! :)


#7

Hello Jules,

 

I'm facing similar problem : I want to draw a PopupMenu within a delimited space, but withTargetScreenArea don't seems to work for me.

Here's what I'm doing : 

I have a button in Hello world and on click I do :

Rectangle <int> rect (button->getX(),button->getY(),100,200);

        PopupMenu menu;

         for (int i = 1; i<50; i++)      {

            menu.addItem(i, String(i));

        }

                const int result = menu.showMenu (PopupMenu::Options()

                                          .withTargetScreenArea(localAreaToGlobal (rect))

                                          .withMaximumNumColumns (1)

                                          );

But the popup draws filing the whole height of my screen...

If I change the X & Y coordinate, it indeed move it's drawing point, but I can't have it constrained inside a specific height as I would like...

I'm still using Juce 3.1.1 Could it be that this has been fixed since then ?

 

Thanks,

 

Salvator


#8

Sorry, what I said was wrong - the target screen area is the area to position the menu around, not inside. There's currently nothing in there that would support limiting the overall size, but it could be added to the options, I guess.


#9

Thanks for the clarification.

+1 for the new option, or even just something like ".withMaximumNumRows(int maxNumRow)

Best,

Salvator