Go to the first, previous, next, last section, table of contents.

Style environments

We need to be able to deal with configuring large hierarchies of components flexibly,i.e., no compilation in order to change button Foo's foreground colour into something slightly darker.

Enter Styles, which are used to structure the customisation attributes and values that user interface components may specify and lookup when created/realised. A Style provides a hierarchical database of style (name,value) pairs that can be queried and extended.

The Style interface borrows most ideas from the Style interface in Fresco and the Style operations provided by eXene, both of which are generalisations of the Xrm abstraction in Xlib which Xt makes good use of (the Xrm stuff is again based on Brian Reid's Scribe). The Style interface here is also based on the resource specifications used in X11, so it does not introduce any new resource specification syntax for the end-user.

A Style consist of two parts, a set of (style option, value) environments, and an inherited style name that determines the context lookups should use. To illustrate the use of style names, imagine we are using a quit button


quitButton :: Component (Button (), DisplayHandle)

main =
 mkDC styleVals                        >>= \ env ->
  button (text "Noddy") () env         >>= \ (_,btn_dh) ->
  quitButton env                       >>= \ (_,quit_dh) ->
 realiseDH env (hbox [btn_dh,quit_dh]) >>
 return ()

To specify the background colour using a Style environment, the following style environment could be used


styleVals = ["*background: red"]

This would turn both the push and quit button red, so if we wanted to limit the red background to the quit button, the environment would have to be


styleVals = ["*QuitButton*background: red"]

Clearly, the quitButton calls upon button to create an instance of itself. But before doing so, it appends the QuitButton name to the inherited style name, and passes the modified Style on. When button is looking up the background colour, the lookup routines append the background style option to the style name:


button pic =
 ...
 resolveStyle style "background" black (read) >>= \ bg ->
 ...

The effective style name used to look up the background for the quit button is then


Haggis.HBox.QuitButton.Button.background

so the style specification "*QuitButton*background: red" will match.

Note that the entries in the style database specifies patterns, while the lookup give precise names, the reverse of `normal' database access.

[Much more on this later]


Go to the first, previous, next, last section, table of contents.