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"
14#include "ftxui/dom/node.hpp"
15#include "ftxui/screen/box.hpp"
19#include "ftxui/util/ref.hpp"
20
21namespace ftxui {
22class Node;
23using Element = std::shared_ptr<Node>;
24using Elements = std::vector<Element>;
25using Decorator = std::function<Element(Element)>;
26using GraphFunction = std::function<std::vector<int>(int, int)>;
27
35};
36
37// Pipe elements into decorator togethers.
38// For instance the next lines are equivalents:
39// -> text("ftxui") | bold | underlined
40// -> underlined(bold(text("FTXUI")))
45
46// --- Widget ---
47Element text(std::string text);
48Element vtext(std::string text);
56Element separator(Pixel);
57Element separatorCharacter(std::string);
59 float right,
60 Color unselected_color,
61 Color selected_color);
63 float down,
64 Color unselected_color,
65 Color selected_color);
66Element gauge(float progress);
67Element gaugeLeft(float progress);
68Element gaugeRight(float progress);
69Element gaugeUp(float progress);
70Element gaugeDown(float progress);
71Element gaugeDirection(float progress, Direction direction);
82Decorator borderWith(const Pixel&);
83Element window(Element title, Element content);
84Element spinner(int charset_index, size_t image_index);
85Element paragraph(const std::string& text);
86Element paragraphAlignLeft(const std::string& text);
87Element paragraphAlignRight(const std::string& text);
88Element paragraphAlignCenter(const std::string& text);
89Element paragraphAlignJustify(const std::string& text);
92Element canvas(ConstRef<Canvas>);
93Element canvas(int width, int height, std::function<void(Canvas&)>);
94Element canvas(std::function<void(Canvas&)>);
95
96// -- Decorator ---
106Decorator color(const LinearGradient&);
107Decorator bgcolor(const LinearGradient&);
110Element color(const LinearGradient&, Element);
111Element bgcolor(const LinearGradient&, Element);
112Decorator focusPosition(int x, int y);
113Decorator focusPositionRelative(float x, float y);
115Decorator hyperlink(std::string link);
116Element hyperlink(std::string link, Element child);
117
118// --- Layout is
119// Horizontal, Vertical or stacked set of elements.
124Element gridbox(std::vector<Elements> lines);
125
126Element hflow(Elements); // Helper: default flexbox with row direction.
127Element vflow(Elements); // Helper: default flexbox with column direction.
128
129// -- Flexibility ---
130// Define how to share the remaining space when not all of it is used inside a
131// container.
132Element flex(Element); // Expand/Minimize if possible/needed.
133Element flex_grow(Element); // Expand element if possible.
134Element flex_shrink(Element); // Minimize element if needed.
135
136Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
137Element xflex_grow(Element); // Expand element if possible on X axis.
138Element xflex_shrink(Element); // Minimize element if needed on X axis.
139
140Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
141Element yflex_grow(Element); // Expand element if possible on Y axis.
142Element yflex_shrink(Element); // Minimize element if needed on Y axis.
143
144Element notflex(Element); // Reset the flex attribute.
145Element filler(); // A blank expandable element.
146
147// -- Size override;
151
152// --- Frame ---
153// A frame is a scrollable area. The internal area is potentially larger than
154// the external one. The internal area is scrolled in order to make visible the
155// focused element.
161
162// --- Cursor ---
163// Those are similar to `focus`, but also change the shape of the cursor.
170
171// --- Misc ---
174Decorator reflect(Box& box);
175// Before drawing the |element| clear the pixel below. This is useful in
176// combinaison with dbox.
178
179// --- Util --------------------------------------------------------------------
184Element nothing(Element element);
185
186namespace Dimension {
188} // namespace Dimension
189
190} // namespace ftxui
191
192// Make container able to take any number of children as input.
193#include "ftxui/dom/take_any_args.hpp"
194
195// Include old definitions using wstring.
197#endif // FTXUI_DOM_ELEMENTS_HPP
Dimensions Fit(Element &)
Definition: util.cpp:95
Decorator bgcolor(Color)
Decorate using a background color.
Definition: color.cpp:124
WidthOrHeight
Definition: elements.hpp:148
@ HEIGHT
Definition: elements.hpp:148
@ WIDTH
Definition: elements.hpp:148
Element borderDouble(Element)
Draw a double border around the element.
Definition: border.cpp:405
Element focusCursorBarBlinking(Element)
Same as focus, but set the cursor shape to be a blinking bar.
Definition: frame.cpp:238
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition: flex.cpp:129
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:170
Element xflex_grow(Element)
Expand if possible on the X axis.
Definition: flex.cpp:147
std::function< Element(Element)> Decorator
Definition: elements.hpp:25
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:37
Element borderDashed(Element)
Draw a light border around the element.
Definition: border.cpp:300
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Definition: separator.cpp:355
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:510
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition: util.cpp:30
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition: size.cpp:90
Direction
Definition: direction.hpp:8
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
Definition: flex.cpp:123
std::shared_ptr< Node > Element
Definition: elements.hpp:23
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:175
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:266
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:207
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:283
Element borderRounded(Element)
Draw a rounded border around the element.
Definition: border.cpp:440
Element emptyElement()
Definition: util.cpp:135
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition: flex.cpp:135
Element window(Element title, Element content)
Draw window with a title and a border around the element.
Definition: border.cpp:500
Element flex_shrink(Element)
Minimize if needed.
Definition: flex.cpp:159
Element hflow(Elements)
Element focusCursorBar(Element)
Same as focus, but set the cursor shape to be a still block.
Definition: frame.cpp:224
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:440
Element focusCursorBlock(Element)
Same as focus, but set the cursor shape to be a still block.
Definition: frame.cpp:196
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:852
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:252
Component operator|(Component component, ComponentDecorator decorator)
Definition: util.cpp:12
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition: border.cpp:370
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition: inverted.cpp:34
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:120
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:24
Element yframe(Element)
Same as frame, but only on the y-axis.
Definition: frame.cpp:183
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition: flex.cpp:153
Element hscroll_indicator(Element)
Display an horizontal scrollbar to the bottom. colors.
Element flex_grow(Element)
Expand if possible.
Definition: flex.cpp:141
Element separatorDashed()
Draw a vertical or horizontal separation in between two other elements, using the DASHED style.
Definition: separator.cpp:244
Element notflex(Element)
Make the element not flexible.
Definition: flex.cpp:177
Element strikethrough(Element)
Apply a strikethrough to text.
Element dbox(Elements)
Stack several element on top of each other.
Definition: dbox.cpp:108
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition: flex.cpp:165
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:393
Element vflow(Elements)
Element select(Element)
Set the child to be the one selected among its siblings.
Definition: frame.cpp:150
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition: text.cpp:180
Element borderLight(Element)
Draw a dashed border around the element.
Definition: border.cpp:335
Element focus(Element)
Set the child to be the one in focus globally.
Definition: frame.cpp:157
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:234
Decorator reflect(Box &box)
Definition: reflect.cpp:44
std::function< std::vector< int >(int, int)> GraphFunction
Definition: elements.hpp:26
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Definition: border.cpp:243
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:132
Element filler()
An element that will take expand proportionnally to the space left in a container.
Definition: flex.cpp:98
Elements paragraph(std::wstring text)
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:167
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:318
Element focusCursorBlockBlinking(Element)
Same as focus, but set the cursor shape to be a blinking block.
Definition: frame.cpp:210
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition: util.cpp:22
Constraint
Definition: elements.hpp:149
@ LESS_THAN
Definition: elements.hpp:149
@ EQUAL
Definition: elements.hpp:149
@ GREATER_THAN
Definition: elements.hpp:149
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:227
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Definition: separator.cpp:281
Element borderEmpty(Element)
Draw an empty border around the element.
Definition: border.cpp:475
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:171
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:28
@ EMPTY
Definition: elements.hpp:34
@ DOUBLE
Definition: elements.hpp:32
@ HEAVY
Definition: elements.hpp:31
@ ROUNDED
Definition: elements.hpp:33
@ DASHED
Definition: elements.hpp:30
@ LIGHT
Definition: elements.hpp:29
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
Definition: gauge.cpp:271