buttonF
, and a
customisable version, for example buttonF'
. The name of
the customisable version is obtained by appending a '
to the
name of the standard version.
Customisable fudgets have a number of parameters that allow things like fonts, colors, border width, etc., to be specified. All these parameters have default values which are used in the standard version of the fudget.
Rather than having one extra argument for each such parameter, customisable versions of fudgets (or other functions) have one extra argument which is a customiser. The customiser is always the first argument. A customiser is a function that modifies a data structure containing the values of all parameters.
The type of the data structure is abstract. Its name is usually the name of the fudget, with the first letter change to upper case--for example,type Customiser a = a -> a
ButtonF
in the case of buttonF'
.So, customisers are obtained by composing a number of modifying functions using ordinary function composition. The functionbuttonF' :: (Graphic a) => (Customiser (ButtonF a)) -> a -> F Click Click
standard
,acts as the identity customiser and does not change any parameters. The standard versions of the fudgets are simply the customisable versions applied tostandard :: Customiser a
standard
, for example:
buttonF = buttonF' standard
The customisers that are common to many fudgets are overloaded. Some customiser classes are shown in Figure 23.
class HasBgColorSpec a where setBgColorSpec :: ColorSpec -> Customiser a class HasFgColorSpec a where setFgColorSpec :: ColorSpec -> Customiser a class HasFont a where setFont :: FontName -> Customiser a class HasMargin a where setMargin :: Int -> Customiser a class HasAlign a where setAlign :: Alignment -> Customiser a class HasKeys a where setKeys :: [(ModState, KeySym)] -> Customiser a ...Figure 23. Some customiser classes.
The table in Figure 24 shows what customisers are supported by the different customisable fudgets in the current version of the Fudget library.
BgColorSpec
FgColorSpec
Font
Margin
Align
Keys
TextF
y y y y y n DisplayF
y y y y y n StringF
y y y n n n ButtonF
y y y n n y ToggleButtonF
n n y n n y RadioGroupF
n n y n n n ShellF
n n n y n n Figure 24. Some customiser instances.
Some fudgets also have non-overloaded customisers, for example:
As an example of the use of customisation, Figure 25 shows a variation of the radio group shown in Figure 10.setInitDisp :: a -> Customiser (DisplayF a) -- changes what is displayed initially setAllowedChar :: (Char -> Bool) -> Customiser StringF -- changes what characters are allowed setPlacer :: Placer -> Customiser RadioGroupF -- changes the placements of the buttons
radioGroupF' (setFont "fixed" . setPlacer (matrixP 2)) [(1,"P1"),(2,"P2"),(3,"P3"),(0,"Off")] 0Figure 25. Custom version of the radio group in Figure 10.