Toolbar

Window toolbar.

Modulerequire("gui")
TypeClass
PlatformsmacOS

This view is only implemented for macOS by wrapping NSToolbar. The API is still experimental and will be changed in future. Currently certain items are not aligned correctly in toolbar.

The toolbar items are not added manually like the normal views, instead you have to implement the get_item delegate which creates items on request, and then call SetDefaultItemIdentifiers to specify the default items to show.

const toolbar = gui.Toolbar.create('my-toolbar')
toolbar.getItem = (toolbar, identifier) => {
  switch (identifier) {
    case 'entry':
      const entry = gui.Entry.create()
      const minSize = entry.getMinimumSize()
      minSize.width = 200
      const maxSize = { width: 2 << 30 - 1, height: minSize.height }
      return { label: 'Address', view: entry, minSize, maxSize }
    case 'button':
      const button = gui.Button.create('GO')
      button.setImage(gui.Image.createFromPath('go.png'))
      return {
        label: 'GO',
        minSize: {width: 30, height: 35},
        view: button
      }
  }
}
toolbar.setDefaultItemIdentifiers(['entry', 'button'])
toolbar.setDisplayMode('icon')
window.setToolbar(toolbar)

Class methods

create(identifier)

Create a new Toolbar view with identifier.

Within the application all toolbars with the same identifier are synchronized to maintain the same state, including for example, the display mode and item order. The identifier is used as the autosave name for toolbars that save their configuration.

Parameters

Return

Toolbar

Methods

setDefaultItemIdentifiers(identifiers)

Set the identifiers of default items that would show in toolbar.

Parameters

setAllowedItemIdentifiers(identifiers)

Set the identifiers of the items that are allowed to show in toolbar.

Parameters

setAllowCustomization(allow)

Set whether users are allowed to customize the toolbar.

Parameters

setDisplayMode(mode)

Set the display mode of the toolbar items.

Parameters

setVisible(visible)

Set whether toolbar is visible.

Parameters

isVisible()

Return whether toolbar is visible.

Return

Boolean

getIdentifier()

Return the identifier of the toolbar.

Return

String

Delegates

getItem(toolbar, identifier)

Called lazily when the toolbar is going to get the item with identifier.

You should not cache the item to be returned.

Parameters

Return

Toolbar::Item