![]() |
Containers, glue, refresh and co. | ![]() |
In what follows widget stands for menu items, as in the body of a tm-widget; a widget defined with tm-widget is included with (dynamic (name)) or (link name).
This does just that: it centers widget with respect to the enclosing widget. Although we are calling this an attribute, the effect is achieved by using a vertical list and a horizontal one together with four glue widgets. This means that in the following example, the first widget is actually expanded to something like the second one.
(tm-widget (wid1)
(centered (text "I'm centered.")))
Scheme]
(tm-widget (wid2)
(vlist
(glue #f #f 0 10)
(hlist
(glue #t #f 25 0)
(text "I'm centered.")
(glue #t #f 25 0))
(glue #f #f 0 10)))
Scheme]
(show wid1)
Scheme]
(show wid2)
Scheme]
(resize '(w1 w2 w3) '(h1 h2 h3) widget)
These two variants resize the argument. The first one specifies a minimum size of w1\(\times\)h1, a default size of w2\(\times\)h2 and a maximum size of w3\(\times\)h3. widget will be set to the default size and will be allowed to resize but not beyond the bounds specified. The second alternative sets a fixed width and height. Both size arguments are evaluated, so that lists must be quoted; both variants may also be mixed.
Sizes are specified as strings with a unit suffix, like in "150px".
(tm-widget (wid)
(resize "200px" "70px" (text "I'm
stuck!")))
Scheme]
(show wid)
Scheme]
This sets some fixed padding around widget. As in the case of centered, the effect is achieved by means of several widgets into which this macro expands. These are actually the same as in the example there, but the glue widgets are all fixed (i.e. have all their expansion parameters set to #f).
You can arrange widgets horizontally or vertically, or in two column mode as in forms (labels aligned at the right of their column, as the ports draw them). Other possibilities are splitters and tabbed widgets. A very useful macro is dynamic, which allows you to embed one widget into another.
Each item gives the contents of the two cells of a row, usually a label and an input widget. (meti right left) is the same as (item left right). An example can be found in “Dialogs and composite widgets”.
Arranges its arguments from left to right. Use glue widgets (see below) to separate them.
Arranges its arguments from top to bottom. The variants horizontal and vertical are mainly used for menus and toolbars.
(hsplit left right)
Puts exactly two widgets side by side resp. one above the other, separated by a border which can be moved by the user.
A tabbed widget with one page per tab; the first argument of each tab is the label of the tab (for instance (text "General")), the remaining ones form the contents of the page:
(tm-widget (tabs-example)
(tabs
(tab (text "First") (text "Contents of the first tab"))
(tab (text "Second") (text "Contents of the second tab")))) |
With icon-tabs and (icon-tab icon-file label widgets), the tabs also display an icon, as in the preferences dialog.
Evaluates expr, typically a call (some-widget args) of a function defined with tm-widget or tm-menu, and inserts the resulting widgets at this place. For menus without arguments, one may also use (link some-menu).
Besides laying out widgets in containers, you will often want to specify how they eat up space around them when the user resizes the window. By default (most?) widgets take up as much space as they can (i.e. they always expand) unless you used resize with them or they can have their size set with a parameter. If you don't want this to happen you can place invisible spacers around them which will (if you tell them to) gobble up as much as they can, either vertically or horizontally or in both directions.
TeXmacs provides one such basic building block:
The first two parameters, horiz and vert, are of boolean type and specify whether the glue widget will try to expand horizontally or vertically when its surroundings do. The last two parameters, width height, either fix the size for non-expanding glue or set a minimum one.
(tm-widget (wid1)
(centered (text "I'm centered.")))
Scheme]
(tm-widget (wid2)
(vlist
(glue #f #f 0 10)
(hlist
(glue #t #f 25 0)
(text "I'm centered.")
(glue #t #f 25 0))
(glue #f #f 0 10)))
Scheme]
(show wid1)
Scheme]
(show wid2)
Scheme]
In addition to the basic glue widget, there are several convenience macros.
Expands to (glue #f #f 0 5).
Expands to (glue #f #f 0 15).
Expands to (glue #f #f 5 0).
Expands to (glue #f #f 15 0).
Expands to (glue #t #f 5 0).
Expands to (glue #t #f 15 0).
For the specific use in menus the following two macros are defined:
A vertical separator line between the items of a horizontal menu or toolbar.
A horizontal separator line between the items of a vertical menu or list.
Widgets are normally built once, when they are displayed. Refresh widgets are rebuilt on demand, so that they can reflect new values of your variables. Only part of their contents is evaluated again, though: the items of a refreshable are computed when the enclosing widget is built, and a refresh makes the widgets again from them. What is evaluated again at a refresh are the conditions of if and when, the lists of for, promises, link and refresh, the sizes of resize, and the values and lists of the fields (input, enum, choice, toggle). Texts and labels, dynamic, assuming, loop, eval and the values of let and with keep the value which they had when the widget was built: an item which must change, such as (text expr), is written as (promise (list 'text expr)), or chosen with if as in the example below.
The widgets are rebuilt whenever (refresh-now kind) is executed, where kind is a string. For instance, the following widget from
menu-test.scm
changes its text when the toggle is clicked:
(tm-widget (widget9)
(padded
(with flag? #f
(refreshable "test"
(if (not flag?) (text "Flag is off"))
(if flag? (text "Flag is on")))
===
(hlist
(toggle (begin (set! flag? answer) (refresh-now
"test")) flag?)
///
(text "Toggle here")))))
Scheme]
(show widget9)
Scheme]
Refreshable widgets of kind "auto" are automatically rebuilt after each user command.
Includes the widget or menu widget (a name defined by tm-widget or menu-bind without arguments, not evaluated), which is rebuilt in the same way. Here kind is written as a symbol, as in (refresh widget8-sub auto).
Like refreshable, but the previously built widget is reused as long as valid? holds; (invalidate-now kind) forces the widget to be rebuilt.
The implementation of these widgets is described in “The Scheme widget language and its interpreter”.