FTXUI 7.1.0
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 <cstdint>
8#include <functional>
9#include <memory>
10
11#include <string_view>
12#include "ftxui/dom/canvas.hpp"
16#include "ftxui/dom/node.hpp"
17#include "ftxui/screen/box.hpp"
20#include "ftxui/util/export.hpp"
21#include "ftxui/util/ref.hpp"
22
23namespace ftxui {
24class Node;
25using Element = std::shared_ptr<Node>;
26using Elements = std::vector<Element>;
27using Decorator = std::function<Element(Element)>;
28using GraphFunction = std::function<std::vector<int>(int, int)>;
29
30/// @brief BorderStyle is an enumeration that represents the different styles
31/// of borders that can be applied to elements in the terminal UI.
32///
33/// BorderStyle is an enumeration that represents the different styles of
34/// borders that can be applied to elements in the terminal UI.
35/// It is used to define the visual appearance of borders around elements,
36/// such as windows, frames, or separators.
37/// @ingroup dom
46
47// Pipe elements into decorator together.
48// For instance the next lines are equivalents:
49// -> text("ftxui") | bold | underlined
50// -> underlined(bold(text("FTXUI")))
55
56// --- Widget ---
57FTXUI_EXPORT(DOM) Element text(std::string_view text);
58FTXUI_EXPORT(DOM) Element vtext(std::string_view text);
67FTXUI_EXPORT(DOM) Element separatorCharacter(std::string_view);
68FTXUI_EXPORT(DOM)
70 float right,
71 Color unselected_color,
72 Color selected_color);
73FTXUI_EXPORT(DOM)
75 float down,
76 Color unselected_color,
77 Color selected_color);
78FTXUI_EXPORT(DOM) Element gauge(float progress);
79FTXUI_EXPORT(DOM) Element gaugeLeft(float progress);
80FTXUI_EXPORT(DOM) Element gaugeRight(float progress);
81FTXUI_EXPORT(DOM) Element gaugeUp(float progress);
82FTXUI_EXPORT(DOM) Element gaugeDown(float progress);
84
85// charset[0] is the "empty" glyph, charset.back() is "full"; entries in
86// between shade the boundary cell.
87FTXUI_EXPORT(DOM)
88Element gaugeCharset(float progress,
89 std::vector<std::string> charset,
101FTXUI_EXPORT(DOM) Decorator borderWith(const Cell&);
102FTXUI_EXPORT(DOM)
103Element window(Element title, Element content, BorderStyle border = ROUNDED);
104FTXUI_EXPORT(DOM) Element spinner(int charset_index, size_t image_index);
105FTXUI_EXPORT(DOM) Element paragraph(std::string_view text);
106FTXUI_EXPORT(DOM) Element paragraphAlignLeft(std::string_view text);
107FTXUI_EXPORT(DOM) Element paragraphAlignRight(std::string_view text);
108FTXUI_EXPORT(DOM) Element paragraphAlignCenter(std::string_view text);
109FTXUI_EXPORT(DOM) Element paragraphAlignJustify(std::string_view text);
113FTXUI_EXPORT(DOM)
114Element canvas(int width, int height, std::function<void(Canvas&)>);
115FTXUI_EXPORT(DOM) Element canvas(std::function<void(Canvas&)>);
116
117// -- Decorator ---
126FTXUI_EXPORT(DOM) Decorator color(Color);
127FTXUI_EXPORT(DOM) Decorator bgcolor(Color);
128FTXUI_EXPORT(DOM) Decorator color(const LinearGradient&);
129FTXUI_EXPORT(DOM) Decorator bgcolor(const LinearGradient&);
130FTXUI_EXPORT(DOM) Element color(Color, Element);
132FTXUI_EXPORT(DOM) Element color(const LinearGradient&, Element);
133FTXUI_EXPORT(DOM) Element bgcolor(const LinearGradient&, Element);
135FTXUI_EXPORT(DOM) Decorator focusPositionRelative(float x, float y);
137FTXUI_EXPORT(DOM) Decorator hyperlink(std::string_view link);
138FTXUI_EXPORT(DOM) Element hyperlink(std::string_view link, Element child);
140FTXUI_EXPORT(DOM) Decorator selectionColor(Color foreground);
141FTXUI_EXPORT(DOM) Decorator selectionBackgroundColor(Color foreground);
142FTXUI_EXPORT(DOM) Decorator selectionForegroundColor(Color foreground);
143FTXUI_EXPORT(DOM) Decorator selectionStyle(std::function<void(Cell&)> style);
144
145// --- Layout is
146// Horizontal, Vertical or stacked set of elements.
150FTXUI_EXPORT(DOM)
151Element flexbox(Elements, FlexboxConfig config = FlexboxConfig());
152FTXUI_EXPORT(DOM) Element gridbox(std::vector<Elements> lines);
153
154FTXUI_EXPORT(DOM)
155Element hflow(Elements); // Helper: default flexbox with row direction.
156FTXUI_EXPORT(DOM)
157Element vflow(Elements); // Helper: default flexbox with column direction.
158
159// -- Flexibility ---
160// Define how to share the remaining space when not all of it is used inside a
161// container.
162FTXUI_EXPORT(DOM) Element flex(Element); // Expand/Minimize if possible/needed.
163FTXUI_EXPORT(DOM) Element flex_grow(Element); // Expand element if possible.
164FTXUI_EXPORT(DOM) Element flex_shrink(Element); // Minimize element if needed.
168
169FTXUI_EXPORT(DOM)
170Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
171FTXUI_EXPORT(DOM)
172Element xflex_grow(Element); // Expand element if possible on X axis.
173FTXUI_EXPORT(DOM)
174Element xflex_shrink(Element); // Minimize element if needed on X axis.
175FTXUI_EXPORT(DOM) Decorator xflex_factor(int grow, int shrink);
178
179FTXUI_EXPORT(DOM)
180Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
181FTXUI_EXPORT(DOM)
182Element yflex_grow(Element); // Expand element if possible on Y axis.
183FTXUI_EXPORT(DOM)
184Element yflex_shrink(Element); // Minimize element if needed on Y axis.
185FTXUI_EXPORT(DOM) Decorator yflex_factor(int grow, int shrink);
188
189FTXUI_EXPORT(DOM) Element notflex(Element); // Reset the flex attribute.
190FTXUI_EXPORT(DOM) Element filler(); // A blank expandable element.
191
192// -- Size override;
193enum WidthOrHeight : uint8_t { WIDTH, HEIGHT };
196
197// --- Frame ---
198// A frame is a scrollable area. The internal area is potentially larger than
199// the external one. The internal area is scrolled in order to make visible the
200// focused element.
205FTXUI_EXPORT(DOM) Element select(Element e); // Deprecated - Alias for focus.
206
207// --- Cursor ---
208// Those are similar to `focus`, but also change the shape of the cursor.
215
216// --- Misc ---
219FTXUI_EXPORT(DOM) Decorator reflect(Box& box);
220// Before drawing the |element| clear the pixel below. This is useful in
221// combination with dbox.
223
224// --- Util --------------------------------------------------------------------
230
231namespace Dimension {
232FTXUI_EXPORT(DOM) Dimensions Fit(Element&, bool extend_beyond_screen = false);
233} // namespace Dimension
234
235} // namespace ftxui
236
237// Make container able to take any number of children as input.
238#include "ftxui/dom/take_any_args.hpp"
239
240// Include old definitions using wstring.
242#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:101
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:119
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. The background follows the content, the rest follows the p...
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition util.cpp:28
Element paragraphAlignLeft(std::string_view the_text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Element flex(Element child)
Make a child element to expand proportionally to the space left in a container.
Definition flex.cpp:95
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 util.cpp:140
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:107
Element flex_shrink(Element child)
Minimize if needed.
Definition flex.cpp:131
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.
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
Definition elements.hpp:38
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....
Direction
Direction is an enumeration that represents the four cardinal directions.
Definition direction.hpp:15
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 gaugeCharset(float progress, std::vector< std::string > charset, Direction direction=Direction::Right)
Draw a high definition progress bar using a custom charset.
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:125
Element hscroll_indicator(Element child)
Display a horizontal scrollbar at the bottom. The background follows the content, the rest follows th...
Element flex_grow(Element child)
Expand if possible.
Definition flex.cpp:113
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:149
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:137
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.
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 expand proportionally to the space left in a container.
Definition flex.cpp:70
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.
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:143
Element hcenter(Element child)
Center an element horizontally.
Element vbox(Elements children)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
@ EMPTY
Definition elements.hpp:44
@ DOUBLE
Definition elements.hpp:42
@ HEAVY
Definition elements.hpp:41
@ ROUNDED
Definition elements.hpp:43
@ DASHED
Definition elements.hpp:40
@ LIGHT
Definition elements.hpp:39
The FTXUI ftxui::Dimension:: namespace.
bool extend_beyond_screen
Definition elements.hpp:232
The FTXUI ftxui:: namespace.
Definition animation.hpp:11
@ LESS_THAN
Definition elements.hpp:194
@ GREATER_THAN
Definition elements.hpp:194
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.
Decorator yflex_shrink_factor(int shrink)
Definition flex.cpp:201
size_t image_index
Definition elements.hpp:104
std::shared_ptr< Node > Element
Definition app.hpp:25
Element xframe(Element child)
Same as frame, but only on the x-axis.
Definition frame.cpp:126
Decorator xflex_grow_factor(int grow)
Definition flex.cpp:177
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
Decorator yflex_grow_factor(int grow)
Definition flex.cpp:195
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:83
Element hbox(Elements children)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
std::vector< Element > Elements
Definition elements.hpp:26
Decorator selectionForegroundColor(Color foreground)
Set the foreground color of an element when selected. Note that the style is applied on top of the ex...
Decorator yflex_factor(int grow, int shrink)
Definition flex.cpp:189
WidthOrHeight
Definition elements.hpp:193
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:27
Decorator flex_shrink_factor(int shrink)
Definition flex.cpp:165
Element yframe(Element child)
Same as frame, but only on the y-axis.
Definition frame.cpp:134
Decorator flex_grow_factor(int grow)
Definition flex.cpp:159
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
int shrink
Definition elements.hpp:165
int y
Definition elements.hpp:134
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:28
Decorator xflex_shrink_factor(int shrink)
Definition flex.cpp:183
Decorator xflex_factor(int grow, int shrink)
Definition flex.cpp:171
Decorator flex_factor(int grow, int shrink)
Definition flex.cpp:153
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
int value
Definition elements.hpp:195
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.
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.
size_t size
Definition screen.cpp:82
std::uint8_t left
Definition screen.cpp:178
std::uint8_t down
Definition screen.cpp:181
std::uint8_t right
Definition screen.cpp:180