andlabs / ui

Platform-native GUI library for Go.
Other
8.33k stars 652 forks source link

Updating labels in groups not working #383

Closed Vorstenbosch closed 4 years ago

Vorstenbosch commented 4 years ago

I was updating labels (appended to vertical boxes) in the UI based on some operations of my service and this worked ok. All I had to do was call SetText().

I recently moved to group my boxes in Group instances but now my labels no longer get updated. Am I missing something about redrawing groups or is that not supported? Is there another way to force a redraw of the UI?

I verified that the Text() function returns the updated values.

To add some context to the issue:

Vorstenbosch commented 4 years ago

My bad. I completely missed the point about "only using the main thread to update the UI". I'll add my own fix here in case someone else misunderstood how to update the UI.

Although it initially worked to just use SetText() (from another go routine) it is not how the UI is supposed to be updated. You should use the function QueueMain() (from main.go), which is pretty obvious if you actually read the in-code documentation.

When I update my labels like so:

ui.QueueMain(func() {
    // update the UI here
})

It all works as expected.

andlabs commented 4 years ago

Is that still not evident from the godoc documentation? If it isn't, then that's still a bug

Vorstenbosch commented 4 years ago

@andlabs I think it is clear if you read the godoc. I just started building my UI without really reading and grabbed what I needed along the way.

What could help is adding a UI update to the examples. Something as easy as updating a label every so often would give enough inspiration for people who are checking the examples instead of browsing the godoc. I can make a PR if you want.

andlabs commented 4 years ago

Sure, though I do need to go back and go through all the PRs I have pending an API change that's taking longer than I originally wanted; I'll keep this open in the meantime

Vorstenbosch commented 4 years ago

@andlabs Shall we close this now the examples are merged?

andlabs commented 4 years ago

All right, I don't remember why not