GNU TeXmacsUser manualReferenceAboutEnglish
The graphical user interface through markup (experimental)

The graphical user interface through markup builds dialogs and other widgets as TeXmacs documents, shown in a TeXmacs view, instead of native widgets of the toolkit. The widgets are then typeset, themed and rendered as any document is, which would unify the various rendering mechanisms of the interface (the native widgets of Qt, Vue or Cocoa, and the typesetter), and make the interface stylable by style files. It is in development: it covers the dialogs and the top windows made from tm-widget descriptions, while the menus, the tool bars and the side tools remain native widgets.

1.Turning it on

The path is taken when (has-markup-gui?) holds (

tm-modes.scm

), that is when the preferences markup gui and developer tool are both on: enable Tools\(\rightarrow\)Developer tool, then View\(\rightarrow\)GUI through markup (toggle-markup-gui,

tm-view.scm

). make-menu-widget* (

menu-widget.scm

) then builds markup instead of native widgets for top-window and dialogue-window.

The path does not depend on the port: the test is a preference, not (gui-version), and the markup is shown in an editor embedded in a dialog (texmacs_input_widget, texmacs_output_widget in

tm_window.cpp

and

tm_button.cpp

), which all the ports provide through their TeXmacs widget: Qt, Vue, Cocoa, and X11, SDL and Qtwk with Widkit. Only the menus, bars and side tools around it are those of the port.

2.Two generations

The style packages of

packages/gui

(gui, gui-widget, gui-form, gui-layout and the themes gui-metal, gui-brushed, gui-granite, from 2007) are a first attempt: forms with inputs (short-input, wide-input, …), buttons, toggles and radio buttons whose actions are links (action), framed boxes made with ornament, and textures as themes. They are used by the old widgets of

kernel/old-gui

(widget-popup, widget-ref, widget-set!), which show them in an auxiliary buffer; this generation is legacy.

The current generation is in

packages/new-gui

(from 2022): its elements react to the mouse by themselves, through two primitives of the typesetter, and the interpreter of tm-widget descriptions produces it. The rest of this chapter is about it.

3.The style packages

gui-button.ts

The core package (gui-system-font, colours gui-bg-color, button-bg-color, gui-input-color…). It defines:

  • buttons: action-button, action-button*, menu-button, menu-button*, each with its looks -normal, -hover and -pressed (ornaments, with a blurred contour gui-contour);

  • toggles: toggle-button, toggle-on-button, toggle-off-button;

  • layout: hlist, vlist, tiled, align-tiled (rewritten into tables by Scheme), glue, raw-table;

  • inputs: input-area, input-field, input-popup, input-list, and the lists choice-list, check-list;

  • tabs: tabs, tabs-bar, tabs-body, active-tab, passive-tab;

  • forms: form-input-text, form-text-area, form-checkbox;

  • styles of text and sections (title-style, section-style, plain-style…), sizes (minipar) and the whole widget, top-widget.

gui-bright, gui-dark

Themes: they load gui-button and set its colours. get-gui-style (

menu-convert.scm

) chooses one from the preference gui theme, which also chooses the theme of Vue.

gui-base, side-tools

Settings of a document shown as a widget, and a smaller magnification for the side tools.

gui-keyboard.ts

Virtual keyboards: keyboard, std-key, extended-key, simple-key, mod-key; with the style new-gui (

styles/test/new-gui.ts

).

4.How the elements react

An element of the new generation is drawn by dynamic-case, which chooses one of its looks from the messages which its box receives, and sends its events to Scheme with relay. For instance action-button* is

<dynamic-case|click,drag|<relay|<action-button-pressed*|x>|gui-on-select|cmd>|mouse-over|<relay|<action-button-hover*|x>|gui-on-select|cmd>|any|<relay|<action-button-normal*|x>|gui-on-select|cmd>>

Some elements are links instead (passive-tab is an action): they follow the usual links, with a double click in an editable document and the security checks of scripts.

5.The Scheme support

gui-utils.scm

, loaded by gui-button (use-module), receives the events:

gui-on-select

On click and drag it only consumes the event; on select (the button released) it gives the focus back to the master buffer, evaluates the command of the element (a string) when idle, and closes the tooltips.

gui-on-toggle

Changes the value of the toggle in the document and runs its command with answer (and name, for form-checkbox) bound.

gui-on-choice

Updates the current item of a choice list and runs its command with answer.

keyboard-press

Overloaded in input fields: Return runs the command of an input-field with its value; in the fields of forms, every key does.

tab-select

Switches the tabs in place.

gui-hlist-table, gui-vlist-table, gui-tiled

Rewrite the lists into tables (extern).

The commands in the markup are evaluated with secure-eval: they may only use secure functions (tm-define with (:secure #t)), which is why the functions above are secure. The keyboard emulates keys with emu-key and emu-toggle-modifier (

gui-keyboard.scm

generates its layouts).

6.The interpreter of widgets

menu-convert.scm

turns a tm-widget description into this markup, as make-menu-widget turns it into native widgets (see the markup interpreter): build-menu-widget calls a markup-… function for each item (texts, menu buttons, toggles, inputs and enumerations, choices, tabs, lists, balloons, divisions, texmacs-output and texmacs-input). The commands are kept in a table and referred to by (eval-nullary-mangled n) or (eval-unary-mangled n answer). make-menu-widget** shows the document (top-widget …) in a texmacs-input widget of the auxiliary buffer tmfs://aux/gui/…, whose master is the current buffer, with the style (tuple "generic" theme).

Not done yet: a refreshable is expanded once, without being shown again on refresh-now; separators, extend and scrollable give nothing; colour pickers, tree views and ink widgets are placeholders; shortcuts are not shown; the table of commands is never emptied.

7.Where it is used

8.A small example

More examples, which can be tried, are in examples of the graphical user interface through markup.

A document with the style gui-button (or gui-dark, gui-bright) shows such a widget; the commands are written as strings, and may use answer and name:

<TeXmacs|2.1.4>
<style|<tuple|generic|gui-button>>
<\body>
  <\top-widget>
    <vlist|<title-style|Demo>
      |<hlist|<action-button|Hello|(display* "hello\n")>
             |<form-checkbox|flag|false|(display* name " = " answer "\n")>>
      |<choice-list|(display* answer "\n")|Red|Red|Green|Blue>
      |<input-field|string|(display* answer "\n")|10em|type here>
      |<tabs|<tabs-bar|<active-tab|One>|<passive-tab|Two>>
             |<tabs-body|<shown|First page>|<hidden|Second page>>>>
  </top-widget>
</body>

The same markup can be shown in a dialog with texmacs-output, as (texmacs-output '(…) '(style (tuple "generic" "gui-button"))).

9.Loose ends

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