<< Prev | - Up - | Next >> |
It is common to have parameters repeated over and over for all widgets in a container of the window, or for all widgets of the same type inside the window. For example, the backgroungColor
of many widgets may be set to the same value (red
for example) to give a uniform background to the window. QHTML provides two functionalities to define parameters in a global way : looks and aliases. Note that they share the same two limitations :
Looks and aliases define parameters statically, ie only when building the window. Changing a look or alias after the window construction is not reflected inside windows already built.
A technical limitation makes the glue
parameter only partially supported : container widgets don't take their children widgets looks and aliases into account. As a result, if a contained widget has a glue
parameter defined in a look
or alias
, it is considered by its container widget to be not glued at all, and the default behavior for glue
will be used (ie take the minimal horizontal and vertical space required to draw the widget). Note that contained widgets will take the glue
parameter from aliases and looks correctly into account, however the application of this parameter will be limited to the space they received from their container widget. Example :
MyLook={QTk.newLook}
{MyLook.set button(glue:nswe)}
{{QHTML.build toplevel(lr(button(value:"1") button(value:"2" look:MyLook) newline
button(value:"3") button(value:"4")))} show}
Note that you can mix aliases and looks together. Parameters defined by looks have a higher prior than those defined by aliases.
Looks define a set of default value associated to widgets. Looks are automatically passed from container widgets to their contained widgets. Looks are a very convenient way to define all default parameters for a rectangular area of the window. A look is created by QHTML.newLook
. A look furnishes two procedures as features of the look:
set
: a one parameter procedure whose parameter defines a look entry. A look entry is a record whose label is the name of the widget, and whose features are the default values defined by that entry. Any parameters can be used, but not all will work correctly when building the window. For example, defining a default value for the handle
parameter will make all these widgets try to use the same handle
which will trigger errors at window construction time. Note that you can define an arbitrary number of default values for distinc parameters in a single set
. Note that successive set
will overwrite previous ones.
get
: a one parameter function that returns the value of the entry given as parameter.
All widgets (almost) support the look
parameter that can be specified a QHTML look
.
local
MyLook={QHTML.newLook}
{MyLook.set button(backgroundColor:red)}
{MyLook.set label(backgroundColor:red)}
in
{{QHTML.build toplevel(look:MyLook
td(label(value:"Hello world")
label(value:"Amazing colors !")
button(value:"Ok")
button(value:"Ok also")))} show}
end
An alias defines another name for a widget, a name that is associated to a set of default parameters. Aliases are well adapted to define default values to a specific kind of widgets that are spread throughout entire windows. QHTML provides:
{QHTML.setAlias Name Ref}
: create an alias of the name Name
(an atom). Ref
is a record whose label is the name of the widget the alias is using, and whose parameters are the default values to use with the alias.
{QHTML.unSetAlias Name}
: unset the alias named Name
. Any further attempt to use that alias will raise an exception.
{QHTML.setAlias redLabel label(backgroundColor:red)}
{QHTML.setAlias yellowLabel label(backgroundColor:yellow)}
{{QHTML.build toplevel(td(redLabel(value:"This label is red")
yellowLabel(value:"This label is yellow")))} show}
<< Prev | - Up - | Next >> |