GNU TeXmacsUser manualReferenceAboutEnglish
Containers, glue, refresh and co.

1.Attribute widgets

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).

(centered widget)
(centers widget)

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.

Scheme]

(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)

(resize '(w1 w2 w3) '(h1 h2 h3) widget)

(resize w h widget)
(resizes 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".

Scheme]

(tm-widget (wid)

(resize "200px" "70px" (text "I'm stuck!")))

Scheme]

(show wid)

(padded widget)
(surrounds widget by padding)

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).

2.Container or layout widgets

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.

(aligned (item left right) …)
(arranges items in a two column table)

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”.

(hlist widgets)
(arranges items horizontally)

Arranges its arguments from left to right. Use glue widgets (see below) to separate them.

(vlist widgets)
(arranges items vertically)

Arranges its arguments from top to bottom. The variants horizontal and vertical are mainly used for menus and toolbars.

(hsplit left right)

(vsplit top bottom)
(arranges two items in a split panel)

Puts exactly two widgets side by side resp. one above the other, separated by a border which can be moved by the user.

(tabs (tab label widgets) (tab label widgets) …)
(a tabbed widget)

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.

(dynamic expr)
(embeds a tm-widget into another one)

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).

3.Glue widgets

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:

(glue horiz vert width height)
(possibly expanding whitespace)

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.

Scheme]

(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)

In addition to the basic glue widget, there are several convenience macros.

===
(vertical separator)

Expands to (glue #f #f 0 5).

======
(big vertical separator)

Expands to (glue #f #f 0 15).

//
(horizontal separator)

Expands to (glue #f #f 5 0).

///
(big horizontal separator)

Expands to (glue #f #f 15 0).

>>
(expanding horizontal separator)

Expands to (glue #t #f 5 0).

>>>
(big expanding horizontal separator)

Expands to (glue #t #f 15 0).

For the specific use in menus the following two macros are defined:

| or /
(separator in horizontal menus)

A vertical separator line between the items of a horizontal menu or toolbar.

---
(separator in vertical menus)

A horizontal separator line between the items of a vertical menu or list.

4.Refresh widgets

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.

(refreshable kind widgets)
(a widget which can be rebuilt)

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:

Scheme]

(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)

Refreshable widgets of kind "auto" are automatically rebuilt after each user command.

(refresh widget kind)
(a named widget which can be rebuilt)

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).

(cached kind valid? widgets)
(a refreshable widget with a cache)

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”.

Permission is granted to copy, distribute and/or modify this˙document under the terms of the GNU Free Documentation License, Version 1.1 or˙any later version published by the Free Software Foundation; with no Invariant˙Sections, with no Front-Cover Texts, and with no Back-Cover Texts. A copy of˙the license is included in the section entitled "GNU Free Documentation License".