GNU TeXmacsUser manualReferenceAboutEnglish
An introduction to widgets

In TeXmacs you create and extend the visual interface using widgets . This word means either the basic building blocks you have at your disposal, like buttons, popup lists, etc. or the collections of those into dialogs, menu bars or whatever. This rather loose concept might be confusing, especially when we refer to what usually are know as dialogs as widgets, but it makes sense because all sorts of widgets can be aggregated to build more complicated ones as well.

1. If you miss some particular “building block” from your OS, you might see whether it's feasible as an aggregation of simpler ones or try and play with the UI interface code in C++ (but you'll have to add it for every supported platform!).

1

However, it must be kept in mind that items intended to be inserted in a menu bar won't necessarily display as they do in a separate window: complicated aggregations of widgets might be better placed in a separate window or dialogue, as explained in “Dialogs and composite widgets”.

A complete reference with all the available widgets is the “Widgets reference guide”, and you can find some examples in the other subsections of “Extending the graphical user interface”. If you'd rather see the sources, the whole list of keywords is in the table gui-make-table inside

menu-define.scm

. How the widget language is implemented is explained in “The Scheme widget language and its interpreter”.

To create a widget, you'll first need to use tm-widget to define a new one. This macro works like tm-define, but its body is written in a special language, with many keywords for the creation of widgets. But we'll start with some buttons and labels.

Execute the following two lines to get the unavoidable example and click on the “Hello” button.

Scheme]

(tm-widget (example1) ("Hello" (set-message "world!" "Hello")))

Scheme]

(top-window example1 "A first try")

As you can see, buttons are implicitly created by simply writing a list with the button's title, followed by the Scheme code to be executed when the button is pressed (here, a message is displayed in the footer of the main window). This is exactly the syntax of menu entries, and the button is rendered as a flat toolbar button. What you probably want is this:

Scheme]

(tm-widget (example2) (explicit-buttons ("Hello" (noop))))

Scheme]

(top-window example2 "A nicer button")

The command is now a no-operation, or (noop). Try changing it for (display "World") or anything that suits you.

The next step is to add some text next to the button, i.e. a label. This is done with the text keyword, as in (text "Hello"), but in order to have both widgets sit side by side, you'll need a container widget as described in "Containers, glue, refresh and co.", such as hlist:

Scheme]

(tm-widget (example3)

(hlist

(text "Hello")

(explicit-buttons ("world" (display "!\n")))))

Scheme]

(top-window example3 "Some text")

That was nice, but as you see, the two widgets are packed together until you resize the window. We need to explicitly tell TeXmacs to insert some space between them:

Scheme]

(tm-widget (example3)

(hlist

(text "Hello")

>>>

(explicit-buttons ("world" (display "!\n")))))

Scheme]

(top-window example3 "Some text")

The special symbol >>> is just one of the predefined glue widgets described in "Containers, glue, refresh and co.".

Text attributes may be changed for text widgets and many others by enclosing them inside what we'll name style widgets. These attributes are mono, grey, inert, bold, verb and explicit-buttons, and respectively: choose a monospaced font, set the color to grey, deactivate the widget (meaning it is rendered, but greyed out and inactive), choose a bold face, do not translate the labels and render entries as explicit buttons. There is also plain-style, meant to reset the style, which currently changes nothing. (The layout helper centered is not a style, but it can be used in a similar way.) Here is an example:

Scheme]

(tm-widget (example3)

(hlist

(bold (text "Hello"))

>>>

(inert (explicit-buttons ("world" (display "!\n"))))))

Scheme]

(top-window example3 "Some text")

From here you can go on reading “Extending the graphical user interface” or see the sample widgets in

menu-test.scm

. This file also defines the helper (show widget), which is short for (top-window widget "Simple widget") and is used in the examples of the following sections.

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