Adapting data types for display
In the example we worked through in the previous section, we learned that it's possible to bind the same value to different widgets since both Slider
and ProgressBar
expect a Float
value for their data. However, it is not always the case that these data types will align perfectly. Sometimes, we will need to perform conversions to connect to the widgets we wish to use. In this section, we will explore how to do so, starting with how we can include a label in the preceding example.
Formatting types into strings
In many applications, it is common to use a Label
or other string-based display to contain information in another format, such as an int
or float64
. With data bindings, this is no different, so the binding
package provides conversion functions that can make this adaptation easy.
To follow on from the previous example, we could include a Label
that displays the float64
value, but to do so, we would need a String
binding rather than...