FTXUI  5.0.0
C++ functional terminal UI.
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"
11 #include "ftxui/dom/direction.hpp"
14 #include "ftxui/dom/node.hpp"
15 #include "ftxui/screen/box.hpp"
16 #include "ftxui/screen/color.hpp"
18 #include "ftxui/util/ref.hpp"
19 
20 namespace ftxui {
21 class Node;
22 using Element = std::shared_ptr<Node>;
23 using Elements = std::vector<Element>;
24 using Decorator = std::function<Element(Element)>;
25 using GraphFunction = std::function<std::vector<int>(int, int)>;
26 
34 };
35 
36 // Pipe elements into decorator togethers.
37 // For instance the next lines are equivalents:
38 // -> text("ftxui") | bold | underlined
39 // -> underlined(bold(text("FTXUI")))
44 
45 // --- Widget ---
46 Element text(std::string text);
47 Element vtext(std::string text);
55 Element separator(Pixel);
56 Element separatorCharacter(std::string);
57 Element separatorHSelector(float left,
58  float right,
59  Color unselected_color,
60  Color selected_color);
62  float down,
63  Color unselected_color,
64  Color selected_color);
65 Element gauge(float progress);
66 Element gaugeLeft(float progress);
67 Element gaugeRight(float progress);
68 Element gaugeUp(float progress);
69 Element gaugeDown(float progress);
70 Element gaugeDirection(float progress, Direction direction);
81 Decorator borderWith(const Pixel&);
83 Element spinner(int charset_index, size_t image_index);
84 Element paragraph(const std::string& text);
85 Element paragraphAlignLeft(const std::string& text);
86 Element paragraphAlignRight(const std::string& text);
87 Element paragraphAlignCenter(const std::string& text);
88 Element paragraphAlignJustify(const std::string& text);
91 Element canvas(ConstRef<Canvas>);
92 Element canvas(int width, int height, std::function<void(Canvas&)>);
93 Element canvas(std::function<void(Canvas&)>);
94 
95 // -- Decorator ---
105 Decorator color(const LinearGradient&);
106 Decorator bgcolor(const LinearGradient&);
109 Element color(const LinearGradient&, Element);
110 Element bgcolor(const LinearGradient&, Element);
111 Decorator focusPosition(int x, int y);
112 Decorator focusPositionRelative(float x, float y);
113 Element automerge(Element child);
114 Decorator hyperlink(std::string link);
115 Element hyperlink(std::string link, Element child);
116 
117 // --- Layout is
118 // Horizontal, Vertical or stacked set of elements.
123 Element gridbox(std::vector<Elements> lines);
124 
125 Element hflow(Elements); // Helper: default flexbox with row direction.
126 Element vflow(Elements); // Helper: default flexbox with column direction.
127 
128 // -- Flexibility ---
129 // Define how to share the remaining space when not all of it is used inside a
130 // container.
131 Element flex(Element); // Expand/Minimize if possible/needed.
132 Element flex_grow(Element); // Expand element if possible.
133 Element flex_shrink(Element); // Minimize element if needed.
134 
135 Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
136 Element xflex_grow(Element); // Expand element if possible on X axis.
137 Element xflex_shrink(Element); // Minimize element if needed on X axis.
138 
139 Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
140 Element yflex_grow(Element); // Expand element if possible on Y axis.
141 Element yflex_shrink(Element); // Minimize element if needed on Y axis.
142 
143 Element notflex(Element); // Reset the flex attribute.
144 Element filler(); // A blank expandable element.
145 
146 // -- Size override;
150 
151 // --- Frame ---
152 // A frame is a scrollable area. The internal area is potentially larger than
153 // the external one. The internal area is scrolled in order to make visible the
154 // focused element.
160 
161 // --- Cursor ---
162 // Those are similar to `focus`, but also change the shape of the cursor.
169 
170 // --- Misc ---
173 Decorator reflect(Box& box);
174 // Before drawing the |element| clear the pixel below. This is useful in
175 // combinaison with dbox.
176 Element clear_under(Element element);
177 
178 // --- Util --------------------------------------------------------------------
183 Element nothing(Element element);
184 
185 namespace Dimension {
186 Dimensions Fit(Element&, bool extend_beyond_screen = false);
187 } // namespace Dimension
188 
189 } // namespace ftxui
190 
191 // Make container able to take any number of children as input.
192 #include "ftxui/dom/take_any_args.hpp"
193 
194 // Include old definitions using wstring.
195 #include "ftxui/dom/deprecated.hpp"
196 #endif // FTXUI_DOM_ELEMENTS_HPP
Dimensions Fit(Element &, bool extend_beyond_screen=false)
Definition: util.cpp:93
Decorator bgcolor(Color)
Decorate using a background color.
Definition: color.cpp:124
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Definition: border.cpp:508
Element vflow(Elements)
WidthOrHeight
Definition: elements.hpp:147
@ HEIGHT
Definition: elements.hpp:147
@ WIDTH
Definition: elements.hpp:147
Element borderDouble(Element)
Draw a double border around the element.
Definition: border.cpp:406
Element focusCursorBarBlinking(Element)
Same as focus, but set the cursor shape to be a blinking bar.
Definition: frame.cpp:237
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition: flex.cpp:128
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
Definition: gauge.cpp:169
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:31
Element separatorStyled(BorderStyle)
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:172
Element xflex_grow(Element)
Expand if possible on the X axis.
Definition: flex.cpp:146
std::function< Element(Element)> Decorator
Definition: elements.hpp:24
Element underlinedDouble(Element)
Apply a underlinedDouble to text.
Element clear_under(Element element)
Before drawing |child|, clear the pixels below. This is useful in.
Definition: clear_under.cpp:38
Element borderDashed(Element)
Draw a dashed border around the element.
Definition: border.cpp:301
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Definition: separator.cpp:357
Element vscroll_indicator(Element)
Display a vertical scrollbar to the right. colors.
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Draw an vertical bar, with the area in between up/downcolored differently.
Definition: separator.cpp:512
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition: util.cpp:28
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition: size.cpp:89
Direction
Definition: direction.hpp:8
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Definition: flex.cpp:122
std::shared_ptr< Node > Element
Definition: elements.hpp:22
Element paragraphAlignRight(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Definition: paragraph.cpp:45
Element xframe(Element)
Same as frame, but only on the x-axis.
Definition: frame.cpp:174
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Definition: gauge.cpp:191
Element focusCursorUnderlineBlinking(Element)
Same as focus, but set the cursor shape to be a blinking underline.
Definition: frame.cpp:265
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition: bold.cpp:33
Element separatorLight()
Draw a vertical or horizontal separation in between two other elements, using the LIGHT style.
Definition: separator.cpp:209
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:282
Element borderRounded(Element)
Draw a rounded border around the element.
Definition: border.cpp:441
Element emptyElement()
Definition: util.cpp:140
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition: flex.cpp:134
Element flex_shrink(Element)
Minimize if needed.
Definition: flex.cpp:158
Element focusCursorBar(Element)
Same as focus, but set the cursor shape to be a still block.
Definition: frame.cpp:223
Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Draw an horizontal bar, with the area in between left/right colored differently.
Definition: separator.cpp:442
Element focusCursorBlock(Element)
Same as focus, but set the cursor shape to be a still block.
Definition: frame.cpp:195
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition: hbox.cpp:83
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
Definition: canvas.cpp:891
Element underlined(Element)
Make the underlined element to be underlined.
Definition: underlined.cpp:33
Element center(Element)
Center an element horizontally and vertically.
Element focusCursorUnderline(Element)
Same as focus, but set the cursor shape to be a still underline.
Definition: frame.cpp:251
Component operator|(Component component, ComponentDecorator decorator)
Definition: util.cpp:12
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition: border.cpp:371
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition: inverted.cpp:34
Elements paragraph(std::wstring text)
Element paragraphAlignCenter(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Definition: paragraph.cpp:55
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Definition: gauge.cpp:242
Element text(std::wstring text)
Display a piece of unicode text.
Definition: text.cpp:119
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:70
std::vector< Element > Elements
Definition: elements.hpp:23
Element yframe(Element)
Same as frame, but only on the y-axis.
Definition: frame.cpp:182
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition: flex.cpp:152
Element hscroll_indicator(Element)
Display an horizontal scrollbar to the bottom. colors.
Element flex_grow(Element)
Expand if possible.
Definition: flex.cpp:140
Element separatorDashed()
Draw a vertical or horizontal separation in between two other elements, using the DASHED style.
Definition: separator.cpp:246
Element notflex(Element)
Make the element not flexible.
Definition: flex.cpp:176
Element strikethrough(Element)
Apply a strikethrough to text.
Element dbox(Elements)
Stack several element on top of each other.
Definition: dbox.cpp:111
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition: flex.cpp:164
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
Definition: gauge.cpp:213
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:395
Element select(Element)
Set the child to be the one selected among its siblings.
Definition: frame.cpp:149
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition: text.cpp:179
Element borderLight(Element)
Draw a light border around the element.
Definition: border.cpp:336
Element focus(Element)
Set the child to be the one in focus globally.
Definition: frame.cpp:156
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition: paragraph.cpp:36
Decorator borderWith(const Pixel &)
Same as border but with a constant Pixel around the element.
Definition: border.cpp:235
Decorator reflect(Box &box)
Definition: reflect.cpp:43
std::function< std::vector< int >(int, int)> GraphFunction
Definition: elements.hpp:25
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Definition: border.cpp:244
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Definition: gridbox.cpp:183
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Definition: separator.cpp:134
Element filler()
An element that will take expand proportionally to the space left in a container.
Definition: flex.cpp:97
Element dim(Element)
Use a light font, for elements with less emphasis.
Definition: dim.cpp:33
Element automerge(Element child)
Enable character to be automatically merged with others nearby.
Definition: automerge.cpp:17
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition: frame.cpp:166
Decorator hyperlink(std::string link)
Decorate using an hyperlink. The link will be opened when the user click on it. This is supported onl...
Definition: hyperlink.cpp:70
Element blink(Element)
The text drawn alternates in between visible and hidden.
Definition: blink.cpp:33
Element vcenter(Element)
Center an element vertically.
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
Definition: separator.cpp:320
Element focusCursorBlockBlinking(Element)
Same as focus, but set the cursor shape to be a blinking block.
Definition: frame.cpp:209
Element hflow(Elements)
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition: util.cpp:22
Constraint
Definition: elements.hpp:148
@ LESS_THAN
Definition: elements.hpp:148
@ EQUAL
Definition: elements.hpp:148
@ GREATER_THAN
Definition: elements.hpp:148
Element gauge(float progress)
Draw a high definition progress bar.
Definition: gauge.cpp:293
Element paragraphAlignJustify(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Definition: paragraph.cpp:66
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Definition: graph.cpp:71
Element border(Element)
Draw a border around the element.
Definition: border.cpp:228
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Definition: separator.cpp:283
Element borderEmpty(Element)
Draw an empty border around the element.
Definition: border.cpp:476
Decorator color(Color)
Decorate using a foreground color.
Definition: color.cpp:110
Element yflex_shrink(Element)
Minimize if needed on the Y axis.
Definition: flex.cpp:170
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition: vbox.cpp:83
BorderStyle
Definition: elements.hpp:27
@ EMPTY
Definition: elements.hpp:33
@ DOUBLE
Definition: elements.hpp:31
@ HEAVY
Definition: elements.hpp:30
@ ROUNDED
Definition: elements.hpp:32
@ DASHED
Definition: elements.hpp:29
@ LIGHT
Definition: elements.hpp:28
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
Definition: gauge.cpp:271