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 <string_view>
11#include "ftxui/dom/canvas.hpp"
15#include "ftxui/dom/node.hpp"
16#include "ftxui/screen/box.hpp"
19#include "ftxui/util/ref.hpp"
20
21namespace ftxui {
22class Node;
23using Element = std::shared_ptr<Node>;
24using Elements = std::vector<Element>;
25using Decorator = std::function<Element(Element)>;
26using GraphFunction = std::function<std::vector<int>(int, int)>;
27
28/// @brief BorderStyle is an enumeration that represents the different styles
29/// of borders that can be applied to elements in the terminal UI.
30///
31/// BorderStyle is an enumeration that represents the different styles of
32/// borders that can be applied to elements in the terminal UI.
33/// It is used to define the visual appearance of borders around elements,
34/// such as windows, frames, or separators.
35/// @ingroup dom
44
45// Pipe elements into decorator togethers.
46// For instance the next lines are equivalents:
47// -> text("ftxui") | bold | underlined
48// -> underlined(bold(text("FTXUI")))
53
54// --- Widget ---
55Element text(std::string_view text);
56Element vtext(std::string_view text);
64Element separator(Pixel);
65Element separatorCharacter(std::string_view);
67 float right,
68 Color unselected_color,
69 Color selected_color);
71 float down,
72 Color unselected_color,
73 Color selected_color);
74Element gauge(float progress);
75Element gaugeLeft(float progress);
76Element gaugeRight(float progress);
77Element gaugeUp(float progress);
78Element gaugeDown(float progress);
79Element gaugeDirection(float progress, Direction direction);
90Decorator borderWith(const Pixel&);
91Element window(Element title, Element content, BorderStyle border = ROUNDED);
92Element spinner(int charset_index, size_t image_index);
93Element paragraph(std::string_view text);
94Element paragraphAlignLeft(std::string_view text);
95Element paragraphAlignRight(std::string_view text);
96Element paragraphAlignCenter(std::string_view text);
97Element paragraphAlignJustify(std::string_view text);
100Element canvas(ConstRef<Canvas>);
101Element canvas(int width, int height, std::function<void(Canvas&)>);
102Element canvas(std::function<void(Canvas&)>);
103
104// -- Decorator ---
113Decorator color(Color);
114Decorator bgcolor(Color);
115Decorator color(const LinearGradient&);
116Decorator bgcolor(const LinearGradient&);
117Element color(Color, Element);
118Element bgcolor(Color, Element);
119Element color(const LinearGradient&, Element);
120Element bgcolor(const LinearGradient&, Element);
121Decorator focusPosition(int x, int y);
122Decorator focusPositionRelative(float x, float y);
124Decorator hyperlink(std::string_view link);
125Element hyperlink(std::string_view link, Element child);
127Decorator selectionColor(Color foreground);
128Decorator selectionBackgroundColor(Color foreground);
129Decorator selectionForegroundColor(Color foreground);
130Decorator selectionStyle(std::function<void(Pixel&)> style);
131
132// --- Layout is
133// Horizontal, Vertical or stacked set of elements.
137Element flexbox(Elements, FlexboxConfig config = FlexboxConfig());
138Element gridbox(std::vector<Elements> lines);
139
140Element hflow(Elements); // Helper: default flexbox with row direction.
141Element vflow(Elements); // Helper: default flexbox with column direction.
142
143// -- Flexibility ---
144// Define how to share the remaining space when not all of it is used inside a
145// container.
146Element flex(Element); // Expand/Minimize if possible/needed.
147Element flex_grow(Element); // Expand element if possible.
148Element flex_shrink(Element); // Minimize element if needed.
149
150Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
151Element xflex_grow(Element); // Expand element if possible on X axis.
152Element xflex_shrink(Element); // Minimize element if needed on X axis.
153
154Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
155Element yflex_grow(Element); // Expand element if possible on Y axis.
156Element yflex_shrink(Element); // Minimize element if needed on Y axis.
157
158Element notflex(Element); // Reset the flex attribute.
159Element filler(); // A blank expandable element.
160
161// -- Size override;
165
166// --- Frame ---
167// A frame is a scrollable area. The internal area is potentially larger than
168// the external one. The internal area is scrolled in order to make visible the
169// focused element.
174Element select(Element e); // Deprecated - Alias for focus.
175
176// --- Cursor ---
177// Those are similar to `focus`, but also change the shape of the cursor.
184
185// --- Misc ---
188Decorator reflect(Box& box);
189// Before drawing the |element| clear the pixel below. This is useful in
190// combinaison with dbox.
192
193// --- Util --------------------------------------------------------------------
198Element nothing(Element element);
199
200namespace Dimension {
201Dimensions Fit(Element&, bool extend_beyond_screen = false);
202} // namespace Dimension
203
204} // namespace ftxui
205
206// Make container able to take any number of children as input.
207#include "ftxui/dom/take_any_args.hpp"
208
209// Include old definitions using wstring.
211#endif // FTXUI_DOM_ELEMENTS_HPP
Decorator bgcolor(Color)
Decorate using a background color.
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Draw window with a title and a border around the element.
Element borderDouble(Element)
Draw a double border around the element.
Element focusCursorBarBlinking(Element)
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:129
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)
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
Element underlinedDouble(Element)
Apply a underlinedDouble to text.
Element clear_under(Element element)
Before drawing |child|, clear the pixels below. This is useful in combination with dbox.
Element borderDashed(Element)
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)
Display a vertical scrollbar on the right. Colors follow the content.
Element nothing(Element element)
A decoration doing absolutely nothing.
Definition dom/util.cpp:28
Element paragraphAlignLeft(std::string_view text)
Return an element drawing the paragraph on multiple lines, aligned on the left.
Decorator size(WidthOrHeight, Constraint, int value)
Apply a constraint on the size of an element.
Direction
Direction is an enumeration that represents the four cardinal directions.
Definition direction.hpp:13
Element flex(Element)
Make a child element to expand proportionally to the space left in a container.
Definition flex.cpp:123
Decorator hyperlink(std::string_view link)
Decorate using a hyperlink. The link will be opened when the user clicks on it. This is supported onl...
Definition hyperlink.cpp:70
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Element focusCursorUnderlineBlinking(Element)
Same as focus, but set the cursor shape to be a blinking underline.
Definition frame.cpp:217
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 displays an ASCII art "video".
Element borderRounded(Element)
Draw a rounded border around the element.
Element emptyElement()
Definition dom/util.cpp:140
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 focusCursorBar(Element)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:175
Element focusCursorBlock(Element)
Same as focus, but set the cursor shape to be a still block.
Definition frame.cpp:147
Element underlined(Element)
Underline the given element.
Element center(Element)
Center an element horizontally and vertically.
Element paragraphAlignJustify(std::string_view text)
Return an element drawing the paragraph on multiple lines, aligned using a justified alignment....
Element focusCursorUnderline(Element)
Same as focus, but set the cursor shape to be a still underline.
Definition frame.cpp:203
Element borderHeavy(Element)
Draw a heavy border around the element.
Element inverted(Element)
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 text(std::wstring text)
Display a piece of unicode text.
Definition text.cpp:164
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....
Element yflex_grow(Element)
Expand if possible on the Y axis.
Definition flex.cpp:153
Element hscroll_indicator(Element)
Display a horizontal scrollbar at the bottom. Colors follow the content.
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 italic(Element)
Apply a underlinedDouble to text.
Definition italic.cpp:17
Element dbox(Elements)
Stack several element on top of each other.
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.
Element paragraphAlignCenter(std::string_view text)
Return an element drawing the paragraph on multiple lines, aligned on the center.
Element vtext(std::wstring text)
Display a piece unicode text vertically.
Definition text.cpp:243
Element borderLight(Element)
Draw a light border around the element.
Element focus(Element)
Set the child to be the one focused among its siblings.
Definition frame.cpp:101
Decorator borderWith(const Pixel &)
Same as border but with a constant Pixel around the element.
Decorator borderStyled(BorderStyle)
Same as border but with different styles.
Element paragraphAlignRight(std::string_view 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 take expand proportionally to the space left in a container.
Definition flex.cpp:98
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 separatorCharacter(std::string_view)
Draw a vertical or horizontal separation in between two other elements.
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:161
Element gauge(float progress)
Draw a high definition progress bar.
Element border(Element)
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)
Draw an empty border around the element.
Decorator color(Color)
Decorate using a foreground color.
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:96
BorderStyle
BorderStyle is an enumeration that represents the different styles of borders that can be applied to ...
Definition elements.hpp:36
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
@ EMPTY
Definition elements.hpp:42
@ DOUBLE
Definition elements.hpp:40
@ HEAVY
Definition elements.hpp:39
@ ROUNDED
Definition elements.hpp:41
@ DASHED
Definition elements.hpp:38
@ LIGHT
Definition elements.hpp:37
Dimensions is a structure that represents the size of the terminal.
Definition terminal.hpp:11
The FTXUI ftxui::Dimension:: namespace.
Dimensions Fit(Element &, bool extend_beyond_screen=false)
The FTXUI ftxui:: namespace.
Definition animation.hpp:10
WidthOrHeight
Definition elements.hpp:162
std::function< Element(Element)> Decorator
Definition elements.hpp:25
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
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
Draw an vertical bar, with the area in between up/downcolored differently.
std::shared_ptr< Node > Element
Definition elements.hpp:23
Element xframe(Element)
Same as frame, but only on the x-axis.
Definition frame.cpp:126
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
Decorator selectionStyle(std::function< void(Pixel &)> style)
Set the style of an element when selected.
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.
Element hbox(Elements)
A container displaying elements horizontally one by one.
Definition hbox.cpp:94
Element canvas(ConstRef< Canvas >)
Produce an element from a Canvas, or a reference to a Canvas.
std::vector< Element > Elements
Definition elements.hpp:24
Decorator selectionForegroundColor(Color foreground)
Set the foreground color of an element when selected. Note that the style is applied on top of the ex...
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...
Element yframe(Element)
Same as frame, but only on the y-axis.
Definition frame.cpp:134
Decorator selectionColor(Color foreground)
Set the color of an element when selected.
Element select(Element e)
Set the child to be the one focused among its siblings.
Definition frame.cpp:108
Element selectionStyleReset(Element)
Reset the selection style of an element.
Decorator reflect(Box &box)
Definition reflect.cpp:43
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:26
Element gridbox(std::vector< Elements > lines)
A container displaying a grid of elements.
Elements paragraph(std::wstring text)
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
Component & operator|=(Component &component, ComponentDecorator decorator)
@ LESS_THAN
Definition elements.hpp:163
@ GREATER_THAN
Definition elements.hpp:163
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
Element graph(GraphFunction)
Draw a graph using a GraphFunction.
std::uint8_t left
Definition screen.cpp:130
std::uint8_t down
Definition screen.cpp:133
std::uint8_t right
Definition screen.cpp:132