23template <
class TModule,
class TModuleW
idget>
34 assert(m->
model ==
this);
35 tm =
dynamic_cast<TModule*
>(m);
38 assert(mw->module == m);
51template <
class TW
idget>
53 TWidget* o =
new TWidget;
60template <
class TW
idget>
63 o->box.pos = o->box.pos.minus(o->box.size.div(2));
69template <
class TPanel = app::SvgPanel>
71 TPanel* panel =
new TPanel;
78template <
class TPanel = app::ThemedSvgPanel>
79TPanel*
createPanel(std::string lightSvgPath, std::string darkSvgPath) {
80 TPanel* panel =
new TPanel;
86template <
class TParamW
idget>
88 TParamWidget* o =
new TParamWidget;
90 o->app::ParamWidget::module =
module;
91 o->app::ParamWidget::paramId = paramId;
92 o->initParamQuantity();
97template <
class TParamW
idget>
100 o->box.pos = o->box.pos.minus(o->box.size.div(2));
105template <
class TPortW
idget>
107 TPortWidget* o =
new TPortWidget;
109 o->app::PortWidget::module =
module;
111 o->app::PortWidget::portId = inputId;
116template <
class TPortW
idget>
119 o->box.pos = o->box.pos.minus(o->box.size.div(2));
124template <
class TPortW
idget>
126 TPortWidget* o =
new TPortWidget;
128 o->app::PortWidget::module =
module;
130 o->app::PortWidget::portId = outputId;
135template <
class TPortW
idget>
138 o->box.pos = o->box.pos.minus(o->box.size.div(2));
143template <
class TModuleLightW
idget>
145 TModuleLightWidget* o =
new TModuleLightWidget;
147 o->app::ModuleLightWidget::module =
module;
148 o->app::ModuleLightWidget::firstLightId = firstLightId;
153template <
class TModuleLightW
idget>
156 o->box.pos = o->box.pos.minus(o->box.size.div(2));
164template <
class TParamW
idget>
167 o->getLight()->module =
module;
168 o->getLight()->firstLightId = firstLightId;
173template <
class TParamW
idget>
176 o->box.pos = o->box.pos.minus(o->box.size.div(2));
181template <
class TMenu = ui::Menu>
183 TMenu* menu =
new TMenu;
184 menu->box.pos =
APP->scene->mousePos;
189 APP->scene->addChild(menuOverlay);
194template <
class TMenuLabel = ui::MenuLabel>
196 TMenuLabel* label =
new TMenuLabel;
202template <
class TMenuItem = ui::MenuItem>
204 TMenuItem* item =
new TMenuItem;
206 item->rightText = rightText;
220template <
class TMenuItem = ui::MenuItem>
221TMenuItem*
createMenuItem(std::string text, std::string rightText, std::function<
void()> action,
bool disabled =
false,
bool alwaysConsume =
false) {
222 struct Item : TMenuItem {
223 std::function<void()> action;
234 item->action = action;
235 item->disabled = disabled;
236 item->alwaysConsume = alwaysConsume;
253template <
class TMenuItem = ui::MenuItem>
254TMenuItem*
createCheckMenuItem(std::string text, std::string rightText, std::function<
bool()> checked, std::function<
void()> action,
bool disabled =
false,
bool alwaysConsume =
false) {
255 struct Item : TMenuItem {
256 std::string rightTextPrefix;
257 std::function<bool()> checked;
258 std::function<void()> action;
261 void step()
override {
262 this->rightText = rightTextPrefix;
264 if (!rightTextPrefix.empty())
265 this->rightText +=
" ";
278 item->rightTextPrefix = rightText;
279 item->checked = checked;
280 item->action = action;
281 item->disabled = disabled;
282 item->alwaysConsume = alwaysConsume;
299template <
class TMenuItem = ui::MenuItem>
300TMenuItem*
createBoolMenuItem(std::string text, std::string rightText, std::function<
bool()> getter, std::function<
void(
bool state)> setter,
bool disabled =
false,
bool alwaysConsume =
false) {
303 }, disabled, alwaysConsume);
316 return ptr ? *ptr :
false;
336template <
class TMenuItem = ui::MenuItem>
338 struct Item : TMenuItem {
341 ui::Menu* createChildMenu()
override {
350 item->disabled = disabled;
368template <
class TMenuItem = ui::MenuItem>
369TMenuItem*
createIndexSubmenuItem(std::string text, std::vector<std::string> labels, std::function<
size_t()> getter, std::function<
void(
size_t val)> setter,
bool disabled =
false,
bool alwaysConsume =
false) {
370 struct Item : TMenuItem {
371 std::function<size_t()> getter;
372 std::function<void(
size_t)> setter;
373 std::vector<std::string> labels;
376 void step()
override {
377 size_t currIndex = getter();
378 std::string label = (currIndex < labels.size()) ? labels[currIndex] :
"";
382 ui::Menu* createChildMenu()
override {
384 for (
size_t i = 0; i < labels.size(); i++) {
386 return getter() == i;
389 },
false, alwaysConsume));
396 item->getter = getter;
397 item->setter = setter;
398 item->labels = labels;
399 item->disabled = disabled;
400 item->alwaysConsume = alwaysConsume;
417 return ptr ? *ptr : 0;
#define APP
Accesses the global Context pointer.
Definition context.hpp:71
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
TMenu * createMenu()
Definition helpers.hpp:182
TParamWidget * createParam(math::Vec pos, engine::Module *module, int paramId)
Definition helpers.hpp:87
TMenuLabel * createMenuLabel(std::string text)
Definition helpers.hpp:195
TPortWidget * createOutputCentered(math::Vec pos, engine::Module *module, int outputId)
Definition helpers.hpp:136
TWidget * createWidget(math::Vec pos)
Creates a Widget subclass with its top-left at a position.
Definition helpers.hpp:52
TModuleLightWidget * createLight(math::Vec pos, engine::Module *module, int firstLightId)
Definition helpers.hpp:144
TMenuItem * createCheckMenuItem(std::string text, std::string rightText, std::function< bool()> checked, std::function< void()> action, bool disabled=false, bool alwaysConsume=false)
Creates a MenuItem with a check mark set by a lambda function.
Definition helpers.hpp:254
TParamWidget * createLightParamCentered(math::Vec pos, engine::Module *module, int paramId, int firstLightId)
Definition helpers.hpp:174
TMenuItem * createSubmenuItem(std::string text, std::string rightText, std::function< void(ui::Menu *menu)> createMenu, bool disabled=false)
Creates a MenuItem that opens a submenu.
Definition helpers.hpp:337
ui::MenuItem * createBoolPtrMenuItem(std::string text, std::string rightText, T *ptr)
Easy wrapper for createBoolMenuItem() to modify a bool pointer.
Definition helpers.hpp:313
TMenuItem * createMenuItem(std::string text, std::string rightText="")
Definition helpers.hpp:203
TMenuItem * createBoolMenuItem(std::string text, std::string rightText, std::function< bool()> getter, std::function< void(bool state)> setter, bool disabled=false, bool alwaysConsume=false)
Creates a MenuItem that controls a boolean value with a check mark.
Definition helpers.hpp:300
TWidget * createWidgetCentered(math::Vec pos)
Creates a Widget subclass with its center at a position.
Definition helpers.hpp:61
TPortWidget * createOutput(math::Vec pos, engine::Module *module, int outputId)
Definition helpers.hpp:125
ui::MenuItem * createIndexPtrSubmenuItem(std::string text, std::vector< std::string > labels, T *ptr)
Easy wrapper for createIndexSubmenuItem() that controls an integer index at a pointer address.
Definition helpers.hpp:414
plugin::Model * createModel(std::string slug)
Returns a Model that constructs a Module and ModuleWidget subclass.
Definition helpers.hpp:24
TParamWidget * createLightParam(math::Vec pos, engine::Module *module, int paramId, int firstLightId)
Creates a param with a light and calls setFirstLightId() on it.
Definition helpers.hpp:165
TParamWidget * createParamCentered(math::Vec pos, engine::Module *module, int paramId)
Definition helpers.hpp:98
TPanel * createPanel(std::string svgPath)
Creates an SvgPanel and loads the SVG from the given path.
Definition helpers.hpp:70
TModuleLightWidget * createLightCentered(math::Vec pos, engine::Module *module, int firstLightId)
Definition helpers.hpp:154
TPortWidget * createInput(math::Vec pos, engine::Module *module, int inputId)
Definition helpers.hpp:106
TMenuItem * createIndexSubmenuItem(std::string text, std::vector< std::string > labels, std::function< size_t()> getter, std::function< void(size_t val)> setter, bool disabled=false, bool alwaysConsume=false)
Creates a MenuItem that when hovered, opens a submenu with several MenuItems indexed by an integer.
Definition helpers.hpp:369
TPortWidget * createInputCentered(math::Vec pos, engine::Module *module, int inputId)
Definition helpers.hpp:117
DSP processor instance for your module.
Definition Module.hpp:29
plugin::Model * model
Not owned.
Definition Module.hpp:34
@ OUTPUT
Definition Port.hpp:39
@ INPUT
Definition Port.hpp:38
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
Type information for a module.
Definition Model.hpp:34
std::string slug
Must be unique.
Definition Model.hpp:40
static std::shared_ptr< Svg > load(const std::string &filename)
Loads Svg from a cache.
#define CHECKMARK_STRING
Useful for menu items with a "true" boolean state.
Definition common.hpp:9
#define RIGHT_ARROW
Useful for menu items that open a sub-menu.
Definition common.hpp:13