File: ZRoot.rst

package info (click to toggle)
tuiwidgets 0.2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,940 kB
  • sloc: cpp: 54,583; python: 495; sh: 83; makefile: 8
file content (155 lines) | stat: -rw-r--r-- 4,984 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
.. _ZRoot:

ZRoot
=====

.. rst-class:: tw-flex-imgs

* .. figure:: tpi/root.tpi

     ZRoot

* .. figure:: tpi/root-fillchar.tpi

     with fill character


ZRoot is designed as the root widget in the widget tree.

It sets a default palette, clears the widget and handles switching between windows using :kbd:`F6` and :kbd:`Shift+F6`.

Commonly an application has a class derived from ZRoot to setup the user interface widget tree.
It is recommended to create the widgets in an overridden :cpp:func:`~void Tui::ZRoot::terminalChanged()` function, so
that all terminal auto detection is already finished when the widget tree is build.

Example
-------

.. literalinclude:: examples/widgets/root.cpp
    :start-after: // snippet-start
    :end-before:  // snippet-end
    :dedent:

See :ref:`Getting_Started` for an example overriding :cpp:func:`~void Tui::ZRoot::terminalChanged()` to setup the
user interface.


.. _ZRoot_keys:

Keyboard Usage
--------------

.. list-table::
   :class: noborder
   :align: left
   :header-rows: 1

   *  - Key
      - State
      - Result

   *  - :kbd:`F6`
      - normal
      - Activate next widget in tab order

   *  - :kbd:`Shift+F6`
      - normal
      - Activate previous widget in tab order

Behavior
--------

ZRoot has by default a minimum size of :cpp:expr:`(40, 7)` to raise the chance that applications not tested with very
small terminals are still somewhat usable.
If an application needs a bigger size to be usable or wants to support smaller sizes it can override this to a suitable
value.

If the terminal is smaller than the minimum size of the root widget (as set in the terminal) the terminal will enable
a minimal viewport scrolling interface so that the root widget still renders at the minimum size and the user can view
parts of the root widget by using the keyboard to scroll the viewport.

See :ref:`term_viewport` for details.

If any child widget of ZRoot implements the :cpp:class:`Tui::ZWindowFacet` and its
:cpp:func:`~bool Tui::ZWindowFacet::isExtendViewport() const` returns :cpp:expr:`true` the minimal size for the root widget is
temporarily extended to include the whole child widget.
This enables selected dialogs and menus to be usable even if the terminal is smaller than the widget.

ZRoot by default has the :cpp:func:`Tui::ZPalette::classic()` palette set as palette.
This palette defines the colors used by the widgets in Tui Widgets.
The predefined palettes only enable palette colors for widgets that are typically used in windows for widgets that are
contained in a widget that has ``window`` as the widget's palette class such as :cpp:class:`Tui::ZWindow` or
:cpp:class:`Tui::ZDialog`.

If ZRoot is resized windows that are neither manually placed nor in a window container according to their
:cpp:class:`Tui::ZWindowFacet` facet implementation are placed using their window facet's auto place implementation.

The layout area of ZRoot is usually its geometry with the contents margins removed.
If the root widgets size is currently expanded due to a window using ``isExtendViewport`` the layout area will not
reflect the temporarily larger geometry due to this window.

Palette
-------

.. list-table::
   :class: noborder
   :align: left
   :header-rows: 1

   *  - Palette Color
      - Usage

   *  - | ``root.fg``,
        | ``root.bg``
      - The body of the widget.


ZRoot
-----

.. cpp:class:: Tui::ZRoot : public Tui::ZWidget

   A widget designed to be used as root of the widget tree.

   **Functions**

   .. cpp:function:: void setFillChar(int fillChar)
   .. cpp:function:: int fillChar() const

      The fill character is what character is used to clear the widgets background.

      It defaults to :cpp:var:`Tui::Erased`.

      This allows for more faithful emulation of the classic look.

   .. cpp:function:: void activateNextWindow()
   .. cpp:function:: void activatePreviousWindow()

      Activate the next/previous child window in the widget.

      Eligible child widgets to activate are widgets that are visible, implement the
      :cpp:class:`Tui::ZWindowFacet` facet and where `ZWidget *placeFocus(bool last)` returns a widget
      (not :cpp:expr:`nullptr`).

      After activation it will be raised using :cpp:func:`~void Tui::ZRoot::raiseOnActivate(ZWidget *w)`.

   .. rst-class:: tw-virtual
   .. cpp:function:: void raiseOnActivate(ZWidget *w)

      Override this function to customize if and how a window is raised when activated.

      The base implementation raises the window using :cpp:func:`void Tui::ZWidget::raise()`.

   **Protected Functions**

   .. rst-class:: tw-virtual
   .. cpp:function:: void terminalChanged()

      This function is called when the terminal changes.

      In applications that don't move the root widget between terminals, it will be called once after the terminal
      auto detection is finished.

      Applications should override this method to build their widget tree.

      The base implementation does nothing.