Skip to content

Instantly share code, notes, and snippets.

@scztt
Last active November 17, 2016 16:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scztt/c4255e2ccc3fea0214b1d00089bc71ef to your computer and use it in GitHub Desktop.
Save scztt/c4255e2ccc3fea0214b1d00089bc71ef to your computer and use it in GitHub Desktop.
(
~menu = Menu(
Action("A", { "a selected".postln }),
Action("B", { "b selected".postln }),
Action("C", { "c selected".postln }),
);
~menu.front; // can be re-invoked after menu is closed
)
(~image = Image(64, 64).draw({
Pen.fillColor = Color.blue;
Pen.fillOval(Rect(0, 0, 64, 64));
});
~menu = Menu(
Action("checked", { "checked".postln })
.checked_(true),
Action("disabled", { "disabled".postln })
.enabled_(false),
Action("keyboard short", { "keyboard short".postln })
.shortcut_("Ctrl+Shift+N"),
Action("icon", { "icon".postln })
.icon_(~image),
Action("font", { "font".postln })
.font_(Font("Helvetica", 20, italic:true)),
Action.separator.string_("other stuff"),
// These will not work if menu is re-invoked....
CustomViewAction(Slider().orientation_(\horizontal)),
// submenu
Menu(
"string.toAction", // Strings can be converted to actions
{ "function.toAction".postln } // Functions can also be converted to actions
).title_("submenu")
).front;
)
(
~toolbar = ToolBar(
Action("one").icon_(~image),
Action("two").icon_(~image),
Action.separator,
CustomViewAction(Slider().orientation_(\vertical)),
Action("three").icon_(~image),
).bounds_(300@50).front;
)
(
MainMenu.register(
Action("Play a sound", {
{ SinOsc.ar(440, 0, Env.perc.kr(doneAction:2)) }.play
}),
"The Sounds Menu", // menu name
"My Sounds" // group w/in menu
);
MainMenu.register(
Action("Play sound with a shortcut", {
{ Saw.ar(440, Env.perc.kr(doneAction:2)) }.play;
}).shortcut_("Ctrl+P"),
"The Sounds Menu", // menu name
"Other Sounds" // group w/in menu
);
)
(
// Common System menus are shown before custom menus
MainMenu.register(
Action("Run SCD", {
Dialog.getPaths({ |paths| paths.do(_.load) });
}).shortcut_("Ctrl+O"),
"File", // menu name
);
MainMenu.register(
Action("Copy", { "copied".postln }).shortcut_("Ctrl+C"),
"Edit", // menu name
);
MainMenu.register(
Action("Paste", { "pasted".postln }).shortcut_("Ctrl+P"),
"Edit", // menu name
);
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment