FTXUI  0.11.1
C++ functional terminal UI.
elements.hpp
Go to the documentation of this file.
1 #ifndef FTXUI_DOM_ELEMENTS_HPP
2 #define FTXUI_DOM_ELEMENTS_HPP
3 
4 #include <functional>
5 #include <memory>
6 
8 #include "ftxui/dom/node.hpp"
9 #include "ftxui/screen/box.hpp"
10 #include "ftxui/screen/color.hpp"
11 #include "ftxui/screen/screen.hpp"
13 
14 namespace ftxui {
15 class Node;
16 using Element = std::shared_ptr<Node>;
17 using Elements = std::vector<Element>;
18 using Decorator = std::function<Element(Element)>;
19 using GraphFunction = std::function<std::vector<int>(int, int)>;
20 
22 
23 // Pipe elements into decorator togethers.
24 // For instance the next lines are equivalents:
25 // -> text("ftxui") | bold | underlined
26 // -> underlined(bold(text("FTXUI")))
30 
31 // --- Widget ---
32 Element text(std::string text);
33 Element vtext(std::string text);
34 Element separator(void);
40 Element separator(Pixel);
41 Element separatorCharacter(std::string);
42 Element gauge(float ratio);
50 Decorator borderWith(Pixel);
51 Element window(Element title, Element content);
52 Element spinner(int charset_index, size_t image_index);
53 Element paragraph(std::string text);
54 Element paragraphAlignLeft(std::string text);
55 Element paragraphAlignRight(std::string text);
56 Element paragraphAlignCenter(std::string text);
60 
61 // -- Decorator ---
71 Decorator focusPosition(int x, int y);
72 Decorator focusPositionRelative(float x, float y);
73 
74 // --- Layout is
75 // Horizontal, Vertical or stacked set of elements.
80 Element gridbox(std::vector<Elements> lines);
81 
82 Element hflow(Elements); // Helper: default flexbox with row direction.
83 Element vflow(Elements); // Helper: default flexbox with column direction.
84 
85 // -- Flexibility ---
86 // Define how to share the remaining space when not all of it is used inside a
87 // container.
88 Element flex(Element); // Expand/Minimize if possible/needed.
89 Element flex_grow(Element); // Expand element if possible.
90 Element flex_shrink(Element); // Minimize element if needed.
91 
92 Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
93 Element xflex_grow(Element); // Expand element if possible on X axis.
94 Element xflex_shrink(Element); // Minimize element if needed on X axis.
95 
96 Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
97 Element yflex_grow(Element); // Expand element if possible on Y axis.
98 Element yflex_shrink(Element); // Minimize element if needed on Y axis.
99 
100 Element notflex(Element); // Reset the flex attribute.
101 Element filler(); // A blank expandable element.
102 
103 // -- Size override;
106 Decorator size(Direction, Constraint, int value);
107 
108 // --
109 Decorator reflect(Box& box);
110 
111 // --- Frame ---
112 // A frame is a scrollable area. The internal area is potentially larger than
113 // the external one. The internal area is scrolled in order to make visible the
114 // focused element.
120 
122 
123 // --- Util --------------------------------------------------------------------
128 Element nothing(Element element);
129 
130 // Before drawing the |element| clear the pixel below. This is useful in
131 // combinaison with dbox.
132 Element clear_under(Element element);
133 
134 namespace Dimension {
136 } // namespace Dimension
137 
138 } // namespace ftxui
139 
140 // Make container able to take any number of children as input.
141 #include "ftxui/dom/take_any_args.hpp"
142 
143 // Include old definitions using wstring.
144 #include "ftxui/dom/deprecated.hpp"
145 #endif /* end of include guard: FTXUI_DOM_ELEMENTS_HPP */
146 
147 // Copyright 2020 Arthur Sonzogni. All rights reserved.
148 // Use of this source code is governed by the MIT license that can be found in
149 // the LICENSE file.
Dimensions Fit(Element &)
Definition: util.cpp:72
Decorator bgcolor(Color)
Decorate using a background color.
Definition: color.cpp:100
Element vflow(Elements)
Element paragraphAlignCenter(std::string text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Definition: paragraph.cpp:51
Element borderDouble(Element)
Draw a double border around the element.
Definition: border.cpp:270
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition: flex.cpp:125
Decorator focusPositionRelative(float x, float y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Definition: focus.cpp:33
Element separatorStyled(BorderStyle)
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:151
Element xflex_grow(Element)
Expand if possible on the X axis.
Definition: flex.cpp:143
std::function< Element(Element)> Decorator
Definition: elements.hpp:18
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Definition: separator.cpp:295
Element vscroll_indicator(Element)
Add a filter that will invert the foreground and the background colors.
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition: util.cpp:26
@ HEIGHT
Definition: elements.hpp:104
@ WIDTH
Definition: elements.hpp:104
Element clear_under(Element element)
Before drawing |child|, clear the pixels below. This is useful in.
Definition: clear_under.cpp:32
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
Definition: flex.cpp:119
Element xframe(Element)
Definition: frame.cpp:142
std::shared_ptr< Node > Element
Definition: elements.hpp:16
Decorator borderWith(Pixel)
Same as border but with a constant Pixel around the element.
Definition: border.cpp:157
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition: bold.cpp:28
Element separatorLight()
Draw a vertical or horizontal separation in between two other elements, using the LIGHT style.
Definition: separator.cpp:187
Element spinner(int charset_index, size_t image_index)
Useful to represent the effect of time and/or events. This display an ASCII art "video".
Definition: spinner.cpp:255
Element borderRounded(Element)
Draw a rounded border around the element.
Definition: border.cpp:304
Element emptyElement()
Definition: util.cpp:110
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition: flex.cpp:131
Element window(Element title, Element content)
Draw window with a title and a border around the element.
Definition: border.cpp:363
Element flex_shrink(Element)
Minimize if needed.
Definition: flex.cpp:155
Element paragraphAlignJustify(std::string text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Definition: paragraph.cpp:62
Element paragraphAlignRight(std::string text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Definition: paragraph.cpp:41
Element focus(Element)
Definition: frame.cpp:79
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition: hbox.cpp:76
Element underlined(Element)
Make the underlined element to be underlined.
Definition: underlined.cpp:28
Element center(Element)
Center an element horizontally and vertically.
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition: border.cpp:236
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition: inverted.cpp:29
Elements paragraph(std::wstring text)
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:106
Element align_right(Element)
Align an element on the right side.
Decorator focusPosition(int x, int y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Definition: focus.cpp:72
std::vector< Element > Elements
Definition: elements.hpp:17
Element operator|(Element, Decorator)
From an element, apply a decorator.
Definition: util.cpp:65
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition: flex.cpp:149
Element flex_grow(Element)
Expand if possible.
Definition: flex.cpp:137
Element yframe(Element)
Definition: frame.cpp:146
Element notflex(Element)
Make the element not flexible.
Definition: flex.cpp:173
Element dbox(Elements)
Stack several element on top of each other.
Definition: dbox.cpp:50
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition: flex.cpp:161
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:332
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition: text.cpp:166
Element borderLight(Element)
Draw a light border around the element.
Definition: border.cpp:202
Decorator reflect(Box &box)
Definition: reflect.cpp:39
std::function< std::vector< int >(int, int)> GraphFunction
Definition: elements.hpp:19
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Definition: border.cpp:166
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Definition: gridbox.cpp:154
Element separator(void)
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:114
Element filler()
An element that will take expand proportionnally to the space left in a container.
Definition: flex.cpp:94
Element dim(Element)
Use a light font, for elements with less emphasis.
Definition: dim.cpp:28
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition: frame.cpp:138
Element blink(Element)
The text drawn alternates in between visible and hidden.
Definition: blink.cpp:28
Element vcenter(Element)
Center an element vertically.
Decorator size(Direction, Constraint, int value)
Apply a constraint on the size of an element.
Definition: size.cpp:86
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
Definition: separator.cpp:259
Element hflow(Elements)
Element paragraphAlignLeft(std::string text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition: paragraph.cpp:32
Constraint
Definition: elements.hpp:105
@ LESS_THAN
Definition: elements.hpp:105
@ EQUAL
Definition: elements.hpp:105
@ GREATER_THAN
Definition: elements.hpp:105
Element gauge(float ratio)
Draw a high definition progress bar.
Definition: gauge.cpp:75
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Definition: graph.cpp:59
Element border(Element)
Draw a border around the element.
Definition: border.cpp:150
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Definition: separator.cpp:223
Element select(Element)
Definition: frame.cpp:38
Element borderEmpty(Element)
Draw an empty border around the element.
Definition: border.cpp:338
Decorator color(Color)
Decorate using a foreground color.
Definition: color.cpp:86
Element yflex_shrink(Element)
Minimize if needed on the Y axis.
Definition: flex.cpp:167
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition: vbox.cpp:77
BorderStyle
Definition: elements.hpp:21
@ EMPTY
Definition: elements.hpp:21
@ DOUBLE
Definition: elements.hpp:21
@ HEAVY
Definition: elements.hpp:21
@ ROUNDED
Definition: elements.hpp:21
@ LIGHT
Definition: elements.hpp:21