Einhugur macOS Bridge plugin. |
|
EinhugurMacOSBridge.NSTouchBar Class
Class to add Touch-Bar support to your application.
NSObject
NSTouchBar
class EinhugurMacOSBridge.NSTouchBar
Constructors
NSTouchBar | Constructs NSTouchBar, taking in optional delegate to construct Touch-Bar items. |
Properties
Handle (Inherited) | Returns Integer handle to the native NSObject structure. |
Methods
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 bitMacOS X Cocoa 64 bitUnsupported Platforms:
MacOS X CarbonWindows 32 bitWindows 64 bitLinux 32 bitLinux 64 bitLinux ARM