FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
elements.hpp
浏览该文件的文档.
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
27/// @brief BorderStyle 是一个枚举,表示可应用于终端 UI 中元素的不同边框样式。
28///
29/// BorderStyle 是一个枚举,表示可应用于终端 UI 中元素的不同边框样式。
30/// 它用于定义元素周围边框的视觉外观,
31/// 例如窗口、框架或分隔符。
32/// @ingroup dom
41
42// 将元素一起导入装饰器。
43// 例如,以下行是等效的:
44// -> text("ftxui") | bold | underlined
45// -> underlined(bold(text("FTXUI")))Element operator|(Element, Decorator);
49
50// --- 小部件 ---
51Element text(std::string text);
52Element vtext(std::string text);
60Element separator(Pixel);
61Element separatorCharacter(std::string);
63 float right,
64 Color unselected_color,
65 Color selected_color);
67 float down,
68 Color unselected_color,
69 Color selected_color);
70Element gauge(float progress);
71Element gaugeLeft(float progress);
72Element gaugeRight(float progress);
73Element gaugeUp(float progress);
74Element gaugeDown(float progress);
75Element gaugeDirection(float progress, Direction direction);
87Element window(Element title, Element content, BorderStyle border = ROUNDED);
88Element spinner(int charset_index, size_t image_index);
89Element paragraph(const std::string& text);
90Element paragraphAlignLeft(const std::string& text);
91Element paragraphAlignRight(const std::string& text);
92Element paragraphAlignCenter(const std::string& text);
93Element paragraphAlignJustify(const std::string& text);
97Element canvas(int width, int height, std::function<void(Canvas&)>);
98Element canvas(std::function<void(Canvas&)>);
99
100// -- 装饰器 ---
117Decorator focusPosition(int x, int y);
118Decorator focusPositionRelative(float x, float y);
120Decorator hyperlink(std::string link);
121Element hyperlink(std::string link, Element child);
123Decorator selectionColor(Color foreground);
126Decorator selectionStyle(std::function<void(Pixel&)> style);
127
128// --- 布局是
129// 水平、垂直或堆叠的元素集。
134Element gridbox(std::vector<Elements> lines);
135
136Element hflow(Elements); // 助手:默认flexbox,行方向。
137Element vflow(Elements); // 助手:默认flexbox,列方向。
138
139// -- 弹性 ---
140// 定义当容器内并非所有空间都使用时如何共享剩余空间。
141Element flex(Element); // 如果可能/需要,展开/最小化。
142Element flex_grow(Element); // 如果可能,展开元素。
143Element flex_shrink(Element); // 如果需要,最小化元素。
144
145Element xflex(Element); // 如果可能/需要,在 X 轴上展开/最小化。
146Element xflex_grow(Element); // 如果可能,在 X 轴上展开元素。
147Element xflex_shrink(Element); // 如果需要,在 X 轴上最小化元素。
148
149Element yflex(Element); // 如果可能/需要,在 Y 轴上展开/最小化。
150Element yflex_grow(Element); // 如果可能,在 Y 轴上展开元素。
151Element yflex_shrink(Element); // 如果需要,在 Y 轴上最小化元素。
152
153Element notflex(Element); // 重置弹性属性。
154Element filler(); // 一个空白的可扩展元素。
155
156// -- 大小覆盖;
160
161// --- 框架 ---
162// 框架是可滚动区域。内部区域可能大于外部区域。
163// 内部区域滚动以使焦点元素可见。
168Element select(Element e); // 已弃用 - focus 的别名。
169
170// --- 光标 ---
171// 这些类似于 `focus`,但也改变光标的形状。
178
179// --- 其他 ---
182Decorator reflect(Box& box);
183// 在绘制 |element| 之前,清除下面的像素。这与 dbox 结合使用时很有用。
185
186// --- 实用工具 --------------------------------------------------------------------
191Element nothing(Element element);
192
193namespace Dimension {
194Dimensions Fit(Element&, bool extend_beyond_screen = false);
195} // namespace Dimension
196
197} // namespace ftxui
198
199// 使容器能够接受任意数量的子元素作为输入。
200#include "ftxui/dom/take_any_args.hpp"
201
202// 包含使用 wstring 的旧定义。
204#endif // FTXUI_DOM_ELEMENTS_HPP
一个适配器。拥有或引用一个不可变对象。
定义 ref.hpp:17
Decorator bgcolor(Color)
使用背景色进行装饰。
Element xflex(Element)
在 X 轴上尽可能地扩展/收缩。
Element gaugeDirection(float progress, Direction direction)
绘制一个向指定方向推进的高清进度条。
Decorator focusPositionRelative(float x, float y)
在 frame 内部使用,这会强制视图滚动到给定位置。位置以请求大小的比例表示。
Element separatorStyled(BorderStyle)
在两个其他元素之间绘制垂直或水平分隔线。
Element xflex_grow(Element)
如果可能,在 X 轴上进行扩展。
Element underlinedDouble(Element)
对文本应用双下划线。
Element clear_under(Element element)
在绘制 |child| 之前,清除下方的像素。这与 dbox 结合使用很有用。
Element separatorEmpty()
使用 EMPTY 样式在两个其他元素之间绘制垂直或水平分隔线。
Element vscroll_indicator(Element)
在右侧显示一个垂直滚动条。 颜色跟随内容。
Element nothing(Element element)
一个什么都不做的装饰器。
Decorator size(WidthOrHeight, Constraint, int value)
对元素大小应用约束。
Direction
Direction 是一个枚举,表示四个基本方向。
Element flex(Element)
使子元素按比例扩展以填充容器中剩余的空间。
Element paragraphAlignRight(const std::string &text)
返回一个在多行上绘制段落并右对齐的元素。
Element bold(Element)
使用粗体字体,用于强调元素。
Element separatorLight()
使用 LIGHT 样式在两个其他元素之间绘制垂直或水平分隔线。
Element spinner(int charset_index, size_t image_index)
用于表示时间或事件的效果。这显示了一个 ASCII 艺术“视频”。
Element emptyElement()
Element yflex(Element)
在 Y 轴上尽可能地扩展/收缩。
Element flex_shrink(Element)
如果需要,进行收缩。
Element underlined(Element)
给定元素加下划线。
Element center(Element)
水平并垂直居中一个元素。
Element inverted(Element)
添加一个过滤器,用于反转前景色和背景色。
Element paragraphAlignCenter(const std::string &text)
返回一个在多行上绘制段落并居中对齐的元素。
Element text(std::wstring text)
显示一段Unicode文本。
Element align_right(Element)
将元素右对齐。
Decorator focusPosition(int x, int y)
在 frame 内部使用,这会强制视图滚动到给定位置。位置以单元格数量表示。
Element yflex_grow(Element)
如果可能,在 Y 轴上进行扩展。
Element hscroll_indicator(Element)
在底部显示一个水平滚动条。 颜色跟随内容。
Element flex_grow(Element)
如果可能,进行扩展。
Element separatorDashed()
使用 DASHED 样式在两个其他元素之间绘制垂直或水平分隔线。
Element notflex(Element)
使元素不可伸缩。
Element strikethrough(Element)
对文本应用删除线。
Element italic(Element)
对文本应用双下划线。
Element dbox(Elements)
将多个元素堆叠在一起。
Element xflex_shrink(Element)
如果需要,在 X 轴上进行收缩。
Element separatorCharacter(std::string)
在两个其他元素之间绘制垂直或水平分隔线。
Element vtext(std::wstring text)
垂直显示一段Unicode文本。
Element focus(Element)
将 child 设置为其同级元素中获得焦点的元素。
Element paragraphAlignLeft(const std::string &text)
返回一个在多行上绘制段落并左对齐的元素。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element filler()
一个元素,它将按比例扩展以填充容器中剩余的空间。
Element dim(Element)
使用浅色字体,用于不那么重要的元素。
定义 dim.cpp:32
Element automerge(Element child)
启用字符自动与附近的其它字符合并。
Decorator hyperlink(std::string link)
使用超链接进行装饰。 当用户点击时,链接将被打开。 这仅在有限的终端模拟器中受支持。 列表:https://github.com/Alhadis/OSC8-Adoption/
Element blink(Element)
绘制的文本在可见和隐藏之间交替。
Element vcenter(Element)
垂直居中一个元素。
Element separatorDouble()
使用 DOUBLE 样式在两个其他元素之间绘制垂直或水平分隔线。
Element paragraphAlignJustify(const std::string &text)
返回一个在多行上绘制段落并使用两端对齐方式的元素。 居中对齐。
Element separatorHeavy()
使用 HEAVY 样式在两个其他元素之间绘制垂直或水平分隔线。
Decorator color(Color)
使用前景色进行装饰。
Element yflex_shrink(Element)
如果需要,在 Y 轴上进行收缩。
Element hcenter(Element)
水平居中一个元素。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
BorderStyle
BorderStyle 是一个枚举,表示可应用于终端 UI 中元素的不同边框样式。
Canvas 是一个与绘图操作相关的可绘制缓冲区。
FlexboxConfig 是一个配置结构体,定义了弹性盒子容器的布局属性。
一个表示线性渐变颜色效果设置的类。
Color 是一个表示终端用户界面中颜色的类。
Box是一个表示2D空间中矩形区域的结构体。
定义 box.hpp:15
Dimensions 是一个表示终端大小的结构。
一个 Unicode 字符及其相关样式。
FTXUI ftxui::Dimension:: 命名空间
Dimensions Fit(Element &, bool extend_beyond_screen=false)
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::function< Element(Element)> Decorator
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
一个容器,用于在行/列中显示元素,并且在填满时能够换行到下一列/行。
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
绘制一个垂直条,上下区域颜色不同。
std::shared_ptr< Node > Element
Element xframe(Element)
与 frame 相同,但仅限于 x 轴。
Element gaugeRight(float progress)
绘制一个从左到右推进的高清进度条。
Element hflow(Elements)
一个容器,用于从左到右在行中显示元素。当填满时,它会在下方开始新的一行。
Decorator selectionStyle(std::function< void(Pixel &)> style)
设置元素选中时的样式。
Element borderEmpty(Element)
Element focusCursorBlock(Element)
Element focusCursorUnderlineBlinking(Element)
Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
绘制一个水平条,左右区域颜色不同。
Element focusCursorBar(Element)
Element hbox(Elements)
一个按水平顺序逐一显示元素的容器。
Element canvas(ConstRef< Canvas >)
从 Canvas 或 Canvas 引用生成元素。
std::vector< Element > Elements
Decorator selectionForegroundColor(Color foreground)
设置元素选中时的前景色。 请注意,此样式是在现有样式之上应用的。
Component operator|(Component component, ComponentDecorator decorator)
Decorator selectionBackgroundColor(Color foreground)
设置元素选中时的背景颜色。 请注意,此样式是在现有样式之上应用的。
Element borderHeavy(Element)
Element gaugeUp(float progress)
绘制一个从下到上推进的高清进度条。
Element focusCursorBlockBlinking(Element)
Element border(Element)
Element borderRounded(Element)
Element yframe(Element)
与 frame 相同,但仅限于 y 轴。
Element window(Element title, Element content, BorderStyle border=ROUNDED)
Decorator selectionColor(Color foreground)
设置元素选中时的颜色。
Decorator borderStyled(BorderStyle)
Element gaugeLeft(float progress)
绘制一个从右到左推进的高清进度条。
Element select(Element e)
将 child 设置为其同级元素中获得焦点的元素。
Element borderDashed(Element)
Element selectionStyleReset(Element)
重置元素的选中样式。
Element borderDouble(Element)
Decorator reflect(Box &box)
std::function< std::vector< int >(int, int)> GraphFunction
Element gridbox(std::vector< Elements > lines)
一个显示元素网格的容器。
Element focusCursorUnderline(Element)
Decorator borderWith(const Pixel &)
Elements paragraph(std::wstring text)
Element frame(Element)
允许元素显示在“虚拟”区域内。其大小可以 大于其容器。在这种情况下,只显示较小的部分。 视图是可滚动的,以使获得焦点的元素可见。
Component & operator|=(Component &component, ComponentDecorator decorator)
Element gauge(float progress)
绘制一个高清进度条。
Element vflow(Elements)
一个容器,用于从上到下在行中显示元素。当填满时,它会在右侧开始新的一列。
Element graph(GraphFunction)
使用 GraphFunction 绘制图表。
Element borderLight(Element)
Element focusCursorBarBlinking(Element)
Element gaugeDown(float progress)
绘制一个从上到下推进的高清进度条。
std::uint8_t left
std::uint8_t down
std::uint8_t right