Go library to integrate the MacBook Touch Bar
go get github.com/LouisBrunner/go-touchbar
// Setup your window code (including NSApplication/NSWindow on macOS)
tb := touchbar.New(touchbar.Options{})
err := tb.Install(Configuration: touchbar.Configuration{
// Add your configuration here
})
if err != nil {
// handle
}
// run your application
// when you want to update the touchbar (even from another routine), call do
err = tb.Update(Configuration: touchbar.Configuration{
// Add your updated configuration here
})
if err != nil {
// handle
}
err = tb.Uninstall()
if err != nil {
// handle
}
https://user-images.githubusercontent.com/7120871/197391736-450bef36-4dd6-4c79-8ae7-3bd68a932eec.mp4
See example application for a real-life example.
Note: most of the widgets are direct translations of the one in Apple's documentation and have similar options. Please refer to the official documentation for more details.
You configure this library by specifying a list of items from the following options:
Button
: a button that can be clicked (has an event handler)Candidates
: a list of text options, allows to give custom recommendations for the current text fieldColorPicker
: used to choose a color (has an event handler)Custom
: can render anything you want, feedback any touch with a X position (has an event handler)Group
: used to group other itemsLabel
: allows to display text and imagesPicker
: used to pick one or more options from a list of choices, equivalent to radio/checkbox buttons (has an event handler)Popover
: a button which shows more options when clicked, equivalent to a modal or collapse widgetScrubber
: allows to select items from a list, which supports scrolling (has an event handler)SegmentedControl
: shows multiple buttons grouped together, similar to Picker
(has an event handler)Sharer
: allows to share using the standard macOS sharing systemSlider
: a slider used to pick value in a range (has an event handler)Stepper
: a control to pick a value in a range through increments (has an event handler)But also from this list of standard Apple widgets which have no customizable options:
OtherItemsProxy
: where to display other Touch Bar closer to the first responderSpaceSmall
: a small spaceSpaceLarge
: a bigger spaceSpaceFlexible
: a space that grows as much as possible