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.

3.1. Spinner as a standalone SWidget

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.

Figure 3.1. The spinner after clicking + 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.

Listing 3.1. SSpinner: your own spinner widget

Check this out with git, if you haven’t done so already, and run it like this:

3.2. Form validation

3.3. Summary

sitemap