Adding a menu item for a parameter

Hi, again :slight_smile:

I would like to know if there is already out of the box menu param widget. A sort of label, where user can do right click, show a list of selectable value, and select one by clicking left button (which show the new value on the label, and set the param’s value as well).

Somethings like this:

image

Even better if multiple sublevels are available, but not strictly necessary right now.

Is there already? Or I should make my own from scratch? I see there is MenuItem and stuff, but not sure if I create one separate and linked to a param.

Thanks, rackers!!!

I do not think there is any way to set a context menu to a parameter as right clicking on a parameter already opens up a menu for params where you enter values from the keyboard. Not sure if you could append options here. Best way to currently do so is with the panel context menu.

It would be a nice feature though.

That could be overridden, since I don’t need that funciton at all with a proper Menu Item.

Everyone will expect that functionality. I’ve not seen anyone override it so not sure if it can. I think it is TextField anyway.

You have do this on your own. The context menu of a parameter is implemented in ParamWidget::createContextMenu, but you can’t influence anything there. You need to override ParamWidget::onButton and do your own stuff. Changing an existing parameter from there is no problem.

Done it:

void onButton(const event::Button &e) override {
	if (e.action == GLFW_PRESS && e.button == GLFW_MOUSE_BUTTON_LEFT) {
		ui::Menu* menu = createMenu();

		ui::MenuLabel* modelLabel = new ui::MenuLabel;
		modelLabel->text = "Filter Type";
		menu->addChild(modelLabel);

		Item *itemTest;
		itemTest = new Item;
		itemTest->paramQuantity = this->paramQuantity;
		itemTest->text = "Off";
		itemTest->mItemValue = 0.0;
		menu->addChild(itemTest);

		itemTest = new Item;
		itemTest->paramQuantity = this->paramQuantity;
		itemTest->text = "LP";
		itemTest->mItemValue = 1.0;
		menu->addChild(itemTest);

		itemTest = new Item;
		itemTest->paramQuantity = this->paramQuantity;
		itemTest->text = "HP";
		itemTest->mItemValue = 2.0;
		menu->addChild(itemTest); 		                      
	}
}

Works perfect! Thanks

2 Likes

What module will this be for, so others will know what to look for.

Work in progress, with a friend :wink: You will be noticed \o

Thanks for your time!

1 Like

Please don’t hack the onButton handler. Doing so is not stable and may crash Rack in any future version.

The Rack v2 API includes

virtual void ParamWidget::appendContextMenu(ui::Menu* menu);

which you can override.

What do you mean with “don’t hack”? Can’t override it? I’ve added SVGKnob::onButton(e); before anything, is it ok so?

Because you’re not calling the superclass’s onButton, any feature that relies on ParamWidget’s button responding in the normal way will break. This is true when overriding any non-empty method.

Sorry, this was bad advice on my side then.

So you confirm: if I call SVGKnob::onButton(e) in the beginning of onButton is ok?

Not really because it’ll open two menus in your case.

Two menu? Uhm I don’t see the second, only the mine :open_mouth: Notice I’m opening it with left click, and right click over a widget should be disabled (thanks to super class method), preventing the main (Rack) menu to be opened…

I just make a parameter and set its value from the menu item handler. It’s simple.look at the source to any of my modular mixers.

There’s an example at the bottom of this file. https://github.com/squinkylabs/SquinkyVCV/blob/master/src/ctrl/SqMenuItem.h

1 Like

I see, thanks for your support!

But I want to open the context menu clickin on parameter (and set its value), rather than open the Rack menu and set a parameter from there.

So a click on param opening my custom menu is needed, in any case :slight_smile:

I’d hold off on this as you’ll be able to add the parameter options safely in v2.

1 Like