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);
116
117// --- Layout is
118// Horizontal, Vertical or stacked set of elements.
123Element gridbox(std::vector<Elements> lines);
124
125Element hflow(Elements); // Helper: default flexbox with row direction.
126Element vflow(Elements); // Helper: default flexbox with column direction.
127
128// -- Flexibility ---
129// Define how to share the remaining space when not all of it is used inside a
130// container.
131Element flex(Element); // Expand/Minimize if possible/needed.
132Element flex_grow(Element); // Expand element if possible.
133Element flex_shrink(Element); // Minimize element if needed.
134
135Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
136Element xflex_grow(Element); // Expand element if possible on X axis.
137Element xflex_shrink(Element); // Minimize element if needed on X axis.
138
139Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
140Element yflex_grow(Element); // Expand element if possible on Y axis.
141Element yflex_shrink(Element); // Minimize element if needed on Y axis.
142
143Element notflex(Element); // Reset the flex attribute.
144Element filler(); // A blank expandable element.
145
146// -- Size override;
150
151// --- Frame ---
152// A frame is a scrollable area. The internal area is potentially larger than
153// the external one. The internal area is scrolled in order to make visible the
154// focused element.
160
161// --- Cursor ---
162// Those are similar to `focus`, but also change the shape of the cursor.
169
170// --- Misc ---
173Decorator reflect(Box& box);
174// Before drawing the |element| clear the pixel below. This is useful in
175// combinaison with dbox.
177
178// --- Util --------------------------------------------------------------------
183Element nothing(Element element);
184
185namespace Dimension {
187} // namespace Dimension
188
189} // namespace ftxui
190
191// Make container able to take any number of children as input.
192#include "ftxui/dom/take_any_args.hpp"
193
194// Include old definitions using wstring.
196#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:147
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:128
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:146
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:122
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:45
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
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:134
Element flex_shrink(Element)
Minimize if needed.
Definition flex.cpp:158
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:83
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.
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:55
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:119
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:152
Element hscroll_indicator(Element)
Display an horizontal scrollbar to the bottom. colors.
Element flex_grow(Element)
Expand if possible.
Definition flex.cpp:140
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:176
Element strikethrough(Element)
Apply a strikethrough to text.
Element dbox(Elements)
Stack several element on top of each other.
Definition dbox.cpp:111
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition flex.cpp:164
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:179
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:36
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:97
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:148
@ GREATER_THAN
Definition elements.hpp:148
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:66
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:170
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:83
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