Differentiating between UI changes from the main thread and another goroutine

This commit is contained in:
vorstenbosch 2020-06-06 00:39:16 +02:00
parent f9ad173d6a
commit d219f06887
1 changed files with 7 additions and 11 deletions

View File

@ -81,20 +81,19 @@ func setupUI() {
mainWindow.SetChild(vbContainer) mainWindow.SetChild(vbContainer)
showMessageButton.OnClicked(func(*ui.Button) { showMessageButton.OnClicked(func(*ui.Button) {
// Update the UI using the QueueMain function // Update the UI directly as it is called from the main thread
ui.QueueMain(func() { messageLabel.SetText(message.Text())
messageLabel.SetText(message.Text())
})
}) })
clearMessageButton.OnClicked(func(*ui.Button) { clearMessageButton.OnClicked(func(*ui.Button) {
// Update the UI using the QueueMain function // Update the UI directly as it is called from the main thread
ui.QueueMain(func() { messageLabel.SetText("")
messageLabel.SetText("")
})
}) })
mainWindow.Show() mainWindow.Show()
// Counting and updating the UI from another goroutine
go counter()
} }
func counter() { func counter() {
@ -112,8 +111,5 @@ func counter() {
func main() { func main() {
count = 0 count = 0
// Counting and updating the UI from another goroutine
go counter()
ui.Main(setupUI) ui.Main(setupUI)
} }