How to 'align' and 'center' the PopUpMenu dropdown arrow?

I am working on some GUI configurations and need to center this ‘dropdown’ arrow. When the PopUpMenu is smaller, it defaults to the left. Is there any way to center this arrow?

Here is my code:

~t1_a_menu_array_arg_a = PopUpMenu(w, Rect(347.5, 11, 15, 10)).items_([“Arg”, “Dur”, “Atk”, “Rel”, “Rate”, “Pos”, “Buf”]).font_(Font([
“Helvetica-Bold”,
].choose, 12));
~t1_a_menu_array_arg_a.background_(Color.clear(0.7));
~t1_a_menu_array_arg_a.stringColor_(Color.white);

2023-03-18_09-36-20

Thanks!

Try making a regular Button and then using it to show a Menu - something like:

~menu = Menu(MenuAction("a"), MenuAction("b"), MenuAction("c")):
~button = Button().states_([["x"]]).front;
~button.action = { ~menu.front }.

You can trigger a Menu via basically any View, so you can even use UserView to just draw whatever you want.

Here’s a working example: ServerView.quark/ServerView.sc at master · scztt/ServerView.quark · GitHub

Awesome. This works well. Thanks for the knowledge!

Another quick example that fully reproduces the “modal” PopUpMenu behavior, where a single item can be selected:

(
~selectedItem = nil;

~menu = Menu(MenuAction("a"), MenuAction("b"), MenuAction("c"));
~menu.actions.do(_.checkable_(true));

~menu.addDependant({
	|menu, what, action|
	what.postln;
	what.switch(
		\aboutToShow, {
			~menu.actions.do({
				|m|
				m.checked = (m == ~selectedItem)
			})			
		},
		\triggered, {
			~selectedItem = action;
			menu.string = action.string;
			action.string.postln;
		}
	)
});

ToolBar(~menu).fixedWidth_(200@30).front;
)