| 
									
										
										
										
											2023-08-19 13:56:36 +02:00
										 |  |  | // Copyright 2020 Arthur Sonzogni. All rights reserved.
 | 
					
						
							|  |  |  | // Use of this source code is governed by the MIT license that can be found in
 | 
					
						
							|  |  |  | // the LICENSE file.
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | #ifndef FTXUI_DOM_ELEMENTS_HPP
 | 
					
						
							|  |  |  | #define FTXUI_DOM_ELEMENTS_HPP
 | 
					
						
							| 
									
										
										
										
											2018-09-18 08:48:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-03 00:35:59 +01:00
										 |  |  | #include <functional>
 | 
					
						
							| 
									
										
										
										
											2020-05-20 20:36:47 +02:00
										 |  |  | #include <memory>
 | 
					
						
							| 
									
										
										
										
											2019-01-03 00:35:59 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 14:17:33 +01:00
										 |  |  | #include "ftxui/dom/canvas.hpp"
 | 
					
						
							| 
									
										
										
										
											2023-03-09 20:21:23 +01:00
										 |  |  | #include "ftxui/dom/direction.hpp"
 | 
					
						
							| 
									
										
										
										
											2021-12-11 17:58:25 +01:00
										 |  |  | #include "ftxui/dom/flexbox_config.hpp"
 | 
					
						
							| 
									
										
										
										
											2023-03-22 09:59:02 -03:00
										 |  |  | #include "ftxui/dom/linear_gradient.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | #include "ftxui/dom/node.hpp"
 | 
					
						
							| 
									
										
										
										
											2021-04-18 22:33:41 +02:00
										 |  |  | #include "ftxui/screen/box.hpp"
 | 
					
						
							| 
									
										
										
										
											2019-01-06 17:10:35 +01:00
										 |  |  | #include "ftxui/screen/color.hpp"
 | 
					
						
							| 
									
										
										
										
											2021-08-03 02:49:29 +05:30
										 |  |  | #include "ftxui/screen/terminal.hpp"
 | 
					
						
							| 
									
										
										
										
											2021-12-23 14:17:33 +01:00
										 |  |  | #include "ftxui/util/ref.hpp"
 | 
					
						
							| 
									
										
										
										
											2018-09-18 08:48:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-12 15:00:08 +01:00
										 |  |  | namespace ftxui { | 
					
						
							| 
									
										
										
										
											2020-05-20 20:36:47 +02:00
										 |  |  | class Node; | 
					
						
							|  |  |  | using Element = std::shared_ptr<Node>; | 
					
						
							| 
									
										
										
										
											2019-01-12 18:24:46 +01:00
										 |  |  | using Elements = std::vector<Element>; | 
					
						
							| 
									
										
										
										
											2019-01-03 00:35:59 +01:00
										 |  |  | using Decorator = std::function<Element(Element)>; | 
					
						
							| 
									
										
										
										
											2020-02-11 21:44:55 +01:00
										 |  |  | using GraphFunction = std::function<std::vector<int>(int, int)>; | 
					
						
							| 
									
										
										
										
											2018-09-19 21:52:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-06-05 11:35:14 +02:00
										 |  |  | /// @brief BorderStyle is an enumeration that represents the different styles
 | 
					
						
							|  |  |  | /// of borders that can be applied to elements in the terminal UI.
 | 
					
						
							|  |  |  | ///
 | 
					
						
							|  |  |  | /// BorderStyle is an enumeration that represents the different styles of
 | 
					
						
							|  |  |  | /// borders that can be applied to elements in the terminal UI.
 | 
					
						
							|  |  |  | /// It is used to define the visual appearance of borders around elements,
 | 
					
						
							|  |  |  | /// such as windows, frames, or separators.
 | 
					
						
							|  |  |  | /// @ingroup dom
 | 
					
						
							| 
									
										
										
										
											2023-03-15 22:50:27 +01:00
										 |  |  | enum BorderStyle { | 
					
						
							|  |  |  |   LIGHT, | 
					
						
							|  |  |  |   DASHED, | 
					
						
							|  |  |  |   HEAVY, | 
					
						
							|  |  |  |   DOUBLE, | 
					
						
							|  |  |  |   ROUNDED, | 
					
						
							|  |  |  |   EMPTY, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-07 15:54:45 +02:00
										 |  |  | // Pipe elements into decorator togethers.
 | 
					
						
							|  |  |  | // For instance the next lines are equivalents:
 | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  | // -> text("ftxui") | bold | underlined
 | 
					
						
							| 
									
										
										
										
											2021-08-09 00:27:37 +02:00
										 |  |  | // -> underlined(bold(text("FTXUI")))
 | 
					
						
							| 
									
										
										
										
											2020-06-07 15:54:45 +02:00
										 |  |  | Element operator|(Element, Decorator); | 
					
						
							| 
									
										
										
										
											2022-03-12 22:18:36 +08:00
										 |  |  | Element& operator|=(Element&, Decorator); | 
					
						
							| 
									
										
										
										
											2020-06-07 15:54:45 +02:00
										 |  |  | Elements operator|(Elements, Decorator); | 
					
						
							|  |  |  | Decorator operator|(Decorator, Decorator); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | // --- Widget ---
 | 
					
						
							| 
									
										
										
										
											2021-08-08 23:25:20 +02:00
										 |  |  | Element text(std::string text); | 
					
						
							|  |  |  | Element vtext(std::string text); | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | Element separator(); | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | Element separatorLight(); | 
					
						
							| 
									
										
										
										
											2023-03-15 22:50:27 +01:00
										 |  |  | Element separatorDashed(); | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | Element separatorHeavy(); | 
					
						
							|  |  |  | Element separatorDouble(); | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | Element separatorEmpty(); | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | Element separatorStyled(BorderStyle); | 
					
						
							| 
									
										
										
										
											2019-01-27 02:33:06 +01:00
										 |  |  | Element separator(Pixel); | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | Element separatorCharacter(std::string); | 
					
						
							| 
									
										
										
										
											2022-03-13 18:51:46 +01:00
										 |  |  | Element separatorHSelector(float left, | 
					
						
							|  |  |  |                            float right, | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  |                            Color unselected_color, | 
					
						
							|  |  |  |                            Color selected_color); | 
					
						
							| 
									
										
										
										
											2022-03-13 18:51:46 +01:00
										 |  |  | Element separatorVSelector(float up, | 
					
						
							|  |  |  |                            float down, | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  |                            Color unselected_color, | 
					
						
							|  |  |  |                            Color selected_color); | 
					
						
							|  |  |  | Element gauge(float progress); | 
					
						
							|  |  |  | Element gaugeLeft(float progress); | 
					
						
							|  |  |  | Element gaugeRight(float progress); | 
					
						
							|  |  |  | Element gaugeUp(float progress); | 
					
						
							|  |  |  | Element gaugeDown(float progress); | 
					
						
							| 
									
										
										
										
											2023-03-09 20:21:23 +01:00
										 |  |  | Element gaugeDirection(float progress, Direction direction); | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | Element border(Element); | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | Element borderLight(Element); | 
					
						
							| 
									
										
										
										
											2023-03-15 22:50:27 +01:00
										 |  |  | Element borderDashed(Element); | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | Element borderHeavy(Element); | 
					
						
							|  |  |  | Element borderDouble(Element); | 
					
						
							|  |  |  | Element borderRounded(Element); | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | Element borderEmpty(Element); | 
					
						
							| 
									
										
										
										
											2021-09-12 00:36:59 +02:00
										 |  |  | Decorator borderStyled(BorderStyle); | 
					
						
							| 
									
										
										
										
											2023-03-16 13:15:14 +01:00
										 |  |  | Decorator borderStyled(BorderStyle, Color); | 
					
						
							|  |  |  | Decorator borderStyled(Color); | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | Decorator borderWith(const Pixel&); | 
					
						
							| 
									
										
										
										
											2024-05-01 11:40:49 +02:00
										 |  |  | Element window(Element title, Element content, BorderStyle border = ROUNDED); | 
					
						
							| 
									
										
										
										
											2019-01-06 22:28:15 +01:00
										 |  |  | Element spinner(int charset_index, size_t image_index); | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | Element paragraph(const std::string& text); | 
					
						
							|  |  |  | Element paragraphAlignLeft(const std::string& text); | 
					
						
							|  |  |  | Element paragraphAlignRight(const std::string& text); | 
					
						
							|  |  |  | Element paragraphAlignCenter(const std::string& text); | 
					
						
							|  |  |  | Element paragraphAlignJustify(const std::string& text); | 
					
						
							| 
									
										
										
										
											2019-01-27 02:33:06 +01:00
										 |  |  | Element graph(GraphFunction); | 
					
						
							| 
									
										
										
										
											2021-10-15 23:04:11 +02:00
										 |  |  | Element emptyElement(); | 
					
						
							| 
									
										
										
										
											2021-12-24 17:29:39 +01:00
										 |  |  | Element canvas(ConstRef<Canvas>); | 
					
						
							|  |  |  | Element canvas(int width, int height, std::function<void(Canvas&)>); | 
					
						
							|  |  |  | Element canvas(std::function<void(Canvas&)>); | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-05 02:03:49 +01:00
										 |  |  | // -- Decorator ---
 | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | Element bold(Element); | 
					
						
							|  |  |  | Element dim(Element); | 
					
						
							| 
									
										
										
										
											2025-03-22 10:03:43 -07:00
										 |  |  | Element italic(Element); | 
					
						
							| 
									
										
										
										
											2018-10-09 19:06:03 +02:00
										 |  |  | Element inverted(Element); | 
					
						
							|  |  |  | Element underlined(Element); | 
					
						
							| 
									
										
										
										
											2023-01-22 11:02:27 +01:00
										 |  |  | Element underlinedDouble(Element); | 
					
						
							| 
									
										
										
										
											2018-10-21 14:18:11 +02:00
										 |  |  | Element blink(Element); | 
					
						
							| 
									
										
										
										
											2023-01-22 11:02:27 +01:00
										 |  |  | Element strikethrough(Element); | 
					
						
							| 
									
										
										
										
											2019-01-03 00:35:59 +01:00
										 |  |  | Decorator color(Color); | 
					
						
							|  |  |  | Decorator bgcolor(Color); | 
					
						
							| 
									
										
										
										
											2023-03-22 09:59:02 -03:00
										 |  |  | Decorator color(const LinearGradient&); | 
					
						
							|  |  |  | Decorator bgcolor(const LinearGradient&); | 
					
						
							| 
									
										
										
										
											2019-01-06 22:28:15 +01:00
										 |  |  | Element color(Color, Element); | 
					
						
							|  |  |  | Element bgcolor(Color, Element); | 
					
						
							| 
									
										
										
										
											2023-03-22 09:59:02 -03:00
										 |  |  | Element color(const LinearGradient&, Element); | 
					
						
							|  |  |  | Element bgcolor(const LinearGradient&, Element); | 
					
						
							| 
									
										
										
										
											2021-12-13 11:38:31 +01:00
										 |  |  | Decorator focusPosition(int x, int y); | 
					
						
							|  |  |  | Decorator focusPositionRelative(float x, float y); | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | Element automerge(Element child); | 
					
						
							| 
									
										
										
										
											2023-06-04 21:06:19 +02:00
										 |  |  | Decorator hyperlink(std::string link); | 
					
						
							|  |  |  | Element hyperlink(std::string link, Element child); | 
					
						
							| 
									
										
										
										
											2024-12-27 15:45:13 +07:00
										 |  |  | Element selectionStyleReset(Element); | 
					
						
							|  |  |  | Decorator selectionColor(Color foreground); | 
					
						
							|  |  |  | Decorator selectionBackgroundColor(Color foreground); | 
					
						
							|  |  |  | Decorator selectionForegroundColor(Color foreground); | 
					
						
							|  |  |  | Decorator selectionStyle(std::function<void(Pixel&)> style); | 
					
						
							| 
									
										
										
										
											2018-09-19 21:52:25 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-23 17:47:33 +02:00
										 |  |  | // --- Layout is
 | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | // Horizontal, Vertical or stacked set of elements.
 | 
					
						
							|  |  |  | Element hbox(Elements); | 
					
						
							| 
									
										
										
										
											2019-01-22 23:42:57 +01:00
										 |  |  | Element vbox(Elements); | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | Element dbox(Elements); | 
					
						
							| 
									
										
										
										
											2021-12-11 17:58:25 +01:00
										 |  |  | Element flexbox(Elements, FlexboxConfig config = FlexboxConfig()); | 
					
						
							| 
									
										
										
										
											2021-08-22 19:36:11 +02:00
										 |  |  | Element gridbox(std::vector<Elements> lines); | 
					
						
							| 
									
										
										
										
											2021-12-11 17:58:25 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | Element hflow(Elements);  // Helper: default flexbox with row direction.
 | 
					
						
							|  |  |  | Element vflow(Elements);  // Helper: default flexbox with column direction.
 | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // -- Flexibility ---
 | 
					
						
							|  |  |  | // Define how to share the remaining space when not all of it is used inside a
 | 
					
						
							|  |  |  | // container.
 | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  | Element flex(Element);         // Expand/Minimize if possible/needed.
 | 
					
						
							|  |  |  | Element flex_grow(Element);    // Expand element if possible.
 | 
					
						
							|  |  |  | Element flex_shrink(Element);  // Minimize element if needed.
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:27:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 02:24:50 +02:00
										 |  |  | Element xflex(Element);         // Expand/Minimize if possible/needed on X axis.
 | 
					
						
							|  |  |  | Element xflex_grow(Element);    // Expand element if possible on X axis.
 | 
					
						
							|  |  |  | Element xflex_shrink(Element);  // Minimize element if needed on X axis.
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:27:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-16 02:24:50 +02:00
										 |  |  | Element yflex(Element);         // Expand/Minimize if possible/needed on Y axis.
 | 
					
						
							|  |  |  | Element yflex_grow(Element);    // Expand element if possible on Y axis.
 | 
					
						
							|  |  |  | Element yflex_shrink(Element);  // Minimize element if needed on Y axis.
 | 
					
						
							| 
									
										
										
										
											2020-07-17 00:27:39 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-25 01:34:13 +02:00
										 |  |  | Element notflex(Element);  // Reset the flex attribute.
 | 
					
						
							|  |  |  | Element filler();          // A blank expandable element.
 | 
					
						
							| 
									
										
										
										
											2019-01-20 23:04:10 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // -- Size override;
 | 
					
						
							| 
									
										
										
										
											2023-03-09 20:21:23 +01:00
										 |  |  | enum WidthOrHeight { WIDTH, HEIGHT }; | 
					
						
							| 
									
										
										
										
											2019-01-20 23:04:10 +01:00
										 |  |  | enum Constraint { LESS_THAN, EQUAL, GREATER_THAN }; | 
					
						
							| 
									
										
										
										
											2023-03-09 20:21:23 +01:00
										 |  |  | Decorator size(WidthOrHeight, Constraint, int value); | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | // --- Frame ---
 | 
					
						
							|  |  |  | // A frame is a scrollable area. The internal area is potentially larger than
 | 
					
						
							|  |  |  | // the external one. The internal area is scrolled in order to make visible the
 | 
					
						
							|  |  |  | // focused element.
 | 
					
						
							|  |  |  | Element frame(Element); | 
					
						
							| 
									
										
										
										
											2020-06-07 15:54:45 +02:00
										 |  |  | Element xframe(Element); | 
					
						
							|  |  |  | Element yframe(Element); | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | Element focus(Element); | 
					
						
							| 
									
										
										
										
											2025-03-19 20:03:05 +05:30
										 |  |  | Element select(Element e);  // Deprecated - Alias for focus.
 | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-11 14:09:53 +01:00
										 |  |  | // --- Cursor ---
 | 
					
						
							|  |  |  | // Those are similar to `focus`, but also change the shape of the cursor.
 | 
					
						
							|  |  |  | Element focusCursorBlock(Element); | 
					
						
							|  |  |  | Element focusCursorBlockBlinking(Element); | 
					
						
							|  |  |  | Element focusCursorBar(Element); | 
					
						
							|  |  |  | Element focusCursorBarBlinking(Element); | 
					
						
							|  |  |  | Element focusCursorUnderline(Element); | 
					
						
							|  |  |  | Element focusCursorUnderlineBlinking(Element); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // --- Misc ---
 | 
					
						
							| 
									
										
										
										
											2021-09-26 15:19:17 +02:00
										 |  |  | Element vscroll_indicator(Element); | 
					
						
							| 
									
										
										
										
											2023-09-26 23:08:42 +02:00
										 |  |  | Element hscroll_indicator(Element); | 
					
						
							| 
									
										
										
										
											2022-11-11 14:09:53 +01:00
										 |  |  | Decorator reflect(Box& box); | 
					
						
							|  |  |  | // Before drawing the |element| clear the pixel below. This is useful in
 | 
					
						
							|  |  |  | // combinaison with dbox.
 | 
					
						
							|  |  |  | Element clear_under(Element element); | 
					
						
							| 
									
										
										
										
											2021-09-26 15:19:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-19 22:06:05 +01:00
										 |  |  | // --- Util --------------------------------------------------------------------
 | 
					
						
							| 
									
										
										
										
											2018-09-22 09:49:43 +02:00
										 |  |  | Element hcenter(Element); | 
					
						
							|  |  |  | Element vcenter(Element); | 
					
						
							|  |  |  | Element center(Element); | 
					
						
							| 
									
										
										
										
											2019-01-06 18:53:02 +01:00
										 |  |  | Element align_right(Element); | 
					
						
							| 
									
										
										
										
											2018-10-21 14:18:11 +02:00
										 |  |  | Element nothing(Element element); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-03 02:49:29 +05:30
										 |  |  | namespace Dimension { | 
					
						
							| 
									
										
										
										
											2024-11-07 21:07:09 +01:00
										 |  |  | Dimensions Fit(Element&, bool extend_beyond_screen = false); | 
					
						
							| 
									
										
										
										
											2021-08-03 02:49:29 +05:30
										 |  |  | }  // namespace Dimension
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-11 21:44:55 +01:00
										 |  |  | }  // namespace ftxui
 | 
					
						
							| 
									
										
										
										
											2018-09-18 08:48:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-07-10 14:23:46 +02:00
										 |  |  | // Make container able to take any number of children as input.
 | 
					
						
							|  |  |  | #include "ftxui/dom/take_any_args.hpp"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-08-08 23:25:20 +02:00
										 |  |  | // Include old definitions using wstring.
 | 
					
						
							|  |  |  | #include "ftxui/dom/deprecated.hpp"
 | 
					
						
							| 
									
										
										
										
											2022-03-31 02:17:43 +02:00
										 |  |  | #endif  // FTXUI_DOM_ELEMENTS_HPP
 |