23template <
class TModule,
class TModuleW
idget>
34 assert(m->
model ==
this);
35 tm =
dynamic_cast<TModule*
>(m);
51template <
class TW
idget>
53 TWidget* o =
new TWidget;
60template <
class TW
idget>
62 TWidget* o = createWidget<TWidget>(pos);
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>
99 TParamWidget* o = createParam<TParamWidget>(pos, module, paramId);
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>
118 TPortWidget* o = createInput<TPortWidget>(pos, module, inputId);
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>
137 TPortWidget* o = createOutput<TPortWidget>(pos, module, outputId);
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>
155 TModuleLightWidget* o = createLight<TModuleLightWidget>(pos, module, firstLightId);
156 o->box.pos = o->box.pos.minus(o->box.size.div(2));
164template <
class TParamW
idget>
166 TParamWidget* o = createParam<TParamWidget>(pos, module, paramId);
167 o->getLight()->module = module;
168 o->
getLight()->firstLightId = firstLightId;
173template <
class TParamW
idget>
175 TParamWidget* o = createLightParam<TParamWidget>(pos, module, paramId, firstLightId);
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;
233 Item* item = createMenuItem<Item>(text, rightText);
234 item->action = action;
235 item->disabled = disabled;
236 item->alwaysConsume = alwaysConsume;
253template <
class TMenuItem = ui::MenuItem>
254ui::MenuItem*
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 +=
" ";
277 Item* item = createMenuItem<Item>(text);
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>
300ui::MenuItem*
createBoolMenuItem(std::string text, std::string rightText, std::function<
bool()> getter, std::function<
void(
bool state)> setter,
bool disabled =
false,
bool alwaysConsume =
false) {
301 struct Item : TMenuItem {
302 std::string rightTextPrefix;
303 std::function<bool()> getter;
304 std::function<void(
size_t)> setter;
307 void step()
override {
308 this->rightText = rightTextPrefix;
310 if (!rightTextPrefix.empty())
311 this->rightText +=
" ";
323 Item* item = createMenuItem<Item>(text);
324 item->rightTextPrefix = rightText;
325 item->getter = getter;
326 item->setter = setter;
327 item->disabled = disabled;
328 item->alwaysConsume = alwaysConsume;
342 return ptr ? *ptr :
false;
362template <
class TMenuItem = ui::MenuItem>
364 struct Item : TMenuItem {
367 ui::Menu* createChildMenu()
override {
374 Item* item = createMenuItem<Item>(text, rightText + (rightText.empty() ?
"" :
" ") +
RIGHT_ARROW);
376 item->disabled = disabled;
394template <
class TMenuItem = ui::MenuItem>
395ui::MenuItem*
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) {
397 std::function<size_t()> getter;
398 std::function<void(
size_t)> setter;
402 void step()
override {
403 size_t currIndex = getter();
404 this->rightText =
CHECKMARK(currIndex == index);
414 struct Item : TMenuItem {
415 std::function<size_t()> getter;
416 std::function<void(
size_t)> setter;
417 std::vector<std::string> labels;
420 void step()
override {
421 size_t currIndex = getter();
422 std::string label = (currIndex < labels.size()) ? labels[currIndex] :
"";
426 ui::Menu* createChildMenu()
override {
428 for (
size_t i = 0; i < labels.size(); i++) {
429 IndexItem* item = createMenuItem<IndexItem>(labels[i]);
430 item->getter = getter;
431 item->setter = setter;
433 item->alwaysConsume = alwaysConsume;
440 Item* item = createMenuItem<Item>(text);
441 item->getter = getter;
442 item->setter = setter;
443 item->labels = labels;
444 item->disabled = disabled;
445 item->alwaysConsume = alwaysConsume;
462 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
ui::MenuItem * 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 * 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
TParamWidget * createLightParamCentered(math::Vec pos, engine::Module *module, int paramId, int firstLightId)
Definition helpers.hpp:174
ui::MenuItem * 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:395
ui::MenuItem * createBoolPtrMenuItem(std::string text, std::string rightText, T *ptr)
Easy wrapper for createBoolMenuItem() to modify a bool pointer.
Definition helpers.hpp:339
TMenuItem * createMenuItem(std::string text, std::string rightText="")
Definition helpers.hpp:203
ui::MenuItem * 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:459
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
ui::MenuItem * 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:363
TPortWidget * createInputCentered(math::Vec pos, engine::Module *module, int inputId)
Definition helpers.hpp:117
DSP processor instance for your module.
Definition Module.hpp:29
Light & getLight(int index)
Definition Module.hpp:290
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
#define CHECKMARK(_cond)
Definition common.hpp:10