Chapter 3. Some everyday widget stuff
This chapter covers
- Some simple GUI widget examples
We’re using this short chapter to cement the concepts of FRP with two more simple SWidget examples. We’re continuing to avoid telling you about StreamSink and CellSink for now so we can achieve a clear separation in your mind between FRP and non-FRP. We’ve talked about how people tend to gravitate toward familiar concepts—we don’t want you saying, “I know how to do this” and mixing sinks into your FRP logic, because this breaks the model. We want you to see what becomes possible when you view streams and cells only as sources.
These examples use the same primitives introduced in chapter 2, so you may need to refer back to it to refresh your memory. Let’s get started.
Let’s take the spinner concept from the previous chapter and separate it out into a new SWidget. You’ll also use a text field instead of a label so it’s more useful. Figure 3.1 shows what it looks like after you click + once.
The next listing shows the separated-out SSpinner class. We’ve left out the main program. It just constructs an SSpinner and adds it to the view. On the input and output side of the text field, you convert between integer and string using map.