SwiftUI
ui.SwiftUI は、Go アプリに本物の macOS コントロールを埋め込みます。通常の QuickGUI コンポーネントには必要ありません。
#Host
コントロールは ui.SwiftUI.Host の中で作ります。Host はネイティブビューの境界であり、内容から自身のサイズを決められます。
func SwiftUiHostExample() *ui.Element {
return ui.SwiftUI.Host(
ui.SwiftUIHostProps{MatchContents: true},
func() *ui.Element {
return ui.SwiftUI.Button(ui.SwiftUIButtonProps{Label: "Continue"})
},
)
}#ネイティブコントロール
Button、Slider、Toggle、ProgressView、Stepper、TextField、SecureField、Picker、SegmentedControl、DatePicker、ColorPicker、Gauge。見た目と動作はシステムのコントロールと同じです。
#制御値
シグナルをバインドし、ネイティブコールバックから値を保存します。SwiftUI コントロールと QuickGUI ビューは同じシグナルを共有できます。DatePicker はミリ秒の Unix タイムスタンプを使います。
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) },
})
},
)
}#サイズ
MatchContents: true は両軸をコントロールから決めます。固有の高さだけ欲しいときは ui.SwiftUIMatchContents{Vertical: true} を使い、幅は自分で設定します。
ui.SwiftUIHostProps{
MatchContents: ui.SwiftUIMatchContents{Vertical: true},
PartProps: ui.PartProps{Style: ui.Style().Width(320)},
}#対応プラットフォーム
SwiftUI のホスティングには macOS が必要です。見た目は OS のバージョンによって変わることがあります。
