FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
elements.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_DOM_ELEMENTS_HPP
5#define FTXUI_DOM_ELEMENTS_HPP
6
7#include <functional>
8#include <memory>
9
10#include "ftxui/dom/canvas.hpp"
14#include "ftxui/dom/node.hpp"
15#include "ftxui/screen/box.hpp"
18#include "ftxui/util/ref.hpp"
19
20namespace ftxui {
21class Node;
22using Element = std::shared_ptr<Node>;
23using Elements = std::vector<Element>;
24using Decorator = std::function<Element(Element)>;
25using GraphFunction = std::function<std::vector<int>(int, int)>;
26
27/// @brief BorderStyle is an enumeration that represents the different styles
28/// of borders that can be applied to elements in the terminal UI.
29///
30/// BorderStyle is an enumeration that represents the different styles of
31/// borders that can be applied to elements in the terminal UI.
32/// It is used to define the visual appearance of borders around elements,
33/// such as windows, frames, or separators.
34/// @ingroup dom
43
44// Pipe elements into decorator togethers.
45// For instance the next lines are equivalents:
46// -> text("ftxui") | bold | underlined
47// -> underlined(bold(text("FTXUI")))
48Element operator|(Element, Decorator);
49Element& operator|=(Element&, Decorator);
50Elements operator|(Elements, Decorator);
51Decorator operator|(Decorator, Decorator);
52
53// --- Widget ---
54Element text(std::string text);
55Element vtext(std::string text);
56Element separator();
57Element separatorLight();
58Element separatorDashed();
59Element separatorHeavy();
60Element separatorDouble();
61Element separatorEmpty();
62Element separatorStyled(BorderStyle);
63Element separator(Pixel);
64Element separatorCharacter(std::string);
65Element separatorHSelector(float left,
66 float right,
67 Color unselected_color,
68 Color selected_color);
69Element separatorVSelector(float up,
70 float down,
71 Color unselected_color,
72 Color selected_color);
73Element gauge(float progress);
74Element gaugeLeft(float progress);
75Element gaugeRight(float progress);
76Element gaugeUp(float progress);
77Element gaugeDown(float progress);
78Element gaugeDirection(float progress, Direction direction);
79Element border(Element);
80Element borderLight(Element);
81Element borderDashed(Element);
82Element borderHeavy(Element);
83Element borderDouble(Element);
84Element borderRounded(Element);
85Element borderEmpty(Element);
86Decorator borderStyled(BorderStyle);
87Decorator borderStyled(BorderStyle, Color);
88Decorator borderStyled(Color);
89Decorator borderWith(const Pixel&);
90Element window(Element title, Element content, BorderStyle border = ROUNDED);
91Element spinner(int charset_index, size_t image_index);
92Element paragraph(const std::string& text);
93Element paragraphAlignLeft(const std::string& text);
94Element paragraphAlignRight(const std::string& text);
95Element paragraphAlignCenter(const std::string& text);
96Element paragraphAlignJustify(const std::string& text);
98Element emptyElement();
99Element canvas(ConstRef<Canvas>);
100Element canvas(int width, int height, std::function<void(Canvas&)>);
101Element canvas(std::function<void(Canvas&)>);
102
103// -- Decorator ---
104Element bold(Element);
105Element dim(Element);
106Element italic(Element);
107Element inverted(Element);
108Element underlined(Element);
109Element underlinedDouble(Element);
110Element blink(Element);
111Element strikethrough(Element);
112Decorator color(Color);
113Decorator bgcolor(Color);
114Decorator color(const LinearGradient&);
115Decorator bgcolor(const LinearGradient&);
116Element color(Color, Element);
117Element bgcolor(Color, Element);
118Element color(const LinearGradient&, Element);
119Element bgcolor(const LinearGradient&, Element);
120Decorator focusPosition(int x, int y);
121Decorator focusPositionRelative(float x, float y);
122Element automerge(Element child);
123Decorator hyperlink(std::string link);
124Element hyperlink(std::string link, Element child);
125Element selectionStyleReset(Element);
126Decorator selectionColor(Color foreground);
127Decorator selectionBackgroundColor(Color foreground);
128Decorator selectionForegroundColor(Color foreground);
129Decorator selectionStyle(std::function<void(Pixel&)> style);
130
131// --- Layout is
132// Horizontal, Vertical or stacked set of elements.
133Element hbox(Elements);
134Element vbox(Elements);
135Element dbox(Elements);
136Element flexbox(Elements, FlexboxConfig config = FlexboxConfig());
137Element gridbox(std::vector<Elements> lines);
138
139Element hflow(Elements); // Helper: default flexbox with row direction.
140Element vflow(Elements); // Helper: default flexbox with column direction.
141
142// -- Flexibility ---
143// Define how to share the remaining space when not all of it is used inside a
144// container.
145Element flex(Element); // Expand/Minimize if possible/needed.
146Element flex_grow(Element); // Expand element if possible.
147Element flex_shrink(Element); // Minimize element if needed.
148
149Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
150Element xflex_grow(Element); // Expand element if possible on X axis.
151Element xflex_shrink(Element); // Minimize element if needed on X axis.
152
153Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
154Element yflex_grow(Element); // Expand element if possible on Y axis.
155Element yflex_shrink(Element); // Minimize element if needed on Y axis.
156
157Element notflex(Element); // Reset the flex attribute.
158Element filler(); // A blank expandable element.
159
160// -- Size override;
163Decorator size(WidthOrHeight, Constraint, int value);
164
165// --- Frame ---
166// A frame is a scrollable area. The internal area is potentially larger than
167// the external one. The internal area is scrolled in order to make visible the
168// focused element.
169Element frame(Element);
170Element xframe(Element);
171Element yframe(Element);
172Element focus(Element);
173Element select(Element e); // Deprecated - Alias for focus.
174
175// --- Cursor ---
176// Those are similar to `focus`, but also change the shape of the cursor.
177Element focusCursorBlock(Element);
178Element focusCursorBlockBlinking(Element);
179Element focusCursorBar(Element);
180Element focusCursorBarBlinking(Element);
181Element focusCursorUnderline(Element);
182Element focusCursorUnderlineBlinking(Element);
183
184// --- Misc ---
185Element vscroll_indicator(Element);
186Element hscroll_indicator(Element);
187Decorator reflect(Box& box);
188// Before drawing the |element| clear the pixel below. This is useful in
189// combinaison with dbox.
190Element clear_under(Element element);
191
192// --- Util --------------------------------------------------------------------
193Element hcenter(Element);
194Element vcenter(Element);
195Element center(Element);
196Element align_right(Element);
197Element nothing(Element element);
198
199namespace Dimension {
200Dimensions Fit(Element&, bool extend_beyond_screen = false);
201} // namespace Dimension
202
203} // namespace ftxui
204
205// Make container able to take any number of children as input.
206#include "ftxui/dom/take_any_args.hpp"
207
208// Include old definitions using wstring.
210#endif // FTXUI_DOM_ELEMENTS_HPP
Direction
Direction is an enumeration that represents the four cardinal directions.
Definition direction.hpp:13
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
Definition elements.hpp:35
@ EMPTY
Definition elements.hpp:41
@ DOUBLE
Definition elements.hpp:39
@ HEAVY
Definition elements.hpp:38
@ ROUNDED
Definition elements.hpp:40
@ DASHED
Definition elements.hpp:37
@ LIGHT
Definition elements.hpp:36
Dimensions is a structure that represents the size of the terminal.
Definition terminal.hpp:11
Dimensions Fit(Element &, bool extend_beyond_screen=false)
Definition dom/util.cpp:93
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
WidthOrHeight
Definition elements.hpp:161
std::function< Element(Element)> Decorator
Definition elements.hpp:24
std::shared_ptr< Node > Element
Definition elements.hpp:22
std::vector< Element > Elements
Definition elements.hpp:23
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:25
@ LESS_THAN
Definition elements.hpp:162
@ GREATER_THAN
Definition elements.hpp:162
std::uint8_t left
Definition screen.cpp:129
std::uint8_t down
Definition screen.cpp:132
std::uint8_t right
Definition screen.cpp:131