Einhugur macOS Bridge plugin.

EinhugurMacOSBridge.NSTouchBar Class

Class to add Touch-Bar support to your application.

NSObject
   NSTouchBar

class EinhugurMacOSBridge.NSTouchBar

Constructors

NSTouchBarConstructs NSTouchBar, taking in optional delegate to construct Touch-Bar items.

Properties

Handle (Inherited) Returns Integer handle to the native NSObject structure.

Methods

shared RegisterForApplicationRegisters Touch-bar for at application level.
shared RegisterForWindowRegisters Touch-bar for at window level.
Release (Inherited) Releases the NSObject.
Retain (Inherited) Retains the NSObject
SetCustomizationAllowedItemIdentifiersSets a list of identifiers for items to show in the Touch Bar’s customization UI.
SetCustomizationIdentifierSets a globally unique string that makes the Touch Bar eligible for user customization.
SetCustomizationRequiredItemIdentifiersSets an optional list of identifiers for items you want to always appear in the Touch Bar and which the user can’t remove during customization.
SetDefaultItemIdentifiersSets default item identifiers. You must always set this for every Touch Bar. The identifiers represent list of the identifiers that you wish to show, actual items with the given identifiers can then come from different sources.
SetEscapeKeyReplacementItemIdentifierSets the identifier of an item that replaces the system-provided button in the Touch Bar.
SetPrincipalItemIdentifierSets The identifier of an item you want the system to center in the Touch Bar.
SetTemplateItemsSets up Touch Bar item pool for the touch-bar.
shared ToggleTouchBarCustomizationPaletteUse this method to show or hide the interface for customizing the Touch Bar.

Delegates

MakeItemForIdentifierDelegate (console safe) Delegate to provide callback for creating touch-bar items. Use of this delegate is optional since you can also create the touch-bar items, inside your MakeTouchBar hook.
MakeTouchBarDelegate (console safe) A delegate used in RegisterForApplication and RegisterForWindow to provide callback hook for creating Touch-bar for given window or your application.

Constants

FixedSpaceLarge = "NSTouchBarItemIdentifierFixedSpaceLarge"
FixedSpaceSmall = "NSTouchBarItemIdentifierFixedSpaceSmall"
FlexibleSpace = "NSTouchBarItemIdentifierFlexibleSpace"
OtherItemsProxy = "NSTouchBarItemIdentifierOtherItemsProxy"

Normal sequence for setting up Touch-Bar at application level:

Property in your App class:
Private Property responder as EinhugurMacOSBridge.NSTouchBarResponder


In App.Open event:
Sub Open() Handles Open
    responder = EinhugurMacOSBridge.NSTouchBar.RegisterForApplication(addressof CreateTouchBar)
End Sub


In your App class a method to respond to the delegate to setup the Touch Bar:
Private Function CreateTouchBar() as EinhugurMacOSBridge.NSTouchBar
using EinhugurMacOSBridge

Dim bar as NSTouchBar = new NSTouchBar(addressof CreateTouchBarItems)

// Principal item is item that. Will attempt to be in the middle. (If wanting like 2 buttons together
// in the middle then we put group item around them and let the group item be the
// principal item.
bar.SetPrincipalItemIdentifier(“com.einhugur.testapp.middleButtons”)

bar.SetDefaultItemIdentifiers(array( _
    NSTouchBar.OtherItemsProxy, _
    "com.einhugur.testapp.middleButtons", _
    NSTouchBar.FixedSpaceLarge, _
    "com.einhugur.testapp.Label1”,  _
"com.einhugur.testapp.Button1”))

return bar
End Function


In the App class we also add method to respond to the item creation delegate:
Private Function CreateTouchBarItems(touchBar as EinhugurMacOSBridge.NSTouchBar, itemIdentifier as String) as EinhugurMacOSBridge.NSTouchBarItem
using EinhugurMacOSBridge

// Here we would check for all the identifiers that we registered and respond to them
// We will only show it for one of the items in this example.

Dim item as NSCustomTouchBarItem

if itemIdentifier = "com.einhugur.testapp.Button1" then item= new NSCustomTouchBarItem(itemIdentifier)

Dim button as NSButton = new NSButton("Some button", addressof Button1Click)

item.SetView(button)

return item
end if
End Function


And of course we also had to create the click handler for the button:
Private Sub Button1Click()
MsgBox "Button1 click"
End Sub


Now, if you have button that might change state, like get disabled from time to time, then it would be good idea to put the NSButton in property on the App class, then you can address the button later to enable and disable it.

Supported Platforms:

  • MacOS X Cocoa 32 bit
  • MacOS X Cocoa 64 bit

    Unsupported Platforms:

  • MacOS X Carbon
  • Windows 32 bit
  • Windows 64 bit
  • Linux 32 bit
  • Linux 64 bit
  • Linux ARM