FTXUI  6.0.2
C++ functional terminal UI.
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
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 ---
46Element text(std::string text);
47Element vtext(std::string text);
55Element separator(Pixel);
56Element separatorCharacter(std::string);
58 float right,
59 Color unselected_color,
60 Color selected_color);
62 float down,
63 Color unselected_color,
64 Color selected_color);
81Decorator borderWith(const Pixel&);
84Element paragraph(const std::string& text);
85Element paragraphAlignLeft(const std::string& text);
86Element paragraphAlignRight(const std::string& text);
87Element paragraphAlignCenter(const std::string& text);
88Element paragraphAlignJustify(const std::string& text);
92Element canvas(int width, int height, std::function<void(Canvas&)>);
93Element canvas(std::function<void(Canvas&)>);
94
95// -- Decorator ---
104Decorator color(Color);
105Decorator bgcolor(Color);
106Decorator color(const LinearGradient&);
107Decorator bgcolor(const LinearGradient&);
108Element color(Color, Element);
109Element bgcolor(Color, Element);
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);
118Decorator selectionColor(Color foreground);
119Decorator selectionBackgroundColor(Color foreground);
120Decorator selectionForegroundColor(Color foreground);
121Decorator selectionStyle(std::function<void(Pixel&)> style);
122
123// --- Layout is
124// Horizontal, Vertical or stacked set of elements.
129Element gridbox(std::vector<Elements> lines);
130
131Element hflow(Elements); // Helper: default flexbox with row direction.
132Element vflow(Elements); // Helper: default flexbox with column direction.
133
134// -- Flexibility ---
135// Define how to share the remaining space when not all of it is used inside a
136// container.
137Element flex(Element); // Expand/Minimize if possible/needed.
138Element flex_grow(Element); // Expand element if possible.
139Element flex_shrink(Element); // Minimize element if needed.
140
141Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
142Element xflex_grow(Element); // Expand element if possible on X axis.
143Element xflex_shrink(Element); // Minimize element if needed on X axis.
144
145Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
146Element yflex_grow(Element); // Expand element if possible on Y axis.
147Element yflex_shrink(Element); // Minimize element if needed on Y axis.
148
149Element notflex(Element); // Reset the flex attribute.
150Element filler(); // A blank expandable element.
151
152// -- Size override;
156
157// --- Frame ---
158// A frame is a scrollable area. The internal area is potentially larger than
159// the external one. The internal area is scrolled in order to make visible the
160// focused element.
165Element select(Element e); // Deprecated - Alias for focus.
166
167// --- Cursor ---
168// Those are similar to `focus`, but also change the shape of the cursor.
175
176// --- Misc ---
179Decorator reflect(Box& box);
180// Before drawing the |element| clear the pixel below. This is useful in
181// combinaison with dbox.
183
184// --- Util --------------------------------------------------------------------
189Element nothing(Element element);
190
191namespace Dimension {
193} // namespace Dimension
194
195} // namespace ftxui
196
197// Make container able to take any number of children as input.
198#include "ftxui/dom/take_any_args.hpp"
199
200// Include old definitions using wstring.
202#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:507
WidthOrHeight
Definition elements.hpp:153
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:189
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.
Element xflex_grow(Element)
Expand if possible on the X axis.
Definition flex.cpp:147
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.
Element borderDashed(Element)
Draw a dashed 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.
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.
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
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
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Definition flex.cpp:123
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:60
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
Element xframe(Element)
Same as frame, but only on the x-axis.
Definition frame.cpp:126
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:217
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.
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:440
Element emptyElement()
Definition util.cpp:140
Decorator selectionStyle(std::function< void(Pixel &)> style)
Set the style of an element when selected.
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:135
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:175
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.
Element focusCursorBlock(Element)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:147
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
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.
Element center(Element)
Center an element horizontally and vertically.
Decorator selectionForegroundColor(Color foreground)
Set the foreground color of an element when selected. Note that the style is applied on top of the ex...
Element focusCursorUnderline(Element)
Same as focus, but set the cursor shape to be a still underline.
Definition frame.cpp:203
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:72
Decorator selectionBackgroundColor(Color foreground)
Set the background color of an element when selected. Note that the style is applied on top of the ex...
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:160
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:69
std::vector< Element > Elements
Definition elements.hpp:23
Element yframe(Element)
Same as frame, but only on the y-axis.
Definition frame.cpp:134
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.
Element notflex(Element)
Make the element not flexible.
Definition flex.cpp:177
Element strikethrough(Element)
Apply a strikethrough to text.
Element italic(Element)
Apply a underlinedDouble to text.
Definition italic.cpp:17
Element dbox(Elements)
Stack several element on top of each other.
Definition dbox.cpp:108
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
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.
Element vflow(Elements)
Element select(Element e)
Set the child to be the one focused among its siblings.
Definition frame.cpp:108
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition text.cpp:220
Element borderLight(Element)
Draw a light border around the element.
Definition border.cpp:335
Element focus(Element)
Set the child to be the one focused among its siblings.
Definition frame.cpp:101
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition paragraph.cpp:49
Element selectionStyleReset(Element)
Reset the selection style of an element.
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:43
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:25
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:173
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element filler()
An element that will take expand proportionally 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:118
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.
Element focusCursorBlockBlinking(Element)
Same as focus, but set the cursor shape to be a blinking block.
Definition frame.cpp:161
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition util.cpp:22
@ LESS_THAN
Definition elements.hpp:154
@ GREATER_THAN
Definition elements.hpp:154
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:85
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.
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:96
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