FTXUI  4.1.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
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
11#include "ftxui/dom/node.hpp"
12#include "ftxui/screen/box.hpp"
16#include "ftxui/util/ref.hpp"
17
18namespace ftxui {
19class Node;
20using Element = std::shared_ptr<Node>;
21using Elements = std::vector<Element>;
22using Decorator = std::function<Element(Element)>;
23using GraphFunction = std::function<std::vector<int>(int, int)>;
24
33
34// Pipe elements into decorator togethers.
35// For instance the next lines are equivalents:
36// -> text("ftxui") | bold | underlined
37// -> underlined(bold(text("FTXUI")))
42
43// --- Widget ---
44Element text(std::string text);
45Element vtext(std::string text);
53Element separator(Pixel);
54Element separatorCharacter(std::string);
56 float right,
57 Color unselected_color,
58 Color selected_color);
60 float down,
61 Color unselected_color,
62 Color selected_color);
63Element gauge(float progress);
64Element gaugeLeft(float progress);
65Element gaugeRight(float progress);
66Element gaugeUp(float progress);
67Element gaugeDown(float progress);
68Element gaugeDirection(float progress, Direction direction);
79Decorator borderWith(const Pixel&);
80Element window(Element title, Element content);
81Element spinner(int charset_index, size_t image_index);
82Element paragraph(const std::string& text);
83Element paragraphAlignLeft(const std::string& text);
84Element paragraphAlignRight(const std::string& text);
85Element paragraphAlignCenter(const std::string& text);
86Element paragraphAlignJustify(const std::string& text);
89Element canvas(ConstRef<Canvas>);
90Element canvas(int width, int height, std::function<void(Canvas&)>);
91Element canvas(std::function<void(Canvas&)>);
92
93// -- Decorator ---
101Decorator color(Color);
102Decorator bgcolor(Color);
103Decorator color(const LinearGradient&);
104Decorator bgcolor(const LinearGradient&);
105Element color(Color, Element);
106Element bgcolor(Color, Element);
107Element color(const LinearGradient&, Element);
108Element bgcolor(const LinearGradient&, Element);
109Decorator focusPosition(int x, int y);
110Decorator focusPositionRelative(float x, float y);
112
113// --- Layout is
114// Horizontal, Vertical or stacked set of elements.
119Element gridbox(std::vector<Elements> lines);
120
121Element hflow(Elements); // Helper: default flexbox with row direction.
122Element vflow(Elements); // Helper: default flexbox with column direction.
123
124// -- Flexibility ---
125// Define how to share the remaining space when not all of it is used inside a
126// container.
127Element flex(Element); // Expand/Minimize if possible/needed.
128Element flex_grow(Element); // Expand element if possible.
129Element flex_shrink(Element); // Minimize element if needed.
130
131Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
132Element xflex_grow(Element); // Expand element if possible on X axis.
133Element xflex_shrink(Element); // Minimize element if needed on X axis.
134
135Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
136Element yflex_grow(Element); // Expand element if possible on Y axis.
137Element yflex_shrink(Element); // Minimize element if needed on Y axis.
138
139Element notflex(Element); // Reset the flex attribute.
140Element filler(); // A blank expandable element.
141
142// -- Size override;
146
147// --- Frame ---
148// A frame is a scrollable area. The internal area is potentially larger than
149// the external one. The internal area is scrolled in order to make visible the
150// focused element.
156
157// --- Cursor ---
158// Those are similar to `focus`, but also change the shape of the cursor.
165
166// --- Misc ---
168Decorator reflect(Box& box);
169// Before drawing the |element| clear the pixel below. This is useful in
170// combinaison with dbox.
172
173// --- Util --------------------------------------------------------------------
178Element nothing(Element element);
179
180namespace Dimension {
182} // namespace Dimension
183
184} // namespace ftxui
185
186// Make container able to take any number of children as input.
187#include "ftxui/dom/take_any_args.hpp"
188
189// Include old definitions using wstring.
191#endif // FTXUI_DOM_ELEMENTS_HPP
192
193// Copyright 2020 Arthur Sonzogni. All rights reserved.
194// Use of this source code is governed by the MIT license that can be found in
195// the LICENSE file.
Dimensions Fit(Element &)
Decorator bgcolor(Color)
Decorate using a background color.
Definition color.cpp:100
WidthOrHeight
Definition elements.hpp:143
Element borderDouble(Element)
Draw a double border around the element.
Definition border.cpp:400
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition flex.cpp:126
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
Definition gauge.cpp:163
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:28
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:144
std::function< Element(Element)> Decorator
Definition elements.hpp:22
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 light border around the element.
Definition border.cpp:295
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Element vscroll_indicator(Element)
Add a filter that will invert the foreground and the background 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:27
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition size.cpp:85
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
Definition flex.cpp:120
Element xframe(Element)
Definition frame.cpp:146
Element paragraphAlignRight(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Definition paragraph.cpp:42
std::shared_ptr< Node > Element
Definition elements.hpp:20
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Definition gauge.cpp:185
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.
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:280
Element borderRounded(Element)
Draw a rounded border around the element.
Definition border.cpp:435
Element emptyElement()
Definition util.cpp:131
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:132
Element window(Element title, Element content)
Draw window with a title and a border around the element.
Definition border.cpp:495
Element flex_shrink(Element)
Minimize if needed.
Definition flex.cpp:156
Element focusCursorBlock(Element)
Definition frame.cpp:171
Element hflow(Elements)
Element focusCursorUnderlineBlinking(Element)
Definition frame.cpp:191
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 focus(Element)
Definition frame.cpp:83
Element focusCursorBar(Element)
Definition frame.cpp:179
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:77
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
Definition canvas.cpp:848
Element underlined(Element)
Make the underlined element to be underlined.
Element center(Element)
Center an element horizontally and vertically.
std::vector< Element > Elements
Definition elements.hpp:21
Component operator|(Component component, ComponentDecorator decorator)
Definition util.cpp:9
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition border.cpp:365
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition inverted.cpp:29
Element paragraphAlignCenter(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Definition paragraph.cpp:52
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Definition gauge.cpp:236
Element focusCursorBlockBlinking(Element)
Definition frame.cpp:175
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:111
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:67
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition flex.cpp:150
Element flex_grow(Element)
Expand if possible.
Definition flex.cpp:138
Element separatorDashed()
Draw a vertical or horizontal separation in between two other elements, using the DASHED style.
Element yframe(Element)
Definition frame.cpp:150
Element notflex(Element)
Make the element not flexible.
Definition flex.cpp:174
Element strikethrough(Element)
Apply a strikethrough to text.
Element dbox(Elements)
Stack several element on top of each other.
Definition dbox.cpp:52
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition flex.cpp:162
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
Definition gauge.cpp:207
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Element vflow(Elements)
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition text.cpp:171
Element borderLight(Element)
Draw a dashed border around the element.
Definition border.cpp:330
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition paragraph.cpp:33
Decorator borderWith(const Pixel &)
Same as border but with a constant Pixel around the element.
Definition border.cpp:229
Decorator reflect(Box &box)
Definition reflect.cpp:39
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:23
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Definition border.cpp:238
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Definition gridbox.cpp:178
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element filler()
An element that will take expand proportionnally to the space left in a container.
Definition flex.cpp:95
Element focusCursorUnderline(Element)
Definition frame.cpp:187
Elements paragraph(std::wstring text)
Element dim(Element)
Use a light font, for elements with less emphasis.
Definition dim.cpp:28
Element automerge(Element child)
Enable character to be automatically merged with others nearby.
Definition automerge.cpp:14
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition frame.cpp:142
Element blink(Element)
The text drawn alternates in between visible and hidden.
Definition blink.cpp:28
Element vcenter(Element)
Center an element vertically.
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition util.cpp:19
@ LESS_THAN
Definition elements.hpp:144
@ GREATER_THAN
Definition elements.hpp:144
Element gauge(float progress)
Draw a high definition progress bar.
Definition gauge.cpp:287
Element paragraphAlignJustify(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Definition paragraph.cpp:63
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Definition graph.cpp:65
Element border(Element)
Draw a border around the element.
Definition border.cpp:222
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Element select(Element)
Definition frame.cpp:38
Element borderEmpty(Element)
Draw an empty border around the element.
Definition border.cpp:470
Element focusCursorBarBlinking(Element)
Definition frame.cpp:183
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:168
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:78
BorderStyle
Definition elements.hpp:25
@ EMPTY
Definition elements.hpp:31
@ DOUBLE
Definition elements.hpp:29
@ HEAVY
Definition elements.hpp:28
@ ROUNDED
Definition elements.hpp:30
@ DASHED
Definition elements.hpp:27
@ LIGHT
Definition elements.hpp:26
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
Definition gauge.cpp:265