Parents and children
 
 
 

You will see the terms’parent’ and ’child’ used in relation to UI elements and ELF commands. In this context a parent is simply a UI element that contains other UI elements, and a child is an element that is contained within a parent. A child of one parent may also be the parent of other children.

Windows are the top-most parent of the hierarchy. Other elements in the hierarchy can be layouts, controls, menus, menu items etc. The hierarchy can be arbitrarily deep as layouts can contain other layouts and menu items can contain sub-menus.

Default parents

To simplify creation of windows and reduce clutter in scripts ELF commands understand the idea of default parents. This means that it is not necessary to explicitly specify the parent for each element created. When a window is created it will become the default parent for any subsequent menus or controls. New UI elements will appear inside that window until the default parent is explicitly changed (with the setParent command) or another window is created.

There are different default parents for layouts and menus. A window is the initial default parent for controls and if the window is created with a menu bar then it is also the initial default parent for menus. When a layout is created it will become the new default parent for layouts and controls. When a menu bar layout is created it will become the new default parent for menus. When a menu is created it will become the default parent for menu items.

The default parent is changed either implicitly by creating a new parent or explicitly using the “setParent” command. To change the default parent for menus the “-m/menu” flag is used. Setting a parent to either a window or a menu bar layout will set the default parent for both menus and layouts. The following is a small code example that illustrates the use of default parents for layouts.

Script 1. Example of default parent layout

window ExampleWindow1;
 columnLayout;
 button -label "Button 1";
 button -label "Button 2";
 rowColumnLayout -numberOfColumns 2;
 text -label "Name:";
 textField;
 text -label "City:";
 textField;
 setParent ..;
 checkBox -label "Lights ";
 checkBox -label "Camera ";
 checkBox -label "Action ";
showWindow ExampleWindow1;

The “text” elements and the “textField” elements are children of the row column layout. They are arranged by the row column layout to be in two columns. If the “setParent .." command wasn’t used then the default parent would continue to be the row column layout and the check boxes would be laid out in two columns also. To demonstrate, the following example is identical to the previous except that the “setParent” command is commented out.

Script 2. Effect of setParent command on default parent layout

window ExampleWindow2;
 columnLayout;
 button -label "Button 1";
 button -label "Button 2";
 rowColumnLayout -numberOfColumns 2;
 text -label "Name:";
 textField;
 text -label "City:";
 textField;
 //setParent ..;
 checkBox -label "Lights ";
 checkBox -label "Camera ";
 checkBox -label "Action ";
showWindow ExampleWindow2;

The “setParent” command accepts “-up” and “-top” as flags to move up the hierarchy one level or to the top of the hierarchy respectively similar You can also explicitly specify a new default parent; for example, “setParent <windowOrLayoutName>;”. The “setParent” command can also be queried for the current parent; for example, “setParent -query”.

The following is a brief example that illustrates the use of default parents for menus.

Script 3. Sample default parent menu

window -menuBar true ExampleWindow3;
 menu -label "File" TestFileMenu;
 menuItem -label "Open" menuItem1;
 menuItem -label "Close" menuItem2;
 menuItem -label "Quit" menuItem3;
 menu -label "Edit" TestEditMenu;
 menuItem -label "Cut" menuItem1;
 menuItem -label "Copy" menuItem2;
 menuItem -label "Paste" menuItem3;
 menu -label "Options" TestOptionsMenu;
 menuItem -label "Color" -subMenu true menuItem1;
 menuItem -label "Red";
 menuItem -label "Green";
 menuItem -label "Blue";
 setParent -menu ..;
 menuItem -label "Size" -subMenu true menuItem2;
 menuItem -label "Small";
 menuItem -label "Medium";
 menuItem -label "Large";
 setParent -menu ..;
showWindow ExampleWindow3;

All commands that create UI elements also accept the “-p/parent parentName” flag for explicit specification of that element’s parent. This flag will always take precedence over the default parent.

Collections are treated differently. They use the current layout as a default parent and they also accept the “-p/parent” flag to be explicitly parented. However, collections also have the ability to span windows and have a “-g/global” flag to select this behavior. When the “-g/global” flag is used the collection will have no parent. Collections are parented only to facilitate their deletion. When the parent is deleted the collection will also be deleted. Global collections must be explicitly deleted.