Note - this API is designed to support a narrow (but common!) set
of use cases. If you find that you need more customization than this
offers, then you will need to consider building your own layout and
event handling for input fields.
For a fuller introduction to this API, see the "Input Forms" section
of the Brick User Guide. Also see the demonstration programs for
examples of forms in action.
This module provides an input form API. This API allows you to
construct an input interface based on a data type of your choice.
Each input in the form corresponds to a field in your data type. This
API then automatically dispatches keyboard and mouse input events to
each form input field, manages rendering of the form, notifies the
user when a form field's value is invalid, and stores valid inputs in
your data type when possible.
A form has both a visual representation and a corresponding data
structure representing the latest valid values for that form
(referred to as the "state" of the form). A FormField is a single
input component in the form and a FormFieldState defines the
linkage between that visual input and the corresponding portion
of the state represented by that visual; there may be multiple
FormFields combined for a single FormFieldState (e.g. a radio
button sequence).
To use a Form, you must include it within your application state
type. You can use formState to access the underlying state whenever
you need it. See programs/FormDemo.hs for a complete working
example.
Also note that, by default, forms and their field inputs are
concatenated together in a vBox. This can be customized on a
per-field basis and for the entire form by using the functions
setFieldConcat and setFormConcat, respectively.
Bear in mind that for most uses, the FormField and FormFieldState
types will not be used directly. Instead, the constructors for
various field types (such as editTextField) will be used instead.