FTXUI  5.0.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 <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 ---
103Decorator color(Color);
104Decorator bgcolor(Color);
105Decorator color(const LinearGradient&);
106Decorator bgcolor(const LinearGradient&);
107Element color(Color, Element);
108Element bgcolor(Color, Element);
109Element color(const LinearGradient&, Element);
110Element bgcolor(const LinearGradient&, Element);
111Decorator focusPosition(int x, int y);
112Decorator focusPositionRelative(float x, float y);
114Decorator hyperlink(std::string link);
115Element hyperlink(std::string link, Element child);
117Decorator selectionColor(Color foreground);
118Decorator selectionBackgroundColor(Color foreground);
119Decorator selectionForegroundColor(Color foreground);
120Decorator selectionStyle(std::function<void(Pixel&)> style);
121
122// --- Layout is
123// Horizontal, Vertical or stacked set of elements.
128Element gridbox(std::vector<Elements> lines);
129
130Element hflow(Elements); // Helper: default flexbox with row direction.
131Element vflow(Elements); // Helper: default flexbox with column direction.
132
133// -- Flexibility ---
134// Define how to share the remaining space when not all of it is used inside a
135// container.
136Element flex(Element); // Expand/Minimize if possible/needed.
137Element flex_grow(Element); // Expand element if possible.
138Element flex_shrink(Element); // Minimize element if needed.
139
140Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
141Element xflex_grow(Element); // Expand element if possible on X axis.
142Element xflex_shrink(Element); // Minimize element if needed on X axis.
143
144Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
145Element yflex_grow(Element); // Expand element if possible on Y axis.
146Element yflex_shrink(Element); // Minimize element if needed on Y axis.
147
148Element notflex(Element); // Reset the flex attribute.
149Element filler(); // A blank expandable element.
150
151// -- Size override;
155
156// --- Frame ---
157// A frame is a scrollable area. The internal area is potentially larger than
158// the external one. The internal area is scrolled in order to make visible the
159// focused element.
165
166// --- Cursor ---
167// Those are similar to `focus`, but also change the shape of the cursor.
174
175// --- Misc ---
178Decorator reflect(Box& box);
179// Before drawing the |element| clear the pixel below. This is useful in
180// combinaison with dbox.
182
183// --- Util --------------------------------------------------------------------
188Element nothing(Element element);
189
190namespace Dimension {
192} // namespace Dimension
193
194} // namespace ftxui
195
196// Make container able to take any number of children as input.
197#include "ftxui/dom/take_any_args.hpp"
198
199// Include old definitions using wstring.
201#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:508
WidthOrHeight
Definition elements.hpp:152
Element borderDouble(Element)
Draw a double border around the element.
Definition border.cpp:406
Element focusCursorBarBlinking(Element)
Same as focus, but set the cursor shape to be a blinking bar.
Definition frame.cpp:237
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:301
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:59
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:174
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:265
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:441
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:223
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:195
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:96
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:251
Component operator|(Component component, ComponentDecorator decorator)
Definition util.cpp:12
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition border.cpp:371
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:71
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:159
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:70
std::vector< Element > Elements
Definition elements.hpp:23
Element yframe(Element)
Same as frame, but only on the y-axis.
Definition frame.cpp:182
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 dbox(Elements)
Stack several element on top of each other.
Definition dbox.cpp:111
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)
Set the child to be the one selected among its siblings.
Definition frame.cpp:149
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition text.cpp:219
Element borderLight(Element)
Draw a light border around the element.
Definition border.cpp:336
Element focus(Element)
Set the child to be the one in focus globally.
Definition frame.cpp:156
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition paragraph.cpp:48
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:235
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:244
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Definition gridbox.cpp:183
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:166
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:209
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition util.cpp:22
@ LESS_THAN
Definition elements.hpp:153
@ GREATER_THAN
Definition elements.hpp:153
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:84
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:228
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:476
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:97
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