pioneerspacesim/pioneer — pull request #2366 by robn (2013-07-08 22:09:19+00:00)
Title: Bind object properties to UI widgets

A facility to automatically update UI widgets on property change.

A widget declares some "bind points", which are really just a name->method mapping. Then some UI client can bind a named object property to a bind point. When the property changes, the bind point method is called with the name of the property. That method can then make necessary changes to the widget's appearance.

Its done this way to avoid a round-trip through Lua for every update, and to avoid the need for Lua to poll and update.

This patch includes a single bind point on `Label` called `text`. To test, try this:

* Launch
* Point at the sky
* Switch to set speed
* Set speed to something astronomically huge (to ensure that the thrusters stay on)
* Switch to the infoview (F3) (to get the UI context on screen)
* Enter the console
* `l = Engine.ui:Label("")`
* `l:Bind("text", Game.player, "fuel")
* `Engine.ui:SetInnerWidget(l)
* Close the console and watch the number. That's your fuel value.

I will be adding bind points to other widgets as necessary in the future (and I have some new widgets on the way as well).