SwiftUI
ui.SwiftUI embeds real macOS controls in a Go application. Ordinary QuickGUI components work without it.
#Host
Create controls inside ui.SwiftUI.Host. The host is the native view boundary and can size itself from its content.
func SwiftUiHostExample() *ui.Element {
return ui.SwiftUI.Host(
ui.SwiftUIHostProps{MatchContents: true},
func() *ui.Element {
return ui.SwiftUI.Button(ui.SwiftUIButtonProps{Label: "Continue"})
},
)
}#Native controls
Button, Slider, Toggle, ProgressView, Stepper, TextField, SecureField, Picker, SegmentedControl, DatePicker, ColorPicker, and Gauge. They look and behave like the system controls.
#Controlled values
Bind a signal and store the value from the native callback. A SwiftUI control and a QuickGUI view can share the same signal. DatePicker uses Unix timestamps in milliseconds.
func SwiftUiToggleExample() *ui.Element {
on, setOn := ui.CreateSignal(true)
return ui.SwiftUI.Host(
ui.SwiftUIHostProps{MatchContents: true},
func() *ui.Element {
return ui.SwiftUI.Toggle(ui.SwiftUIToggleProps{
IsOn: on,
Label: "Notifications",
OnIsOnChange: func(next bool, _ *native.Event) { setOn(next) },
})
},
)
}#Sizing
MatchContents: true sizes both axes from the control. Use ui.SwiftUIMatchContents{Vertical: true} for an intrinsic height and set the width yourself.
ui.SwiftUIHostProps{
MatchContents: ui.SwiftUIMatchContents{Vertical: true},
PartProps: ui.PartProps{Style: ui.Style().Width(320)},
}#Platform support
SwiftUI hosting requires macOS. Appearance can vary with the operating-system version.
