![]() |
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.
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.
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.
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.
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.
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
).
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>> |
dynamic-case is typeset as a case_box (
case_boxes.cpp
), with all its branches; a message (click, mouse-over, focus, a broadcast message, or a comma separated list of them; any matches all) shows the branch of the first case which it satisfies.
relay is typeset as a relay_box (
change_boxes.cpp
): a message calls the Scheme function given as second argument with the type of the event, its position and the other (evaluated) arguments, through secure-eval; a result other than #f invalidates the box, and a string or tree result is given back.
In an editor (a document, an auxiliary buffer, a texmacs-input widget), edit_interface_rep::mouse_click and mouse_select send click and select to the boxes first (
edit_mouse.cpp
); a non-empty answer stops the usual moving of the cursor. In a texmacs-output widget, box_widget_rep::handle_mouse (
tm_button.cpp
) does the same.
broadcast-message sends a message to all the boxes of the view (edit_interface_rep::broadcast_message): the keyboard uses it to show its keys in their shifted form (shift, no-shift) without typesetting again.
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.
gui-utils.scm
, loaded by gui-button (use-module), receives the events:
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.
Changes the value of the toggle in the document and runs its command with answer (and name, for form-checkbox) bound.
Updates the current item of a choice list and runs its command with answer.
Overloaded in input fields: Return runs the command of an input-field with its value; in the fields of forms, every key does.
Switches the tabs in place.
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).
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.
The dialogs and top windows, with View\(\rightarrow\)GUI through markup.
The custom keyboard (Developer\(\rightarrow\)Custom keyboard), shown in a texmacs-output widget with the style new-gui (all ports), or as native buttons built from the same markup (QTMOnscreenKeyboard, Qt only).
The preferences of a server, a form (
progs/forms/server-preferences.tm
) with form-input-text and form-checkbox.
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"))).
toggle-on-button and toggle-off-button mark an argument x which they do not have.
gui-on-toggle builds (with name 'cmd) for a toggle-button (which has no name), so that the command is not run: the toggles made by the interpreter do nothing, while form-checkbox works.
The keyboard narrow-us-keyboard tests modifiers in upper case, while they are kept in lower case.