Background processing

As you may have realized from the first line of andlabs UI code (ui.Main(func() { ... })), multithreading is something that needs to be considered when building using this API. This is due to the fact that most of the toolkits it integrates with will require graphical updates to all execute on the same thread (often, the main application thread). The andlabs UI aims to hide this complexity by managing the threads internally and provides helper methods to manage this.

As a result of this design, any user interface updates outside of the ui.Main() setup (or callbacks on controls created there) must be passed to the ui.QueueMain() method in the form of a function, as with the initial setup. This allows andlabs UI code to process the updates on the appropriate thread for the current framework. The following code illustrates how a label's text could be changed as the result of some background processing:

ui.QueueMain(func () {
label.SetText("background")
})

Callbacks such as OnClicked() and OnClosing() also take a func() parameter, just as the ui.QueueMain() function does. This code will automatically be executed on the correct thread, so there is no additional complexity to worry about.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.223.171.51