PopUpTreeMenu:
Filter:
PopUpTreeMenu/Classes (extension) | GUI

PopUpTreeMenu
ExtensionExtension

hierarchical PopUp menu

Description

This class is modelled after PopUpMenu, but implements submenus.

Keyboard navigation (optional)

spaceopen
arrowsleft, right, up, down
[a-z,0-9]jump to item
returnselect
escapeclose

Known problems / todo

Menues that are close to the right-hand side of the screen and extend across the border will overlap.

Class Methods

.new

Create a new menu. To make it work one must set a -tree.

Instance Methods

.tree

Dictionary of dictionaries. Branches terminate if they have an empty dictionary as a value (= leaf).

Discussion:

The tree dictionary is unordered. By default branches and leaves on the same level will be sorted and displayed in alphabetic order. See -sortFunc.

Below is an example of a tree without branches - all leaves (keys) are on the same leve. This will be similar to a regular PopUpMenu.

Next an example of a nested structure. This will create a submenu.

Symbols, numbers and strings can be used as keys (compared to the old version which only accepted symbols).

NOTE: It is possible to create complex and deeply nested menu structures, but it is not a good idea. For ease of use rarely should one nest more than single level deep. Submenus of submenus are difficult to navigate.

.allowsReselection

Determines whether the action is triggered when selecting already selected item. Defaults to false.

Arguments:

A Boolean.

.currentLeaf

Array of keys pointing to current selection (leaves only). Empty if nothing selected. See -currentPath for reporting both branches and leaves.

.currentPath

Array of keys pointing to current selection. Empty if nothing selected.

.sortFunc

Set a custom Function to sort the tree dictionary in other ways than the default alphabetic order. Note that the -tree keys are converted and passed in to this function as symbols.

.hiliteColor

Get or set the selection color.

.value

Get or set the value.

Arguments:

path

Should be an array of keys.

Returns:

Array of keys pointing to the last selected node/leaf. nil if nothing selected.

.valueAction

Set the value and evaluate the action.

Arguments:

path

Should be an array of keys.

Actions

.action

Function that gets evaluated when some leaf is selected. Arguments passed in: this, value

.openAction

Function that gets evaluated when the popup menu is clicked. Arguments passed in: this, mouseX, mouseY

Discussion:

This can be used to automatically populate -tree and keep it in sync with files in a folder. See examples below.

.closeAction

Function that gets evaluated when the popup menu closes. Arguments passed in: this, mouseX, mouseY

Apperance

.bounds

Get or set the position and dimension of the menu as a Rect.

.font

Get or set the Font.

.hiliteColor

Get or set the selection color.

.icon

Get or set the String used as branch indicator. By default this is "▶"

.flashRate

Set the speed of the flashes for the select item animation. The default is 0.1

.numFlashes

Set the number of flashes for the select item animation. The default is 1

.margin

Get or set the size of the side margins. The default is 4

Examples