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);
Thanks!
scztt
March 18, 2023, 1:52pm
#2
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!
scztt
March 18, 2023, 2:46pm
#4
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;
)