FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
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 <string_view>
11#include "ftxui/dom/canvas.hpp"
15#include "ftxui/dom/node.hpp"
16#include "ftxui/screen/box.hpp"
19#include "ftxui/util/export.hpp"
20#include "ftxui/util/ref.hpp"
21
22namespace ftxui {
23class Node;
24using Element = std::shared_ptr<Node>;
25using Elements = std::vector<Element>;
26using Decorator = std::function<Element(Element)>;
27using GraphFunction = std::function<std::vector<int>(int, int)>;
28
29/// @brief BorderStyle is an enumeration that represents the different styles
30/// of borders that can be applied to elements in the terminal UI.
31///
32/// BorderStyle is an enumeration that represents the different styles of
33/// borders that can be applied to elements in the terminal UI.
34/// It is used to define the visual appearance of borders around elements,
35/// such as windows, frames, or separators.
36/// @ingroup dom
45
46// Pipe elements into decorator together.
47// For instance the next lines are equivalents:
48// -> text("ftxui") | bold | underlined
49// -> underlined(bold(text("FTXUI")))
54
55// --- Widget ---
56FTXUI_EXPORT(DOM) Element text(std::string_view text);
57FTXUI_EXPORT(DOM) Element vtext(std::string_view text);
66FTXUI_EXPORT(DOM) Element separatorCharacter(std::string_view);
67FTXUI_EXPORT(DOM)
69 float right,
70 Color unselected_color,
71 Color selected_color);
72FTXUI_EXPORT(DOM)
74 float down,
75 Color unselected_color,
76 Color selected_color);
77FTXUI_EXPORT(DOM) Element gauge(float progress);
78FTXUI_EXPORT(DOM) Element gaugeLeft(float progress);
79FTXUI_EXPORT(DOM) Element gaugeRight(float progress);
80FTXUI_EXPORT(DOM) Element gaugeUp(float progress);
81FTXUI_EXPORT(DOM) Element gaugeDown(float progress);
93FTXUI_EXPORT(DOM) Decorator borderWith(const Cell&);
94FTXUI_EXPORT(DOM)
95Element window(Element title, Element content, BorderStyle border = ROUNDED);
96FTXUI_EXPORT(DOM) Element spinner(int charset_index, size_t image_index);
97FTXUI_EXPORT(DOM) Element paragraph(std::string_view text);
98FTXUI_EXPORT(DOM) Element paragraphAlignLeft(std::string_view text);
99FTXUI_EXPORT(DOM) Element paragraphAlignRight(std::string_view text);
100FTXUI_EXPORT(DOM) Element paragraphAlignCenter(std::string_view text);
101FTXUI_EXPORT(DOM) Element paragraphAlignJustify(std::string_view text);
105FTXUI_EXPORT(DOM)
106Element canvas(int width, int height, std::function<void(Canvas&)>);
107FTXUI_EXPORT(DOM) Element canvas(std::function<void(Canvas&)>);
108
109// -- Decorator ---
118FTXUI_EXPORT(DOM) Decorator color(Color);
119FTXUI_EXPORT(DOM) Decorator bgcolor(Color);
120FTXUI_EXPORT(DOM) Decorator color(const LinearGradient&);
121FTXUI_EXPORT(DOM) Decorator bgcolor(const LinearGradient&);
122FTXUI_EXPORT(DOM) Element color(Color, Element);
124FTXUI_EXPORT(DOM) Element color(const LinearGradient&, Element);
125FTXUI_EXPORT(DOM) Element bgcolor(const LinearGradient&, Element);
127FTXUI_EXPORT(DOM) Decorator focusPositionRelative(float x, float y);
129FTXUI_EXPORT(DOM) Decorator hyperlink(std::string_view link);
130FTXUI_EXPORT(DOM) Element hyperlink(std::string_view link, Element child);
132FTXUI_EXPORT(DOM) Decorator selectionColor(Color foreground);
133FTXUI_EXPORT(DOM) Decorator selectionBackgroundColor(Color foreground);
134FTXUI_EXPORT(DOM) Decorator selectionForegroundColor(Color foreground);
135FTXUI_EXPORT(DOM) Decorator selectionStyle(std::function<void(Cell&)> style);
136
137// --- Layout is
138// Horizontal, Vertical or stacked set of elements.
142FTXUI_EXPORT(DOM)
143Element flexbox(Elements, FlexboxConfig config = FlexboxConfig());
144FTXUI_EXPORT(DOM) Element gridbox(std::vector<Elements> lines);
145
146FTXUI_EXPORT(DOM)
147Element hflow(Elements); // Helper: default flexbox with row direction.
148FTXUI_EXPORT(DOM)
149Element vflow(Elements); // Helper: default flexbox with column direction.
150
151// -- Flexibility ---
152// Define how to share the remaining space when not all of it is used inside a
153// container.
154FTXUI_EXPORT(DOM) Element flex(Element); // Expand/Minimize if possible/needed.
155FTXUI_EXPORT(DOM) Element flex_grow(Element); // Expand element if possible.
156FTXUI_EXPORT(DOM) Element flex_shrink(Element); // Minimize element if needed.
157
158FTXUI_EXPORT(DOM)
159Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
160FTXUI_EXPORT(DOM)
161Element xflex_grow(Element); // Expand element if possible on X axis.
162FTXUI_EXPORT(DOM)
163Element xflex_shrink(Element); // Minimize element if needed on X axis.
164
165FTXUI_EXPORT(DOM)
166Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
167FTXUI_EXPORT(DOM)
168Element yflex_grow(Element); // Expand element if possible on Y axis.
169FTXUI_EXPORT(DOM)
170Element yflex_shrink(Element); // Minimize element if needed on Y axis.
171
172FTXUI_EXPORT(DOM) Element notflex(Element); // Reset the flex attribute.
173FTXUI_EXPORT(DOM) Element filler(); // A blank expandable element.
174
175// -- Size override;
179
180// --- Frame ---
181// A frame is a scrollable area. The internal area is potentially larger than
182// the external one. The internal area is scrolled in order to make visible the
183// focused element.
188FTXUI_EXPORT(DOM) Element select(Element e); // Deprecated - Alias for focus.
189
190// --- Cursor ---
191// Those are similar to `focus`, but also change the shape of the cursor.
198
199// --- Misc ---
202FTXUI_EXPORT(DOM) Decorator reflect(Box& box);
203// Before drawing the |element| clear the pixel below. This is useful in
204// combination with dbox.
206
207// --- Util --------------------------------------------------------------------
213
214namespace Dimension {
215FTXUI_EXPORT(DOM) Dimensions Fit(Element&, bool extend_beyond_screen = false);
216} // namespace Dimension
217
218} // namespace ftxui
219
220// Make container able to take any number of children as input.
221#include "ftxui/dom/take_any_args.hpp"
222
223// Include old definitions using wstring.
225#endif // FTXUI_DOM_ELEMENTS_HPP
An adapter. Own or reference an immutable object.
Definition ref.hpp:20
#define FTXUI_EXPORT(component)
Definition export.hpp:24
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Element borderDouble(Element child)
Draw a double border around the element.
Element text(std::string_view text)
Display a piece of UTF8 encoded unicode text.
Element focusCursorBarBlinking(Element child)
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.
Decorator focusPositionRelative(float x, float y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Element separatorStyled(BorderStyle style)
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
Element underlinedDouble(Element child)
Apply a underlinedDouble to text.
Element clear_under(Element element)
Before drawing |child|, clear the cells below. This is useful in combination with dbox.
Element borderDashed(Element child)
Draw a dashed border around the element.
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Element vscroll_indicator(Element child)
Display a vertical scrollbar on the right. Colors follow the content.
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition dom/util.cpp:28
Element paragraphAlignLeft(std::string_view the_text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Decorator size(WidthOrHeight direction, Constraint constraint, int value)
Apply a constraint on the size of an element.
Direction
Direction is an enumeration that represents the four cardinal directions.
Definition direction.hpp:13
Element flex(Element child)
Make a child element to expand proportionally to the space left in a container.
Definition flex.cpp:123
Element hyperlink(std::string_view link, Element child)
Make the rendered area clickable using a web browser. The link will be opened when the user clicks on...
Definition hyperlink.cpp:52
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Element focusCursorUnderlineBlinking(Element child)
Same as focus, but set the cursor shape to be a blinking underline.
Definition frame.cpp:217
Element bold(Element child)
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 displays an ASCII art "video".
Element borderRounded(Element child)
Draw a rounded border around the element.
Element emptyElement()
Definition dom/util.cpp:140
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:135
Element flex_shrink(Element child)
Minimize if needed.
Definition flex.cpp:159
Element focusCursorBar(Element child)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:175
Element focusCursorBlock(Element child)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:147
Element vtext(std::string_view text)
Display a piece of unicode text vertically.
Element underlined(Element child)
Underline the given element.
Element center(Element child)
Center an element horizontally and vertically.
Element paragraphAlignJustify(std::string_view the_text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Element focusCursorUnderline(Element child)
Same as focus, but set the cursor shape to be a still underline.
Definition frame.cpp:203
Element borderHeavy(Element child)
Draw a heavy border around the element.
Element inverted(Element child)
Add a filter that will invert the foreground and the background colors.
Definition inverted.cpp:34
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Element align_right(Element child)
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....
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition flex.cpp:153
Element hscroll_indicator(Element child)
Display a horizontal scrollbar at the bottom. Colors follow the content.
Element flex_grow(Element child)
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 child)
Make the element not flexible.
Definition flex.cpp:177
Element strikethrough(Element child)
Apply a strikethrough to text.
Element italic(Element child)
Apply a underlinedDouble to text.
Definition italic.cpp:17
Element dbox(Elements children_)
Stack several element on top of each other.
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition flex.cpp:165
Decorator borderWith(const Cell &pixel)
Same as border but with a constant Cell around the element.
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
Element paragraphAlignCenter(std::string_view the_text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Element borderLight(Element child)
Draw a light border around the element.
Element focus(Element child)
Set the child to be the one focused among its siblings.
Definition frame.cpp:101
Element paragraph(std::string_view the_text)
Return an element drawing the paragraph on multiple lines.
Element bgcolor(Color color, Element child)
Set the background color of an element.
Definition dom/color.cpp:96
Decorator borderStyled(BorderStyle style)
Same as border but with different styles.
Element paragraphAlignRight(std::string_view the_text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
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
Element dim(Element child)
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 separatorCharacter(std::string_view value)
Draw a vertical or horizontal separation in between two other elements.
Element blink(Element child)
The text drawn alternates in between visible and hidden.
Definition blink.cpp:33
Element vcenter(Element child)
Center an element vertically.
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
Element focusCursorBlockBlinking(Element child)
Same as focus, but set the cursor shape to be a blinking block.
Definition frame.cpp:161
Element color(Color color, Element child)
Set the foreground color of an element.
Definition dom/color.cpp:81
Element gauge(float progress)
Draw a high definition progress bar.
Element border(Element child)
Draw a border around the element.
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Element borderEmpty(Element child)
Draw an empty border around the element.
Element yflex_shrink(Element)
Minimize if needed on the Y axis.
Definition flex.cpp:171
Element hcenter(Element child)
Center an element horizontally.
Element vbox(Elements children)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
Definition elements.hpp:37
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
@ EMPTY
Definition elements.hpp:43
@ DOUBLE
Definition elements.hpp:41
@ HEAVY
Definition elements.hpp:40
@ ROUNDED
Definition elements.hpp:42
@ DASHED
Definition elements.hpp:39
@ LIGHT
Definition elements.hpp:38
The FTXUI ftxui::Dimension:: namespace.
bool extend_beyond_screen
Definition elements.hpp:215
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
WidthOrHeight
Definition elements.hpp:176
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
A container displaying elements on row/columns and capable of wrapping on the next column/row when fu...
Definition flexbox.cpp:252
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Draw an vertical bar, with the area in between up/downcolored differently.
size_t image_index
Definition elements.hpp:96
std::shared_ptr< Node > Element
Definition elements.hpp:24
Element xframe(Element child)
Same as frame, but only on the x-axis.
Definition frame.cpp:126
FTXUI_EXPORT(DOM) Element gridbox(std Element hflow(Elements)
A container displaying elements in rows from left to right. When filled, it starts on a new row below...
Definition flexbox.cpp:270
FTXUI_EXPORT(DOM) Element separatorCharacter(std Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
Draw a horizontal bar, with the area in between left/right colored differently.
Direction direction
Definition elements.hpp:82
Element hbox(Elements children)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
std::vector< Element > Elements
Definition elements.hpp:25
Decorator selectionForegroundColor(Color foreground)
Set the foreground color of an element when selected. Note that the style is applied on top of the ex...
Component operator|(Component component, ComponentDecorator decorator)
Decorator selectionBackgroundColor(Color foreground)
Set the background color of an element when selected. Note that the style is applied on top of the ex...
std::function< Element(Element)> Decorator
Definition elements.hpp:26
Element yframe(Element child)
Same as frame, but only on the y-axis.
Definition frame.cpp:134
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
int y
Definition elements.hpp:126
Element selectionStyleReset(Element child)
Reset the selection style of an element.
const Element & element
Definition node.hpp:95
Decorator reflect(Box &box)
Definition reflect.cpp:43
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:27
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
int value
Definition elements.hpp:178
Element canvas(int width, int height, std::function< void(Canvas &)>)
Produce an element drawing a canvas of requested size.
Element frame(Element child)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition frame.cpp:118
Component & operator|=(Component &component, ComponentDecorator decorator)
Element select(Element e)
Set the child to be the one focused among its siblings.
Definition frame.cpp:108
Decorator selectionStyle(std::function< void(Cell &)> style)
Set the style of an element when selected.
@ LESS_THAN
Definition elements.hpp:177
@ GREATER_THAN
Definition elements.hpp:177
Element vflow(Elements)
A container displaying elements in rows from top to bottom. When filled, it starts on a new columns o...
Definition flexbox.cpp:290
Element graph(GraphFunction graph_function)
Draw a graph using a GraphFunction.
std::uint8_t left
Definition screen.cpp:142
std::uint8_t down
Definition screen.cpp:145
std::uint8_t right
Definition screen.cpp:144