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 "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/// @ingroup dom
40
41// 將元素串聯到裝飾器中。
42// 例如,以下幾行是等效的:
43// -> text("ftxui") | bold | underlined
44// -> underlined(bold(text("FTXUI")))
49
50// --- 小工具 ---
51Element text(std::string text);
52Element vtext(std::string text);
62Element separatorCharacter(std::string);
64 float right,
65 Color unselected_color,
66 Color selected_color);
68 float down,
69 Color unselected_color,
70 Color selected_color);
71Element gauge(float progress);
72Element gaugeLeft(float progress);
73Element gaugeRight(float progress);
74Element gaugeUp(float progress);
75Element gaugeDown(float progress);
76Element gaugeDirection(float progress, Direction direction);
88Element window(Element title, Element content, BorderStyle border = ROUNDED);
89Element spinner(int charset_index, size_t image_index);
90Element paragraph(const std::string& text);
91Element paragraphAlignLeft(const std::string& text);
92Element paragraphAlignRight(const std::string& text);
93Element paragraphAlignCenter(const std::string& text);
94Element paragraphAlignJustify(const std::string& text);
98Element canvas(int width, int height, std::function<void(Canvas&)>);
99Element canvas(std::function<void(Canvas&)>);
100
101// -- 裝飾器 ---
118Decorator focusPosition(int x, int y);
119Decorator focusPositionRelative(float x, float y);
121Decorator hyperlink(std::string link);
122Element hyperlink(std::string link, Element child);
124Decorator selectionColor(Color foreground);
127Decorator selectionStyle(std::function<void(Pixel&)> style);
128
129// --- 佈局是
130// 水平、垂直或堆疊的元素集合。
135Element gridbox(std::vector<Elements> lines);
136
137Element hflow(Elements); // Helper: default flexbox with row direction.
138Element vflow(Elements); // Helper: default flexbox with column direction.
139
140// -- 彈性 ---
141// 定義當容器中並非所有空間都被使用時,如何分享剩餘空間。
142Element flex(Element); // Expand/Minimize if possible/needed.
143Element flex_grow(Element); // Expand element if possible.
144Element flex_shrink(Element); // Minimize element if needed.
145
146Element xflex(Element); // Expand/Minimize if possible/needed on X axis.
147Element xflex_grow(Element); // Expand element if possible on X axis.
148Element xflex_shrink(Element); // Minimize element if needed on X axis.
149
150Element yflex(Element); // Expand/Minimize if possible/needed on Y axis.
151Element yflex_grow(Element); // Expand element if possible on Y axis.
152Element yflex_shrink(Element); // Minimize element if needed on Y axis.
153
154Element notflex(Element); // Reset the flex attribute.
155Element filler(); // A blank expandable element.
156
157// -- 大小覆蓋;
161
162// --- 框架 ---
163// 框架是可滾動的區域。內部區域可能大於外部區域。內部區域會滾動以使焦點元素可見。
168Element select(Element e); // Deprecated - Alias for 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
一個適配器。擁有或引用一個不可變的物件。
Definition ref.hpp:17
Decorator bgcolor(Color)
使用背景顏色進行裝飾。
Element window(Element title, Element content, BorderStyle border=ROUNDED)
繪製帶有標題和邊框的視窗。
Element borderDouble(Element)
在元素周圍繪製雙線邊框。
Element focusCursorBarBlinking(Element)
與 focus 相同,但將游標形狀設置為閃爍條狀。
Definition frame.cpp:187
Element xflex(Element)
在 X 軸上盡可能擴展/在需要時最小化。
Definition flex.cpp:146
Element gaugeDirection(float progress, Direction direction)
繪製一個指定方向的高解析度進度條。
Decorator focusPositionRelative(float x, float y)
在 frame 內部使用,這會強制視圖滾動到給定位置。該位置以請求大小的比例表示。
Element separatorStyled(BorderStyle)
在兩個元素之間繪製垂直或水平分隔線。
Element xflex_grow(Element)
在 X 軸上盡可能擴展。
Definition flex.cpp:164
Element underlinedDouble(Element)
對文字應用雙底線。
Element clear_under(Element element)
在繪製 |child| 之前,清除下方的像素。這在與 dbox 結合使用時非常有用。
Element borderDashed(Element)
在元素周圍繪製虛線邊框。
Element separatorEmpty()
使用 EMPTY 樣式在兩個元素之間繪製垂直或水平分隔線。
Element vscroll_indicator(Element)
在右側顯示一個垂直捲軸。 顏色與內容一致。
Element nothing(Element element)
一個什麼都不做的裝飾器。
Definition dom/util.cpp:28
Decorator size(WidthOrHeight, Constraint, int value)
限制元素的大小。
Direction
Direction 是一個列舉,表示四個主要方向。
Definition direction.hpp:12
Element flex(Element)
使子元素按比例擴展以佔據容器中剩餘的空間。
Definition flex.cpp:140
Element paragraphAlignRight(const std::string &text)
回傳一個在多行上繪製段落並靠右對齊的元素。
Element gaugeRight(float progress)
繪製一個從左到右進展的高解析度進度條。
Element focusCursorUnderlineBlinking(Element)
與 focus 相同,但將游標形狀設置為閃爍底線。
Definition frame.cpp:215
Element bold(Element)
使用粗體字型,用於需要更多強調的元素。
Definition bold.cpp:33
Element separatorLight()
使用 LIGHT 樣式在兩個元素之間繪製垂直或水平分隔線。
Element spinner(int charset_index, size_t image_index)
用於表示時間和/或事件的效果。這將顯示 一個 ASCII 藝術「影片」。
Element borderRounded(Element)
在元素周圍繪製圓角邊框。
Element emptyElement()
Definition dom/util.cpp:140
Element yflex(Element)
在 Y 軸上盡可能擴展/在需要時最小化。
Definition flex.cpp:152
Element flex_shrink(Element)
在需要時最小化。
Definition flex.cpp:176
Element focusCursorBar(Element)
與 focus 相同,但將游標形狀設置為靜止條狀。
Definition frame.cpp:173
Element focusCursorBlock(Element)
與 focus 相同,但將游標形狀設置為靜止方塊。
Definition frame.cpp:145
Element underlined(Element)
為給定元素加上底線。
Element center(Element)
水平與垂直置中一個元素。
Element focusCursorUnderline(Element)
與 focus 相同,但將游標形狀設置為靜止底線。
Definition frame.cpp:201
Element borderHeavy(Element)
在元素周圍繪製粗邊框。
Element inverted(Element)
添加一個濾鏡,它將反轉前景和背景 顏色。
Definition inverted.cpp:34
Element paragraphAlignCenter(const std::string &text)
回傳一個在多行上繪製段落並置中對齊的元素。
Element gaugeUp(float progress)
繪製一個從下到上進展的高解析度進度條。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element align_right(Element)
將元素靠右對齊。
Decorator focusPosition(int x, int y)
在 frame 內部使用,這會強制視圖滾動到給定位置。該位置以單元格數表示。
Element yflex_grow(Element)
在 Y 軸上盡可能擴展。
Definition flex.cpp:170
Element hscroll_indicator(Element)
在底部顯示一個水平捲軸。 顏色與內容一致。
Element flex_grow(Element)
盡可能擴展。
Definition flex.cpp:158
Element separatorDashed()
使用 DASHED 樣式在兩個元素之間繪製垂直或水平分隔線。
Element notflex(Element)
使元素不可伸縮。
Definition flex.cpp:194
Element strikethrough(Element)
對文字應用刪除線。
Element italic(Element)
將文字套用斜體。
Definition italic.cpp:16
Element dbox(Elements)
將多個元素堆疊在一起。
Element xflex_shrink(Element)
在 X 軸上在需要時最小化。
Definition flex.cpp:182
Element gaugeLeft(float progress)
繪製一個從右到左進展的高解析度進度條。
Element separatorCharacter(std::string)
在兩個元素之間繪製垂直或水平分隔線。
Element vtext(std::wstring text)
垂直顯示一段 Unicode 文字。
Definition text.cpp:220
Element borderLight(Element)
在元素周圍繪製細邊框。
Element focus(Element)
將 child 設置為其同級元素中被聚焦的元素。
Definition frame.cpp:101
Element paragraphAlignLeft(const std::string &text)
回傳一個在多行上繪製段落並靠左對齊的元素。
Decorator borderWith(const Pixel &)
與 border 相同,但在元素周圍使用恆定的像素。
Decorator borderStyled(BorderStyle)
與 border 相同,但具有不同的樣式。
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element filler()
一個元素,它會按比例擴展以佔據容器中剩餘的空間。
Definition flex.cpp:97
Element dim(Element)
使用淺色字體,適用於不那麼強調的元素。
Definition dim.cpp:33
Element automerge(Element child)
啟用字符自動與附近其他字符合併。
Definition automerge.cpp:17
Decorator hyperlink(std::string link)
使用超連結裝飾。 當用戶點擊時,連結將被開啟。 此功能僅在有限的終端模擬器中受支援。 List: https://github.com/Alhadis/OSC8-Adoption/
Definition hyperlink.cpp:70
Element blink(Element)
繪製的文字在可見和隱藏之間交替。
Definition blink.cpp:33
Element vcenter(Element)
垂直置中一個元素。
Element separatorDouble()
使用 DOUBLE 樣式在兩個元素之間繪製垂直或水平分隔線。
Element focusCursorBlockBlinking(Element)
與 focus 相同,但將游標形狀設置為閃爍方塊。
Definition frame.cpp:159
Element gauge(float progress)
繪製一個高解析度進度條。
Element paragraphAlignJustify(const std::string &text)
回傳一個在多行上繪製段落並使用左右對齊的元素。
Element border(Element)
在元素周圍繪製邊框。
Element separatorHeavy()
使用 HEAVY 樣式在兩個元素之間繪製垂直或水平分隔線。
Element borderEmpty(Element)
在元素周圍繪製空邊框。
Decorator color(Color)
使用前景顏色進行裝飾。
Element yflex_shrink(Element)
在 Y 軸上在需要時最小化。
Definition flex.cpp:188
Element hcenter(Element)
水平置中一個元素。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
BorderStyle
BorderStyle 是一個列舉,表示可以應用於終端機 UI 元素的不同邊框樣式。
Definition elements.hpp:32
Element gaugeDown(float progress)
繪製一個從上到下進展的高解析度進度條。
@ EMPTY
Definition elements.hpp:38
@ DOUBLE
Definition elements.hpp:36
@ HEAVY
Definition elements.hpp:35
@ ROUNDED
Definition elements.hpp:37
@ DASHED
Definition elements.hpp:34
@ LIGHT
Definition elements.hpp:33
畫布是與繪圖操作相關聯的可繪製緩衝區。
Definition canvas.hpp:35
FlexboxConfig 是一個配置結構,用於定義彈性盒容器的佈局屬性。
表示線性漸變顏色效果設定的類別。
Color 是一個在終端使用者介面中表示顏色的類別。
Definition color.hpp:20
Dimensions 是一個表示終端機大小的結構
Definition terminal.hpp:11
一個 Unicode 字元及其相關樣式。
Definition pixel.hpp:14
FTXUI 的 ftxui::Dimension:: 命名空間
Dimensions Fit(Element &, bool extend_beyond_screen=false)
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
WidthOrHeight
Definition elements.hpp:158
std::function< Element(Element)> Decorator
Definition elements.hpp:24
Element flexbox(Elements, FlexboxConfig config=FlexboxConfig())
一個容器,用於在行/列中顯示元素,並在滿時能夠換行到下一列/行。
Definition flexbox.cpp:249
Element separatorVSelector(float up, float down, Color unselected_color, Color selected_color)
繪製一個垂直條,其中上方/下方之間的區域以不同顏色顯示。
std::shared_ptr< Node > Element
Definition elements.hpp:22
Element xframe(Element)
與 frame 相同,但僅限於 x 軸。
Definition frame.cpp:124
Element hflow(Elements)
一個容器,用於從左到右在行中顯示元素。當填滿時,它會在下方的新行開始。
Definition flexbox.cpp:266
Decorator selectionStyle(std::function< void(Pixel &)> style)
設定元素被選取時的樣式。
Element separatorHSelector(float left, float right, Color unselected_color, Color selected_color)
繪製一個水平條,其中左右兩側之間的區域以不同顏色顯示。
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94
std::vector< Element > Elements
Definition elements.hpp:23
Decorator selectionForegroundColor(Color foreground)
設定元素被選取時的前景顏色。 請注意,此樣式會應用在現有樣式之上。
Component operator|(Component component, ComponentDecorator decorator)
Decorator selectionBackgroundColor(Color foreground)
設定元素被選取時的背景顏色。 請注意,此樣式會應用在現有樣式之上。
Element separatorRounded()
Element yframe(Element)
與 frame 相同,但僅限於 y 軸。
Definition frame.cpp:132
Decorator selectionColor(Color foreground)
設定元素被選取時的顏色。
Element select(Element e)
將 child 設置為其同級元素中被聚焦的元素。
Definition frame.cpp:108
Element selectionStyleReset(Element)
重設元素的選取樣式。
Element canvas(ConstRef< Canvas >)
Decorator reflect(Box &box)
Definition reflect.cpp:42
std::function< std::vector< int >(int, int)> GraphFunction
Definition elements.hpp:25
Element gridbox(std::vector< Elements > lines)
顯示元素網格的容器。
Elements paragraph(std::wstring text)
Element frame(Element)
允許元素顯示在「虛擬」區域內。其大小可以大於其容器。在這種情況下,只會顯示較小的一部分。視圖可滾動以使聚焦元素可見。
Definition frame.cpp:116
Component & operator|=(Component &component, ComponentDecorator decorator)
@ LESS_THAN
Definition elements.hpp:159
@ GREATER_THAN
Definition elements.hpp:159
Element vflow(Elements)
一個容器,用於從上到下在行中顯示元素。當填滿時,它會在右側的新列開始。 filled, it starts on a new row. is full, it starts a new row.
Definition flexbox.cpp:285
Element graph(GraphFunction)
使用 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