Einhugur macOS Bridge plugin. |

# EinhugurMacOSBridge.NSTouchBar Class (desktop)

Class to add Touch-Bar support to your application.

EinhugurCoreBridge.NSObject
NSTouchBar

class EinhugurMacOSBridge.NSTouchBar

#### Constructors

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

#### Properties

ClassName (Inherited) (desktop - console) | Returns the name of the Cocoa class under the hood as String.
Handle (Inherited) | Returns Integer handle to the native NSObject structure.

#### Methods

shared RegisterForApplication | Registers Touch-bar for at application level.
shared RegisterForWindow | Registers Touch-bar for at window level. (This variation of the method takes new style Xojo DesktopWindow)
shared RegisterForWindow | Registers Touch-bar for at window level. (This variation of the method takes old style Xojo Window)
Release (Inherited) | Releases the NSObject.
Retain (Inherited) | Retains the NSObject
SetCustomizationAllowedItemIdentifiers | Sets a list of identifiers for items to show in the Touch Bar’s customization UI.
SetCustomizationIdentifier | Sets a globally unique string that makes the Touch Bar eligible for user customization.
SetCustomizationRequiredItemIdentifiers | Sets 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.
SetDefaultItemIdentifiers | Sets 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.
SetEscapeKeyReplacementItemIdentifier | Sets the identifier of an item that replaces the system-provided button in the Touch Bar.
SetPrincipalItemIdentifier | Sets The identifier of an item you want the system to center in the Touch Bar.
SetTemplateItems | Sets up Touch Bar item pool for the touch-bar.
shared ToggleTouchBarCustomizationPalette | Use this method to show or hide the interface for customizing the Touch Bar.

#### Delegates

MakeItemForIdentifierDelegate | 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 | 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" |
Version = 5.0 (Inherited) |

#### 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 Intel 64 bit
- macOS Apple Silicon

#### Unsupported Platforms:

- Windows 32 bit
- Windows 64 bit
- Windows ARM 64 bit
- Linux 32 bit
- Linux 64 bit
- Linux ARM 32 bit
- Linux ARM 64 bit