FTXUI  3.0.0
C++ functional terminal UI.
Loading...
Searching...
No Matches
elements.hpp
Go to the documentation of this file.
1#ifndef FTXUI_DOM_ELEMENTS_HPP
2#define FTXUI_DOM_ELEMENTS_HPP
3
4#include <functional>
5#include <memory>
6
9#include "ftxui/dom/node.hpp"
10#include "ftxui/screen/box.hpp"
14#include "ftxui/util/ref.hpp"
15
16namespace ftxui {
17class Node;
18using Element = std::shared_ptr<Node>;
19using Elements = std::vector<Element>;
20using Decorator = std::function<Element(Element)>;
21using GraphFunction = std::function<std::vector<int>(int, int)>;
22
24enum class GaugeDirection { Left, Up, Right, Down };
25
26// Pipe elements into decorator togethers.
27// For instance the next lines are equivalents:
28// -> text("ftxui") | bold | underlined
29// -> underlined(bold(text("FTXUI")))
34
35// --- Widget ---
36Element text(std::string text);
37Element vtext(std::string text);
44Element separator(Pixel);
45Element separatorCharacter(std::string);
47 float right,
48 Color unselected_color,
49 Color selected_color);
51 float down,
52 Color unselected_color,
53 Color selected_color);
54Element gauge(float progress);
55Element gaugeLeft(float progress);
56Element gaugeRight(float progress);
57Element gaugeUp(float progress);
58Element gaugeDown(float progress);
67Decorator borderWith(const Pixel&);
68Element window(Element title, Element content);
69Element spinner(int charset_index, size_t image_index);
70Element paragraph(const std::string& text);
71Element paragraphAlignLeft(const std::string& text);
72Element paragraphAlignRight(const std::string& text);
73Element paragraphAlignCenter(const std::string& text);
74Element paragraphAlignJustify(const std::string& text);
77Element canvas(ConstRef<Canvas>);
78Element canvas(int width, int height, std::function<void(Canvas&)>);
79Element canvas(std::function<void(Canvas&)>);
80
81// -- Decorator ---
87Decorator color(Color);
88Decorator bgcolor(Color);
89Element color(Color, Element);
90Element bgcolor(Color, Element);
91Decorator focusPosition(int x, int y);
92Decorator focusPositionRelative(float x, float y);
94
95// --- Layout is
96// Horizontal, Vertical or stacked set of elements.
101Element gridbox(std::vector<Elements> lines);
102
103Element hflow(Elements); // Helper: default flexbox with row direction.
104Element vflow(Elements); // Helper: default flexbox with column direction.
105
106// -- Flexibility ---
107// Define how to share the remaining space when not all of it is used inside a
108// container.
109Element flex(Element); // Expand/Minimize if possible/needed.
110Element flex_grow(Element); // Expand element if possible.
111Element flex_shrink(Element); // Minimize element if needed.
112
113Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
114Element xflex_grow(Element); // Expand element if possible on X axis.
115Element xflex_shrink(Element); // Minimize element if needed on X axis.
116
117Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
118Element yflex_grow(Element); // Expand element if possible on Y axis.
119Element yflex_shrink(Element); // Minimize element if needed on Y axis.
120
121Element notflex(Element); // Reset the flex attribute.
122Element filler(); // A blank expandable element.
123
124// -- Size override;
128
129// --
130Decorator reflect(Box& box);
131
132// --- Frame ---
133// A frame is a scrollable area. The internal area is potentially larger than
134// the external one. The internal area is scrolled in order to make visible the
135// focused element.
141
143
144// --- Util --------------------------------------------------------------------
149Element nothing(Element element);
150
151// Before drawing the |element| clear the pixel below. This is useful in
152// combinaison with dbox.
154
155namespace Dimension {
157} // namespace Dimension
158
159} // namespace ftxui
160
161// Make container able to take any number of children as input.
162#include "ftxui/dom/take_any_args.hpp"
163
164// Include old definitions using wstring.
166#endif // FTXUI_DOM_ELEMENTS_HPP
167
168// Copyright 2020 Arthur Sonzogni. All rights reserved.
169// Use of this source code is governed by the MIT license that can be found in
170// the LICENSE file.
Dimensions Fit(Element &)
Decorator bgcolor(Color)
Decorate using a background color.
Definition color.cpp:100
Element borderDouble(Element)
Draw a double border around the element.
Definition border.cpp:320
Element xflex(Element)
Expand/Minimize if possible/needed on the X axis.
Definition flex.cpp:126
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:28
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:144
std::function< Element(Element)> Decorator
Definition elements.hpp:20
Element clear_under(Element element)
Before drawing |child|, clear the pixels below. This is useful in.
Element separatorEmpty()
Draw a vertical or horizontal separation in between two other elements, using the EMPTY style.
Element vscroll_indicator(Element)
Add a filter that will invert the foreground and the background 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:26
Element flex(Element)
Make a child element to expand proportionnally to the space left in a container.
Definition flex.cpp:120
Element xframe(Element)
Definition frame.cpp:142
Element paragraphAlignRight(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the right.
Definition paragraph.cpp:42
std::shared_ptr< Node > Element
Definition elements.hpp:18
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Definition gauge.cpp:184
Element bold(Element)
Use a bold font, for elements with more emphasis.
Definition bold.cpp:28
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:259
Element borderRounded(Element)
Draw a rounded border around the element.
Definition border.cpp:354
Element emptyElement()
Definition util.cpp:130
Element yflex(Element)
Expand/Minimize if possible/needed on the Y axis.
Definition flex.cpp:132
Element window(Element title, Element content)
Draw window with a title and a border around the element.
Definition border.cpp:413
Element flex_shrink(Element)
Minimize if needed.
Definition flex.cpp:156
Element hflow(Elements)
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 focus(Element)
Definition frame.cpp:79
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:76
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
Definition canvas.cpp:845
Element underlined(Element)
Make the underlined element to be underlined.
Element center(Element)
Center an element horizontally and vertically.
std::vector< Element > Elements
Definition elements.hpp:19
Component operator|(Component component, ComponentDecorator decorator)
Definition util.cpp:9
Element borderHeavy(Element)
Draw a heavy border around the element.
Definition border.cpp:286
Element inverted(Element)
Add a filter that will invert the foreground and the background colors.
Definition inverted.cpp:29
Element paragraphAlignCenter(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Definition paragraph.cpp:52
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Definition gauge.cpp:235
Element text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:111
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:67
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition flex.cpp:150
Element flex_grow(Element)
Expand if possible.
Definition flex.cpp:138
Element yframe(Element)
Definition frame.cpp:146
Element notflex(Element)
Make the element not flexible.
Definition flex.cpp:174
Element dbox(Elements)
Stack several element on top of each other.
Definition dbox.cpp:51
Element xflex_shrink(Element)
Minimize if needed on the X axis.
Definition flex.cpp:162
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
Definition gauge.cpp:206
Element separatorCharacter(std::string)
Draw a vertical or horizontal separation in between two other elements.
Element vflow(Elements)
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition text.cpp:171
Element borderLight(Element)
Draw a light border around the element.
Definition border.cpp:252
Element paragraphAlignLeft(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Definition paragraph.cpp:33
Decorator borderWith(const Pixel &)
Same as border but with a constant Pixel around the element.
Definition border.cpp:207
Decorator reflect(Box &box)
Definition reflect.cpp:39
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:21
GaugeDirection
Definition elements.hpp:24
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Definition border.cpp:216
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Definition gridbox.cpp:159
Element separator()
Draw a vertical or horizontal separation in between two other elements.
Element filler()
An element that will take expand proportionnally to the space left in a container.
Definition flex.cpp:95
Elements paragraph(std::wstring text)
Element dim(Element)
Use a light font, for elements with less emphasis.
Definition dim.cpp:28
Element automerge(Element child)
Enable character to be automatically merged with others nearby.
Definition automerge.cpp:14
Element frame(Element)
Allow an element to be displayed inside a 'virtual' area. It size can be larger than its container....
Definition frame.cpp:138
Element blink(Element)
The text drawn alternates in between visible and hidden.
Definition blink.cpp:28
Element vcenter(Element)
Center an element vertically.
Decorator size(Direction, Constraint, int value)
Apply a constraint on the size of an element.
Definition size.cpp:85
Element separatorDouble()
Draw a vertical or horizontal separation in between two other elements, using the DOUBLE style.
Component & operator|=(Component &component, ComponentDecorator decorator)
Definition util.cpp:19
@ LESS_THAN
Definition elements.hpp:126
@ GREATER_THAN
Definition elements.hpp:126
Element gauge(float progress)
Draw a high definition progress bar.
Definition gauge.cpp:286
Element paragraphAlignJustify(const std::string &text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Definition paragraph.cpp:63
Element gaugeDirection(float progress, GaugeDirection)
Draw a high definition progress bar progressing in specified direction.
Definition gauge.cpp:162
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
Definition graph.cpp:62
Element border(Element)
Draw a border around the element.
Definition border.cpp:200
Element separatorHeavy()
Draw a vertical or horizontal separation in between two other elements, using the HEAVY style.
Element select(Element)
Definition frame.cpp:38
Element borderEmpty(Element)
Draw an empty border around the element.
Definition border.cpp:388
Decorator color(Color)
Decorate using a foreground color.
Definition color.cpp:86
Element yflex_shrink(Element)
Minimize if needed on the Y axis.
Definition flex.cpp:168
Element hcenter(Element)
Center an element horizontally.
Element vbox(Elements)
A container displaying elements vertically one by one.
Definition vbox.cpp:77
BorderStyle
Definition elements.hpp:23
@ EMPTY
Definition elements.hpp:23
@ DOUBLE
Definition elements.hpp:23
@ HEAVY
Definition elements.hpp:23
@ ROUNDED
Definition elements.hpp:23
@ LIGHT
Definition elements.hpp:23
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
Definition gauge.cpp:264