# Nested/Composite/Meta Controls

**URL:** <https://iplug2.discourse.group/t/nested-composite-meta-controls/101>\
**Category:** Uncategorized\
**Created:** [4 June 2020 03:44 UTC](https://iplug2.discourse.group/t/nested-composite-meta-controls/101 "2020-06-04T03:44:42Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![montag](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/montag/32/52_2.png) [@montag](https://iplug2.discourse.group/u/montag)\
**Post date:** [4 June 2020 03:44 UTC](https://iplug2.discourse.group/t/nested-composite-meta-controls/101/1 "2020-06-04T03:44:43Z")

</div>

I’m wondering how to “nest” controls into reusable components (or meta controls, I guess).

Is this the best example to follow?

> <https://github.com/iPlug2/iPlug2/blob/master/IGraphics/Controls/IVPresetManagerControl.h>

Any other helpful advice? (Asked in Slack but posting here for benefit of others.)

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [4 June 2020 10:18 UTC](https://iplug2.discourse.group/t/nested-composite-meta-controls/101/2 "2020-06-04T10:18:57Z")

</div>

Just bear in mind these IControls that nest other IControls are a bit niche (i personally haven’t used them much before) and are not the only way of grouping controls. Controls can be assigned a control group (see [IGraphics::AttachControl](https://iplug2.github.io/iPlug2/class_i_graphics.html#afbca10b1912ddc855b7fc9d9a24a5c91)). You can also have parameter groups, which might be useful.

---

<div class="post-metadata">

**Author:** ![montag](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/montag/32/52_2.png) [@montag](https://iplug2.discourse.group/u/montag)\
**Post date:** [12 June 2020 20:19 UTC](https://iplug2.discourse.group/t/nested-composite-meta-controls/101/3 "2020-06-12T20:19:39Z")

</div>

I would like to advocate some support for nesting controls in iPlug 2.

The one thing I have run into is that, while I can do `GetUI()->AttachControl(...)` in `OnAttached()` of some “parent” control, this doesn’t establish a parent-child relationship.

For example, if I call `Hide()` on the parent control, the controls attached as “children” don’t also get hidden.

This shows up in the bundled controls too; if you call `IVNumberBoxControl::Hide` it doesn’t get properly hidden. You must override `Hide()` to ensure that the “child” controls get hidden manually:

```auto
  void Hide(bool hide) override
  {
    mTextReadout->Hide(hide);
    mIncButton->Hide(hide);
    mDecButton->Hide(hide);
  }

```

So I would advocate a basic set of child management built into `IControl` interface. Like `AddChild`, `RemoveChild`, etc. Instead of `GetUI()->AttachControl()` it would be great to have `this->AddChild()`, which would manage UI and add the control to a `vector<IControl*> mChildren` or something like that.

Thoughts? 🙂

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [13 June 2020 14:41 UTC](https://iplug2.discourse.group/t/nested-composite-meta-controls/101/4 "2020-06-13T14:41:30Z")

</div>

It’s a nice thought, but the big question would be how does the mouse event propagation work? Do child controls also get added to the main IGraphics::mControls stack.

I’ve been investigating nested controls for a while (i have a branch where i am working on multi-touchable controls, including an MPE keyboard that is made up of individual controls fro each key), so I will try and look at it soon.

---

<div class="post-metadata">

**Author:** ![HoRNet](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/hornet/32/66_2.png) [@HoRNet](https://iplug2.discourse.group/u/HoRNet)\
**Post date:** [16 June 2020 13:04 UTC](https://iplug2.discourse.group/t/nested-composite-meta-controls/101/5 "2020-06-16T13:04:46Z")

</div>

I did that kind of relationship for the TotalEQ we released earlier this year.  
The controls that surround the frequency and gain control point are “children” of the control that draws the EQ response curve, actually to create what at the time i called the “proxy” control i had to explicitly pass every “OnMouse…” event from the “proxy” to the child control that was hit, thus evaluating if the mouse pointer was inside the chidren’s IRECT when the event fired. Also there are some little quirks with the mouse up event that may happen outside the chidren’s rect but the mouse down could have been originated inside the children’s area, so you must keep track of where the mouse down event started.

Saverio
