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 "ftxui/dom/canvas.hpp"
11#include "ftxui/dom/direction.hpp"
12#include "ftxui/dom/flexbox_config.hpp"
13#include "ftxui/dom/linear_gradient.hpp"
14#include "ftxui/dom/node.hpp"
15#include "ftxui/screen/box.hpp"
16#include "ftxui/screen/color.hpp"
17#include "ftxui/screen/terminal.hpp"
18#include "ftxui/util/ref.hpp"
19
20 namespace ftxui {
21 class Node;
22 using Element = std::shared_ptr<Node>;
23 using Elements = std::vector<Element>;
24 using Decorator = std::function<Element(Element)>;
25 using GraphFunction = std::function<std::vector<int>(int, int)>;
26
27/// @brief BorderStyle is an enumeration that represents the different styles
28/// of borders that can be applied to elements in the terminal UI.
29///
30/// BorderStyle is an enumeration that represents the different styles of
31/// borders that can be applied to elements in the terminal UI.
32/// It is used to define the visual appearance of borders around elements,
33/// such as windows, frames, or separators.
34/// @ingroup dom
35 enum BorderStyle {
36 LIGHT,
37 DASHED,
38 HEAVY,
39 DOUBLE,
40 ROUNDED,
41 EMPTY,
42};
43
44// Pipe elements into decorator togethers.
45// For instance the next lines are equivalents:
46// -> text("ftxui") | bold | underlined
47// -> underlined(bold(text("FTXUI")))
48 Element operator|(Element, Decorator);
49 Element& operator|=(Element&, Decorator);
50 Elements operator|(Elements, Decorator);
51 Decorator operator|(Decorator, Decorator);
52
53// --- Widget ---
54 Element text(std::string text);
55 Element vtext(std::string text);
56 Element separator();
57 Element separatorLight();
58 Element separatorDashed();
59 Element separatorHeavy();
60 Element separatorDouble();
61 Element separatorEmpty();
62 Element separatorStyled(BorderStyle);
63 Element separator(Pixel);
64 Element separatorCharacter(std::string);
65 Element separatorHSelector(float left,
66 float right,
67 Color unselected_color,
68 Color selected_color);
69 Element separatorVSelector(float up,
70 float down,
71 Color unselected_color,
72 Color selected_color);
73 Element gauge(float progress);
74 Element gaugeLeft(float progress);
75 Element gaugeRight(float progress);
76 Element gaugeUp(float progress);
77 Element gaugeDown(float progress);
78 Element gaugeDirection(float progress, Direction direction);
79 Element border(Element);
80 Element borderLight(Element);
81 Element borderDashed(Element);
82 Element borderHeavy(Element);
83 Element borderDouble(Element);
84 Element borderRounded(Element);
85 Element borderEmpty(Element);
86 Decorator borderStyled(BorderStyle);
87 Decorator borderStyled(BorderStyle, Color);
88 Decorator borderStyled(Color);
89 Decorator borderWith(const Pixel&);
90 Element window(Element title, Element content, BorderStyle border = ROUNDED);
91 Element spinner(int charset_index, size_t image_index);
92 Element paragraph(const std::string& text);
93 Element paragraphAlignLeft(const std::string& text);
94 Element paragraphAlignRight(const std::string& text);
95 Element paragraphAlignCenter(const std::string& text);
96 Element paragraphAlignJustify(const std::string& text);
97 Element graph(GraphFunction);
98 Element emptyElement();
99 Element canvas(ConstRef<Canvas>);
100 Element canvas(int width, int height, std::function<void(Canvas&)>);
101 Element canvas(std::function<void(Canvas&)>);
102
103// -- Decorator ---
104 Element bold(Element);
105 Element dim(Element);
106 Element italic(Element);
107 Element inverted(Element);
108 Element underlined(Element);
109 Element underlinedDouble(Element);
110 Element blink(Element);
111 Element strikethrough(Element);
112 Decorator color(Color);
113 Decorator bgcolor(Color);
114 Decorator color(const LinearGradient&);
115 Decorator bgcolor(const LinearGradient&);
116 Element color(Color, Element);
117 Element bgcolor(Color, Element);
118 Element color(const LinearGradient&, Element);
119 Element bgcolor(const LinearGradient&, Element);
120 Decorator focusPosition(int x, int y);
121 Decorator focusPositionRelative(float x, float y);
122 Element automerge(Element child);
123 Decorator hyperlink(std::string link);
124 Element hyperlink(std::string link, Element child);
125 Element selectionStyleReset(Element);
126 Decorator selectionColor(Color foreground);
127 Decorator selectionBackgroundColor(Color foreground);
128 Decorator selectionForegroundColor(Color foreground);
129 Decorator selectionStyle(std::function<void(Pixel&)> style);
130
131// --- Layout is
132// Horizontal, Vertical or stacked set of elements.
133 Element hbox(Elements);
134 Element vbox(Elements);
135 Element dbox(Elements);
136 Element flexbox(Elements, FlexboxConfig config = FlexboxConfig());
137 Element gridbox(std::vector<Elements> lines);
138
139 Element hflow(Elements); // Helper: default flexbox with row direction.
140 Element vflow(Elements); // Helper: default flexbox with column direction.
141
142// -- Flexibility ---
143// Define how to share the remaining space when not all of it is used inside a
144// container.
145 Element flex(Element); // Expand/Minimize if possible/needed.
146 Element flex_grow(Element); // Expand element if possible.
147 Element flex_shrink(Element); // Minimize element if needed.
148
149 Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
150 Element xflex_grow(Element); // Expand element if possible on X axis.
151 Element xflex_shrink(Element); // Minimize element if needed on X axis.
152
153 Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
154 Element yflex_grow(Element); // Expand element if possible on Y axis.
155 Element yflex_shrink(Element); // Minimize element if needed on Y axis.
156
157 Element notflex(Element); // Reset the flex attribute.
158 Element filler(); // A blank expandable element.
159
160// -- Size override;
161 enum WidthOrHeight { WIDTH, HEIGHT };
162 enum Constraint { LESS_THAN, EQUAL, GREATER_THAN };
163 Decorator size(WidthOrHeight, Constraint, int value);
164
165// --- Frame ---
166// A frame is a scrollable area. The internal area is potentially larger than
167// the external one. The internal area is scrolled in order to make visible the
168// focused element.
169 Element frame(Element);
170 Element xframe(Element);
171 Element yframe(Element);
172 Element focus(Element);
173 Element select(Element e); // Deprecated - Alias for focus.
174
175// --- Cursor ---
176// Those are similar to `focus`, but also change the shape of the cursor.
177 Element focusCursorBlock(Element);
178 Element focusCursorBlockBlinking(Element);
179 Element focusCursorBar(Element);
180 Element focusCursorBarBlinking(Element);
181 Element focusCursorUnderline(Element);
182 Element focusCursorUnderlineBlinking(Element);
183
184// --- Misc ---
185 Element vscroll_indicator(Element);
186 Element hscroll_indicator(Element);
187 Decorator reflect(Box& box);
188// Before drawing the |element| clear the pixel below. This is useful in
189// combinaison with dbox.
190 Element clear_under(Element element);
191
192// --- Util --------------------------------------------------------------------
193 Element hcenter(Element);
194 Element vcenter(Element);
195 Element center(Element);
196 Element align_right(Element);
197 Element nothing(Element element);
198
199 namespace Dimension {
200 Dimensions Fit(Element&, bool extend_beyond_screen = false);
201} // namespace Dimension
202
203} // namespace ftxui
204
205// Make container able to take any number of children as input.
206#include "ftxui/dom/take_any_args.hpp"
207
208// Include old definitions using wstring.
209#include "ftxui/dom/deprecated.hpp"
210#endif // FTXUI_DOM_ELEMENTS_HPP
box.hpp
canvas.hpp
color.hpp
direction.hpp
deprecated.hpp
flexbox_config.hpp
ftxui::bgcolor
Decorator bgcolor(Color)
Decorate using a background color.
Definition dom/color.cpp:124
ftxui::window
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Definition src/ftxui/dom/border.cpp:507
ftxui::borderDouble
Element borderDouble(Element)
Draw a double border around the element.
Definition src/ftxui/dom/border.cpp:405
ftxui::focusCursorBarBlinking
Element focusCursorBarBlinking(Element)
Same as focus, but set the cursor shape to be a blinking bar.
Definition frame.cpp:189
ftxui::xflex
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition flex.cpp:129
ftxui::gaugeDirection
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
Definition src/ftxui/dom/gauge.cpp:169
ftxui::focusPositionRelative
Decorator focusPositionRelative(float x, float y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Definition src/ftxui/dom/focus.cpp:31
ftxui::separatorStyled
Element separatorStyled(BorderStyle)
Draw a vertical or horizontal separation in between two other elements.
Definition src/ftxui/dom/separator.cpp:172
ftxui::xflex_grow
Element xflex_grow(Element)
Expand if possible on the X axis.
Definition flex.cpp:147
ftxui::underlinedDouble
Element underlinedDouble(Element)
Apply a underlinedDouble to text.
Definition underlined_double.cpp:17
ftxui::clear_under
Element clear_under(Element element)
Before drawing |child|, clear the pixels below. This is useful in combination with dbox.
Definition clear_under.cpp:38
ftxui::borderDashed
Element borderDashed(Element)
Draw a dashed border around the element.
Definition src/ftxui/dom/border.cpp:300
ftxui::separatorEmpty
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Definition src/ftxui/dom/separator.cpp:357
ftxui::vscroll_indicator
Element vscroll_indicator(Element)
Display a vertical scrollbar on the right. Colors follow the content.
Definition scroll_indicator.cpp:21
ftxui::nothing
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition dom/util.cpp:28
ftxui::size
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Definition src/ftxui/dom/size.cpp:89
ftxui::Direction
Direction
Direction is an enumeration that represents the four cardinal directions.
Definition direction.hpp:13
ftxui::flex
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Definition flex.cpp:123
ftxui::paragraphAlignRight
Element paragraphAlignRight(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Definition src/ftxui/dom/paragraph.cpp:60
ftxui::gaugeRight
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Definition src/ftxui/dom/gauge.cpp:191
ftxui::focusCursorUnderlineBlinking
Element focusCursorUnderlineBlinking(Element)
Same as focus, but set the cursor shape to be a blinking underline.
Definition frame.cpp:217
ftxui::bold
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition bold.cpp:33
ftxui::separatorLight
Element separatorLight()
Draw a vertical or horizontal separation in between two other elements, using the LIGHT style.
Definition src/ftxui/dom/separator.cpp:209
ftxui::spinner
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".
Definition src/ftxui/dom/spinner.cpp:282
ftxui::borderRounded
Element borderRounded(Element)
Draw a rounded border around the element.
Definition src/ftxui/dom/border.cpp:440
ftxui::emptyElement
Element emptyElement()
Definition dom/util.cpp:140
ftxui::yflex
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:135
ftxui::flex_shrink
Element flex_shrink(Element)
Minimize if needed.
Definition flex.cpp:159
ftxui::focusCursorBar
Element focusCursorBar(Element)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:175
ftxui::focusCursorBlock
Element focusCursorBlock(Element)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:147
ftxui::underlined
Element underlined(Element)
Underline the given element.
Definition underlined.cpp:33
ftxui::center
Element center(Element)
Center an element horizontally and vertically.
Definition composite_decorator.cpp:31
ftxui::focusCursorUnderline
Element focusCursorUnderline(Element)
Same as focus, but set the cursor shape to be a still underline.
Definition frame.cpp:203
ftxui::borderHeavy
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition src/ftxui/dom/border.cpp:370
ftxui::inverted
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition inverted.cpp:34
ftxui::paragraphAlignCenter
Element paragraphAlignCenter(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Definition src/ftxui/dom/paragraph.cpp:72
ftxui::gaugeUp
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Definition src/ftxui/dom/gauge.cpp:242
ftxui::text
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:160
ftxui::align_right
Element align_right(Element)
Align an element on the right side.
Definition composite_decorator.cpp:39
ftxui::focusPosition
Decorator focusPosition(int x, int y)
Used inside a frame, this force the view to be scrolled toward a a given position....
Definition src/ftxui/dom/focus.cpp:69
ftxui::yflex_grow
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition flex.cpp:153
ftxui::hscroll_indicator
Element hscroll_indicator(Element)
Display a horizontal scrollbar at the bottom. Colors follow the content.
Definition scroll_indicator.cpp:76
ftxui::flex_grow
Element flex_grow(Element)
Expand if possible.
Definition flex.cpp:141
ftxui::separatorDashed
Element separatorDashed()
Draw a vertical or horizontal separation in between two other elements, using the DASHED style.
Definition src/ftxui/dom/separator.cpp:246
ftxui::notflex
Element notflex(Element)
Make the element not flexible.
Definition flex.cpp:177
ftxui::strikethrough
Element strikethrough(Element)
Apply a strikethrough to text.
Definition strikethrough.cpp:17
ftxui::italic
Element italic(Element)
Apply a underlinedDouble to text.
Definition italic.cpp:17
ftxui::dbox
Element dbox(Elements)
Stack several element on top of each other.
Definition src/ftxui/dom/dbox.cpp:55
ftxui::xflex_shrink
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition flex.cpp:165
ftxui::gaugeLeft
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
Definition src/ftxui/dom/gauge.cpp:213
ftxui::separatorCharacter
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Definition src/ftxui/dom/separator.cpp:395
ftxui::vtext
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition text.cpp:220
ftxui::borderLight
Element borderLight(Element)
Draw a light border around the element.
Definition src/ftxui/dom/border.cpp:335
ftxui::focus
Element focus(Element)
Set the child to be the one focused among its siblings.
Definition frame.cpp:101
ftxui::paragraphAlignLeft
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition src/ftxui/dom/paragraph.cpp:49
ftxui::borderWith
Decorator borderWith(const Pixel &)
Same as border but with a constant Pixel around the element.
Definition src/ftxui/dom/border.cpp:234
ftxui::borderStyled
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Definition src/ftxui/dom/border.cpp:243
ftxui::separator
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Definition src/ftxui/dom/separator.cpp:134
ftxui::filler
Element filler()
An element that will take expand proportionally to the space left in a container.
Definition flex.cpp:98
ftxui::dim
Element dim(Element)
Use a light font, for elements with less emphasis.
Definition dim.cpp:33
ftxui::automerge
Element automerge(Element child)
Enable character to be automatically merged with others nearby.
Definition automerge.cpp:17
ftxui::hyperlink
Decorator hyperlink(std::string link)
Decorate using a hyperlink. The link will be opened when the user clicks on it. This is supported onl...
Definition hyperlink.cpp:70
ftxui::blink
Element blink(Element)
The text drawn alternates in between visible and hidden.
Definition blink.cpp:33
ftxui::vcenter
Element vcenter(Element)
Center an element vertically.
Definition composite_decorator.cpp:23
ftxui::separatorDouble
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
Definition src/ftxui/dom/separator.cpp:320
ftxui::focusCursorBlockBlinking
Element focusCursorBlockBlinking(Element)
Same as focus, but set the cursor shape to be a blinking block.
Definition frame.cpp:161
ftxui::gauge
Element gauge(float progress)
Draw a high definition progress bar.
Definition src/ftxui/dom/gauge.cpp:293
ftxui::paragraphAlignJustify
Element paragraphAlignJustify(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Definition src/ftxui/dom/paragraph.cpp:85
ftxui::border
Element border(Element)
Draw a border around the element.
Definition src/ftxui/dom/border.cpp:227
ftxui::separatorHeavy
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Definition src/ftxui/dom/separator.cpp:283
ftxui::borderEmpty
Element borderEmpty(Element)
Draw an empty border around the element.
Definition src/ftxui/dom/border.cpp:475
ftxui::color
Decorator color(Color)
Decorate using a foreground color.
Definition dom/color.cpp:110
ftxui::yflex_shrink
Element yflex_shrink(Element)
Minimize if needed on the Y axis.
Definition flex.cpp:171
ftxui::hcenter
Element hcenter(Element)
Center an element horizontally.
Definition composite_decorator.cpp:15
ftxui::vbox
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:96
ftxui::BorderStyle
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
Definition elements.hpp:35
ftxui::gaugeDown
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
Definition src/ftxui/dom/gauge.cpp:271
ftxui::EMPTY
@ EMPTY
Definition elements.hpp:41
ftxui::DOUBLE
@ DOUBLE
Definition elements.hpp:39
ftxui::HEAVY
@ HEAVY
Definition elements.hpp:38
ftxui::ROUNDED
@ ROUNDED
Definition elements.hpp:40
ftxui::DASHED
@ DASHED
Definition elements.hpp:37
ftxui::LIGHT
@ LIGHT
Definition elements.hpp:36
ftxui::Dimensions
Dimensions is a structure that represents the size of the terminal.
Definition terminal.hpp:11
linear_gradient.hpp
ftxui::Dimension::Fit
Dimensions Fit(Element &, bool extend_beyond_screen=false)
ftxui
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
ftxui::WidthOrHeight
WidthOrHeight
Definition elements.hpp:161
ftxui::HEIGHT
@ HEIGHT
Definition elements.hpp:161
ftxui::WIDTH
@ WIDTH
Definition elements.hpp:161
ftxui::Decorator
std::function< Element(Element)> Decorator
Definition elements.hpp:24
ftxui::flexbox
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:251
ftxui::separatorVSelector
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 src/ftxui/dom/separator.cpp:512
ftxui::Element
std::shared_ptr< Node > Element
Definition elements.hpp:22
ftxui::xframe
Element xframe(Element)
Same as frame, but only on the x-axis.
Definition frame.cpp:126
ftxui::hflow
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:269
ftxui::selectionStyle
Decorator selectionStyle(std::function< void(Pixel &)> style)
Set the style of an element when selected.
Definition selection_style.cpp:86
ftxui::separatorHSelector
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.
Definition src/ftxui/dom/separator.cpp:442
ftxui::hbox
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
ftxui::canvas
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
Definition src/ftxui/dom/canvas.cpp:891
ftxui::Elements
std::vector< Element > Elements
Definition elements.hpp:23
ftxui::selectionForegroundColor
Decorator selectionForegroundColor(Color foreground)
Set the foreground color of an element when selected. Note that the style is applied on top of the ex...
Definition selection_style.cpp:69
ftxui::operator|
Component operator|(Component component, ComponentDecorator decorator)
Definition component/util.cpp:12
ftxui::selectionBackgroundColor
Decorator selectionBackgroundColor(Color foreground)
Set the background color of an element when selected. Note that the style is applied on top of the ex...
Definition selection_style.cpp:61
ftxui::yframe
Element yframe(Element)
Same as frame, but only on the y-axis.
Definition frame.cpp:134
ftxui::selectionColor
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
Definition selection_style.cpp:78
ftxui::select
Element select(Element e)
Set the child to be the one focused among its siblings.
Definition frame.cpp:108
ftxui::selectionStyleReset
Element selectionStyleReset(Element)
Reset the selection style of an element.
Definition selection_style.cpp:55
ftxui::reflect
Decorator reflect(Box &box)
Definition reflect.cpp:43
ftxui::GraphFunction
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:25
ftxui::gridbox
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Definition src/ftxui/dom/gridbox.cpp:173
ftxui::paragraph
Elements paragraph(std::wstring text)
ftxui::frame
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
ftxui::operator|=
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition component/util.cpp:22
ftxui::Constraint
Constraint
Definition elements.hpp:162
ftxui::LESS_THAN
@ LESS_THAN
Definition elements.hpp:162
ftxui::EQUAL
@ EQUAL
Definition elements.hpp:162
ftxui::GREATER_THAN
@ GREATER_THAN
Definition elements.hpp:162
ftxui::vflow
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:289
ftxui::graph
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Definition src/ftxui/dom/graph.cpp:71
node.hpp
ref.hpp
left
std::uint8_t left
Definition screen.cpp:129
down
std::uint8_t down
Definition screen.cpp:132
right
std::uint8_t right
Definition screen.cpp:131
terminal.hpp