SubMenu Columns Vs Root Menu Columns

Hello,
I am curious if anybody has had success of retaining the sub menu’s original .minimumColumns() function while adding it to a parent menu as a sub menu.

How would one, create a parent menu of 1 column, one sub menu of 2 columns, and another sub menu with 5 columns?

I am at loss, anything would help!

Currently I am adding menu’s to a combo box’s root menu. To make the problem a little more tricky.

I implemented these changes, it worked a bit.
https://github.com/WeAreROLI/JUCE/commit/64be913fa24066d88b6e3fcb2828b341b05722a0

I was able to get it to work, within the PopUpMenu.cpp

There was this function, it seemed pretty cool to have the columns be determined by the number of items so I wrote this!

void layoutMenuItems (const int maxMenuW, const int maxMenuH, int& width, int& height)
{

    numColumns = options.getMinimumNumColumns();
	
	if (items.size() > 12) {
		numColumns = 2;
	}
	if (items.size() > 24) {
		numColumns = 3;
	}
	if (items.size() > 36) {
		numColumns = 4;
	}
	if (items.size() > 48) {
		numColumns = 5;
	}
	if (items.size() > 60) {
		numColumns = 6;
	}
	if (items.size() > 72) {
		numColumns = 7;
	}
	if (items.size() > 84) {
		numColumns = 8;
	}
	if (items.size() > 96) {
		numColumns = 9;
	}
	if (items.size() > 108) {
		numColumns = 10;
	}
    contentHeight = 0;

    auto maximumNumColumns = options.getMaximumNumColumns() > 0 ? options.getMaximumNumColumns() : 7;

Instead of that big if statement couldn’t you just do something like…

numColumns = jlimit (options.getMinimumNumColumns(),
                     maximumNumColumns, 
                     items.size() / 12 + 1);
1 Like

Thanks @anthony-nicholls!
I thought of dividing but, didn’t think of adding one!
:joy::joy::joy:
That looks great,

===* Update Suggestion for JUCE *===
numColumns = jlimit (options.getMinimumNumColumns(),
maximumNumColumns,
items.size() / 12 + 1);
}

One more feature I think would add to this functionality, is creating a
.endColumn() as a sibling to .addSeperator() for the PopUpMenu class. I think this would work nicely with Options and MenuIter!

Lastly, since I tagged an admin…
I should make one more suggestion on the topic of the Popup Menu. A feature I haven’t looked into how to build, but would also be pretty cool.

A .getSubMenu(“SubMenu”), Allowing for manipulation of a sub menu’s options. Like the combo box’s get root menu.

Regards,
Skyler