FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
ftxui/component

Detailed Description

請查看 ftxui/component 模組的教學。

Functions

 FTXUI_EXPORT (COMPONENT) void RequestAnimationFrame()
 RequestAnimationFrame 是一個函式,它請求在下一個動畫週期中繪製新畫面。
 
class FTXUI_EXPORT (COMPONENT) ComponentBase = {})
 它將自己實作為 ftxui::Element 進行渲染。它透過回應 ftxui::Event 來實現鍵盤導航。
 
Component Button (ButtonOption option)
 繪製一個按鈕。點擊時執行一個函式。
 
Component Button (ConstStringRef label, std::function< void()> on_click, ButtonOption option)
 繪製一個按鈕。點擊時執行一個函式。
 
Component CatchEvent (Component child, std::function< bool(Event event)> on_event)
 傳回一個元件,使用 |on_event| 來攔截事件。此函式 在事件已被處理時必須回傳 true,否則回傳 false。
 
ComponentDecorator CatchEvent (std::function< bool(Event)> on_event)
 裝飾一個元件,使用 |on_event| 來攔截事件。此函式 在事件已被處理時必須回傳 true,否則回傳 false。
 
Component Checkbox (CheckboxOption option)
 繪製可勾選的元素。
 
Component Checkbox (ConstStringRef label, bool *checked, CheckboxOption option)
 繪製可勾選的元素。
 
Component Vertical (Components children)
 一個元件列表,垂直地一個接一個繪製,並使用上/下箭頭鍵或 'j'/'k' 鍵進行垂直導航。
 
Component Vertical (Components children, int *selector)
 一個元件清單,垂直逐一繪製,並使用上下方向鍵 或 'j'/'k' 鍵進行垂直導覽。 這對於實作選單(Menu)非常有用。
 
Component Horizontal (Components children)
 一個元件清單,水平逐一繪製,並使用左右方向鍵 或 'h'/'l' 鍵進行水平導覽。
 
Component Horizontal (Components children, int *selector)
 一個元件列表,水平地一個接一個繪製,並使用左/右箭頭鍵或 'h'/'l' 鍵進行水平導航。
 
Component Tab (Components children, int *selector)
 一個元件列表,一次只繪製一個並與之互動。|selector| 給出所選元件的索引。這對於實作分頁很有用。
 
Component Stacked (Components children)
 一個元件列表,將彼此堆疊。 事件會傳播到第一個元件,如果未處理則傳播到第二個,依此類推。 元件以給定的相反順序繪製。 當一個元件獲得焦點時,它會被放到最前面,而不改變其他元素的相對順序。
 
Component Dropdown (ConstStringListRef entries, int *selected)
 下拉式選單。
 
Component Dropdown (DropdownOption option)
 下拉式選單。
 
Component Hoverable (Component component, bool *hover)
 包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
 
Component Hoverable (Component component, std::function< void()> on_enter, std::function< void()> on_leave)
 包裝一個元件。使用回呼函數。
 
ComponentDecorator Hoverable (bool *hover)
 包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
 
ComponentDecorator Hoverable (std::function< void()> on_enter, std::function< void()> on_leave)
 包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
 
Component Hoverable (Component component, std::function< void(bool)> on_change)
 包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
 
ComponentDecorator Hoverable (std::function< void(bool)> on_change)
 包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
 
Component Input (InputOption option)
 用於編輯文字的輸入框。
 
Component Input (StringRef content, InputOption option)
 用於編輯文字的輸入框。
 
Component Input (StringRef content, StringRef placeholder, InputOption option)
 用於編輯文字的輸入框。
 
Component Maybe (Component child, std::function< bool()> show)
 裝飾一個組件 |child|。它只在 |show| 返回 true 時顯示。
 
ComponentDecorator Maybe (std::function< bool()> show)
 裝飾一個組件。它只在 |show| 函數返回 true 時顯示。
 
Component Maybe (Component child, const bool *show)
 裝飾一個組件 |child|。它只在 |show| 為 true 時顯示。
 
ComponentDecorator Maybe (const bool *show)
 裝飾一個組件。它只在 |show| 為 true 時顯示。
 
Component Menu (MenuOption option)
 一份文字清單。取得焦點的元素會被選取。
 
Component Menu (ConstStringListRef entries, int *selected, MenuOption option)
 一份文字清單。取得焦點的元素會被選取。
 
Component Toggle (ConstStringListRef entries, int *selected)
 元素的水平列表。使用者可以在其中導航。
 
Component MenuEntry (ConstStringRef label, MenuEntryOption option)
 一個特定的選單項目。可以將它們放入 Container::Vertical 以 組成一個選單。
 
Component MenuEntry (MenuEntryOption option)
 一個特定的選單項目。可以將它們放入 Container::Vertical 以 組成一個選單。
 
FTXUI_EXPORT(COMPONENT) ComponentDecorator Maybe(std Component Modal (Component main, Component modal, const bool *show_modal)
 
ComponentDecorator Modal (Component modal, const bool *show_modal)
 
Component Radiobox (RadioboxOption option)
 一份元素清單,只能選取其中一個。
 
Component Radiobox (ConstStringListRef entries, int *selected, RadioboxOption option)
 一份元素清單,只能選取其中一個。
 
Component Renderer (std::function< Element()> render)
 傳回一個元件,使用 |render| 來繪製其介面。
 
Component Renderer (Component child, std::function< Element()> render)
 回傳一個新的 Component,類似 |child|,但使用 |render| 作為 Component::Render() 事件。
 
FTXUI_EXPORT(COMPONENT) Component Renderer(std Component Renderer (std::function< Element(bool)> render)
 回傳一個可聚焦的元件,使用 |render| 來渲染其介面。
 
ComponentDecorator Renderer (ElementDecorator decorator)
 透過裝飾元件所渲染的內容來裝飾該元件。
 
Component ResizableSplitLeft (Component main, Component back, int *main_size)
 兩個元件之間的水平分割,可透過 滑鼠調整大小。
 
Component ResizableSplitRight (Component main, Component back, int *main_size)
 兩個元件之間的水平分割,可透過 滑鼠調整大小。
 
Component ResizableSplitTop (Component main, Component back, int *main_size)
 兩個元件之間的垂直分割,可透過 滑鼠調整大小。
 
Component ResizableSplitBottom (Component main, Component back, int *main_size)
 兩個元件之間的垂直分割,可透過 滑鼠調整大小。
 
Component Slider (ConstStringRef label, Ref< int > value, ConstRef< int > min, ConstRef< int > max, ConstRef< int > increment)
 一個水平滑桿。
 
Component Window (WindowOptions option)
 一個可拖曳/可調整大小的視窗。要使用多個視窗,它們必須透過 Container::Stacked({...}) 元件堆疊。
 

Function Documentation

◆ FTXUI_EXPORT() [1/2]

class FTXUI_EXPORT ( COMPONENT )

RequestAnimationFrame 是一個函式,它請求在下一個動畫週期中繪製新畫面。

Note
此函式通常由需要隨時間更新其狀態或外觀的元件呼叫,例如動畫或轉場。 當變更不依賴於終端機接收到的事件,而是依賴於時間的推移時,這非常有用。

尚未完成動畫的元件可以呼叫此函式,以請求稍後繪製新畫面。

當沒有新事件且沒有動畫要完成時,不會繪製新畫面。

此動畫步驟所代表的持續時間。

此動畫步驟所代表的持續時間。

Definition at line 22 of file animation.hpp.

◆ FTXUI_EXPORT() [2/2]

template FTXUI_EXPORT ( COMPONENT ) = {})

它將自己實作為 ftxui::Element 進行渲染。它透過回應 ftxui::Event 來實現鍵盤導航。

滑鼠事件。它包含滑鼠的座標、按下的按鈕 以及修飾鍵(shift、ctrl、meta)。

Loop 是一個管理元件事件迴圈的類別。

代表一個事件。它可以是按鍵事件、終端機大小調整,或更多...

Dropdown 元件的選項。

下拉式選單是開啟/關閉單選方塊的核取方塊。

傳遞給 Window 元件渲染函式的狀態。

Radiobox 元件的選項。

Input 元件的選項。

用於定義 Input 元件的樣式。

核取方塊元件的選項。

AnimatedButton 元件的選項。

Menu 元件的選項。

MenuEntry 元件的選項。

關於潛在動畫顏色的選項。

底線效果的選項。

來自 |ButtonOption|、|CheckboxOption|、 |RadioboxOption|、|MenuEntryOption|、|MenuOption| 的轉換參數。

例如:

  • 可列印字元可以使用 Event::Character('a') 建立。
  • 一些特殊事件已預定義,例如 Event::ArrowLeft。
  • 可以使用以下方式找到特殊事件的任意程式碼: ./example/util/print_key_press 例如,CTRL+A 對應到 Event::Special({1});

有關 xterm 規範的有用文件: https://invisible-island.net/xterm/ctlseqs/ctlseqs.html

它負責執行元件、處理事件,以及 更新畫面。

Loop 類別設計用來與代表終端機畫面的 App 物件 一起使用。

範例

int main() {
auto screen = ftxui::App::TerminalOutput();
auto component = ftxui::Button("Click me", [] { ... });
ftxui::Loop loop(screen.get(), component);
// 或者
loop.Run(); // 阻塞直到元件結束。
// 或者
loop.RunOnce(); // 非阻塞,立即返回。
// 或者
loop.RunOnceBlocking(); // 阻塞直到處理一個事件為止。
// 或者在迴圈中:
while (!loop.HasQuitted()) {
loop.RunOnce();
// 做一些其他事情,例如執行不同函式庫的迴圈函式。
}
}
Component Button(ConstStringRef label, std::function< void()> on_click, ButtonOption options=ButtonOption::Simple())
繪製一個按鈕。點擊時執行一個函式。

< 要顯示的標籤。

< 按鈕/核取方塊/單選框的狀態

< 該項目是否為作用中的項目。

< 該項目是否為使用者所聚焦的項目。

< 該項目的索引(若適用),否則為 -1。

‍項目清單。

‍選取項目的索引。

‍當選取項目改變時呼叫。

‍當使用者按下 Enter 鍵時呼叫。

當使用者改變狀態時呼叫。

< 輸入框是否被滑鼠懸停。

< 輸入框是否被使用者聚焦。

< 輸入框是否為空並顯示 佔位文字。

建立預設輸入樣式:

具有高邊距的黑底白字樣式:

輸入框的內容。

輸入框為空時的內容。

< 使用 '*' 遮蔽輸入內容。

< 輸入框是否可以多行輸入。

< 插入或覆寫字元模式。

當內容改變時呼叫。

當使用者按下 Enter 鍵時呼叫。

當選取項目改變時呼叫。

< 包裹在此視窗內的元素。

< 視窗的標題。

< 該視窗是否為作用中的視窗。

< 該視窗是否正在被拖曳。

< 該視窗是否正在被調整大小。

< 可調整大小的左側邊是否被懸停。

< 可調整大小的右側邊是否被懸停。

< 可調整大小的上側邊是否被懸停。

< 可調整大小的下側邊是否被懸停。

< 此視窗所包裹的元件。

< 此視窗所顯示的標題。

< 視窗的左側位置。

< 視窗的上側位置。

< 視窗的寬度。

< 視窗的高度。

< 左側邊是否可調整大小?

< 右側邊是否可調整大小?

< 上側邊是否可調整大小?

< 下側邊是否可調整大小?

一個選用的函式,用來自訂視窗的外觀:

下拉選單是開啟還是關閉:

僅支援的終端機。

僅支援的終端機。

< 要顯示的標籤。

< 按鈕/核取方塊/單選框的狀態

< 該項目是否為作用中的項目。

< 該項目是否為使用者所聚焦的項目。

< 該項目的索引(若適用),否則為 -1。

‍項目清單。

‍選取項目的索引。

‍當選取項目改變時呼叫。

‍當使用者按下 Enter 鍵時呼叫。

當使用者改變狀態時呼叫。

< 輸入框是否被滑鼠懸停。

< 輸入框是否被使用者聚焦。

< 輸入框是否為空並顯示 佔位文字。

建立預設輸入樣式:

具有高邊距的黑底白字樣式:

輸入框的內容。

輸入框為空時的內容。

< 使用 '*' 遮蔽輸入內容。

< 輸入框是否可以多行輸入。

< 插入或覆寫字元模式。

當內容改變時呼叫。

當使用者按下 Enter 鍵時呼叫。

當選取項目改變時呼叫。

< 包裹在此視窗內的元素。

< 視窗的標題。

< 該視窗是否為作用中的視窗。

< 該視窗是否正在被拖曳。

< 該視窗是否正在被調整大小。

< 可調整大小的左側邊是否被懸停。

< 可調整大小的右側邊是否被懸停。

< 可調整大小的上側邊是否被懸停。

< 可調整大小的下側邊是否被懸停。

< 此視窗所包裹的元件。

< 此視窗所顯示的標題。

< 視窗的左側位置。

< 視窗的上側位置。

< 視窗的寬度。

< 視窗的高度。

< 左側邊是否可調整大小?

< 右側邊是否可調整大小?

< 上側邊是否可調整大小?

< 下側邊是否可調整大小?

一個選用的函式,用來自訂視窗的外觀:

下拉選單是開啟還是關閉:

僅支援的終端機。

僅支援的終端機。

Definition at line 1 of file captured_mouse.hpp.

◆ Button() [1/2]

Component Button ( ButtonOption option)

繪製一個按鈕。點擊時執行一個函式。

Parameters
option額外的可選參數。
See also
ButtonBase

範例

auto screen = App::FitComponent();
Component button = Button({
.label = "Click to quit",
.on_click = screen.ExitLoopClosure(),
});
screen.Loop(button)
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23

輸出

┌─────────────┐
│Click to quit│
└─────────────┘

Definition at line 174 of file src/ftxui/component/button.cpp.

◆ Button() [2/2]

Component Button ( ConstStringRef label,
std::function< void()> on_click,
ButtonOption option )

繪製一個按鈕。點擊時執行一個函式。

Parameters
label按鈕的標籤。
on_click點擊時要執行的動作。
option額外的可選參數。
See also
ButtonBase

範例

auto screen = App::FitComponent();
std::string label = "Click to quit";
Component button = Button(&label, screen.ExitLoopClosure());
screen.Loop(button)

輸出

┌─────────────┐
│Click to quit│
└─────────────┘

Definition at line 202 of file src/ftxui/component/button.cpp.

◆ CatchEvent() [1/2]

Component CatchEvent ( Component child,
std::function< bool(Event event)> on_event )

傳回一個元件,使用 |on_event| 來攔截事件。此函式 在事件已被處理時必須回傳 true,否則回傳 false。

Parameters
child被包裝的元件。
on_event繪製介面的函式。

範例

auto screen = App::TerminalOutput();
auto renderer = Renderer([] {
return text("My interface");
});
auto component = CatchEvent(renderer, [&](Event event) {
if (event == Event::Character('q')) {
screen.ExitLoopClosure()();
return true;
}
return false;
});
screen.Loop(component);
Component Renderer(Component child, std::function< Element()>)
回傳一個新的 Component,類似 |child|,但使用 |render| 作為 Component::Render() 事件。
Element text(std::string_view text)
顯示一段 UTF8 編碼的 Unicode 文字。
Component CatchEvent(Component child, std::function< bool(Event)>)

Definition at line 58 of file catch_event.cpp.

◆ CatchEvent() [2/2]

ComponentDecorator CatchEvent ( std::function< bool(Event)> on_event)

裝飾一個元件,使用 |on_event| 來攔截事件。此函式 在事件已被處理時必須回傳 true,否則回傳 false。

Parameters
on_event繪製介面的函式。

範例

auto screen = App::TerminalOutput();
auto renderer = Renderer([] { return text("Hello world"); });
renderer |= CatchEvent([&](Event event) {
if (event == Event::Character('q')) {
screen.ExitLoopClosure()();
return true;
}
return false;
});
screen.Loop(renderer);

Definition at line 84 of file catch_event.cpp.

◆ Checkbox() [1/2]

Component Checkbox ( CheckboxOption option)

繪製可勾選的元素。

Parameters
option額外的可選參數。
See also
CheckboxBase

範例

auto screen = App::FitComponent();
CheckboxOption option;
option.label = "Make a sandwidth";
option.checked = false;
Component checkbox = Checkbox(option);
screen.Loop(checkbox)
Component Checkbox(ConstStringRef label, bool *checked, CheckboxOption options=CheckboxOption::Simple())
繪製可勾選的元素。

輸出

☐ Make a sandwich

Definition at line 111 of file src/ftxui/component/checkbox.cpp.

◆ Checkbox() [2/2]

Component Checkbox ( ConstStringRef label,
bool * checked,
CheckboxOption option )

繪製可勾選的元素。

Parameters
label核取方塊的標籤。
checked核取方塊是否被勾選。
option額外的可選參數。
See also
CheckboxBase

範例

auto screen = App::FitComponent();
std::string label = "Make a sandwidth";
bool checked = false;
Component checkbox = Checkbox(&label, &checked);
screen.Loop(checkbox)

輸出

☐ Make a sandwich

Definition at line 138 of file src/ftxui/component/checkbox.cpp.

◆ Vertical() [1/2]

Component Vertical ( Components children)

一個元件列表,垂直地一個接一個繪製,並使用上/下箭頭鍵或 'j'/'k' 鍵進行垂直導航。

Parameters
children元件列表。
See also
ContainerBase

範例

auto container = Container::Vertical({
children_1,
children_2,
children_3,
children_4,
});
Component Vertical(Components children)
一個元件列表,垂直地一個接一個繪製,並使用上/下箭頭鍵或 'j'/'k' 鍵進行垂直導航。

Definition at line 330 of file container.cpp.

◆ Vertical() [2/2]

Component Vertical ( Components children,
int * selector )

一個元件清單,垂直逐一繪製,並使用上下方向鍵 或 'j'/'k' 鍵進行垂直導覽。 這對於實作選單(Menu)非常有用。

Parameters
children元件清單。
selector選定子項目索引的參照。
See also
ContainerBase

範例

int selected_children = 2;
auto container = Container::Vertical({
children_1,
children_2,
children_3,
children_4,
}, &selected_children);

Definition at line 353 of file container.cpp.

◆ Horizontal() [1/2]

Component Horizontal ( Components children)

一個元件清單,水平逐一繪製,並使用左右方向鍵 或 'h'/'l' 鍵進行水平導覽。

Parameters
children元件清單。
See also
ContainerBase

範例

auto container = Container::Horizontal({
children_1,
children_2,
children_3,
children_4,
});
Component Horizontal(Components children, int *selector)
一個元件列表,水平地一個接一個繪製,並使用左/右箭頭鍵或 'h'/'l' 鍵進行水平導航。

Definition at line 373 of file container.cpp.

◆ Horizontal() [2/2]

Component Horizontal ( Components children,
int * selector )

一個元件列表,水平地一個接一個繪製,並使用左/右箭頭鍵或 'h'/'l' 鍵進行水平導航。

Parameters
children元件列表。
selector所選子元件索引的參考。
See also
ContainerBase

範例

int selected_children = 2;
auto container = Container::Horizontal({
children_1,
children_2,
children_3,
children_4,
}, selected_children);

Definition at line 394 of file container.cpp.

◆ Tab()

Component Tab ( Components children,
int * selector )

一個元件列表,一次只繪製一個並與之互動。|selector| 給出所選元件的索引。這對於實作分頁很有用。

Parameters
children元件列表。
selector繪製中的子元件索引。
See also
ContainerBase

範例

int tab_drawn = 0;
auto container = Container::Tab({
children_1,
children_2,
children_3,
children_4,
}, &tab_drawn);
Component Tab(Components children, int *selector)
一個元件列表,一次只繪製一個並與之互動。|selector| 給出所選元件的索引。這對於實作分頁很有用。

Definition at line 415 of file container.cpp.

◆ Stacked()

Component Stacked ( Components children)

一個元件列表,將彼此堆疊。 事件會傳播到第一個元件,如果未處理則傳播到第二個,依此類推。 元件以給定的相反順序繪製。 當一個元件獲得焦點時,它會被放到最前面,而不改變其他元素的相對順序。

這應該與 Window 元件一起使用。

Parameters
children元件列表。
See also
Window

範例

auto container = Container::Stacked({
children_1,
children_2,
children_3,
children_4,
});
Component Stacked(Components children)
一個元件列表,將彼此堆疊。 事件會傳播到第一個元件,如果未處理則傳播到第二個,依此類推。 元件以給定的相反順序繪製。 當一個元件獲得焦點時,它會被放到最前面,而不改變其他元素的相對順序。

Definition at line 440 of file container.cpp.

◆ Dropdown() [1/2]

Component Dropdown ( ConstStringListRef entries,
int * selected )

下拉式選單。

Parameters
entries要顯示的項目清單。
selected選定項目的索引。

Definition at line 22 of file src/ftxui/component/dropdown.cpp.

◆ Dropdown() [2/2]

Component Dropdown ( DropdownOption option)

下拉式選單。

Parameters
option下拉式選單的選項。

Definition at line 33 of file src/ftxui/component/dropdown.cpp.

◆ Hoverable() [1/6]

Component Hoverable ( Component component,
bool * hover )

包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。

Parameters
component被包裝的元件。
hover反映元件是否被懸停的值。

範例

auto button = Button("exit", screen.ExitLoopClosure());
bool hover = false;
auto button_hover = Hoverable(button, &hover);
Component Hoverable(Component component, bool *hover)
包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
Definition hoverable.cpp:32

Definition at line 32 of file hoverable.cpp.

◆ Hoverable() [2/6]

Component Hoverable ( Component component,
std::function< void()> on_enter,
std::function< void()> on_leave )

包裝一個元件。使用回呼函數。

Parameters
component被包裝的元件。
on_enter進入時的回呼函數
on_leave離開時的回呼函數

範例

auto button = Button("exit", screen.ExitLoopClosure());
bool hover = false;
auto button_hover = Hoverable(button, &hover);

Definition at line 75 of file hoverable.cpp.

◆ Hoverable() [3/6]

ComponentDecorator Hoverable ( bool * hover)

包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。

Parameters
hover反映元件是否被懸停的值。

範例

bool hover = false;
auto button = Button("exit", screen.ExitLoopClosure());
button |= Hoverable(&hover);

Definition at line 129 of file hoverable.cpp.

◆ Hoverable() [4/6]

ComponentDecorator Hoverable ( std::function< void()> on_enter,
std::function< void()> on_leave )

包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。

Parameters
on_enter當滑鼠懸停在元件上時呼叫。
on_leave當滑鼠離開元件時呼叫。

範例

auto button = Button("exit", screen.ExitLoopClosure());
int on_enter_cnt = 0;
int on_leave_cnt = 0;
button |= Hoverable(
[&]{ on_enter_cnt++; },
[&]{ on_leave_cnt++; }
);

Definition at line 152 of file hoverable.cpp.

◆ Hoverable() [5/6]

Component Hoverable ( Component component,
std::function< void(bool)> on_change )

包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。

Parameters
component被包裝的元件。
on_change當滑鼠進入或離開元件時呼叫。

範例

auto button = Button("exit", screen.ExitLoopClosure());
bool hovered = false;
auto button_hoverable = Hoverable(button,
[&](bool hover) { hovered = hover;});

Definition at line 174 of file hoverable.cpp.

◆ Hoverable() [6/6]

ComponentDecorator Hoverable ( std::function< void(bool)> on_change)

包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。

Parameters
on_change當滑鼠進入或離開元件時呼叫。

範例

auto button = Button("exit", screen.ExitLoopClosure());
bool hovered = false;
button |= Hoverable([&](bool hover) { hovered = hover;});

Definition at line 194 of file hoverable.cpp.

◆ Input() [1/3]

Component Input ( InputOption option)

用於編輯文字的輸入框。

Parameters
option額外的可選參數。
See also
InputBase

範例

auto screen = App::FitComponent();
std::string content= "";
std::string placeholder = "placeholder";
Component input = Input({
.content = &content,
.placeholder = &placeholder,
})
screen.Loop(input);
Component Input(StringRef content, InputOption options={})
用於編輯文字的輸入框。

輸出

placeholder

Definition at line 590 of file src/ftxui/component/input.cpp.

◆ Input() [2/3]

Component Input ( StringRef content,
InputOption option )

用於編輯文字的輸入框。

Parameters
content可編輯的內容。
option額外的可選參數。
See also
InputBase

範例

auto screen = App::FitComponent();
std::string content= "";
std::string placeholder = "placeholder";
Component input = Input(content, {
.placeholder = &placeholder,
.password = true,
})
screen.Loop(input);

輸出

placeholder

Definition at line 618 of file src/ftxui/component/input.cpp.

◆ Input() [3/3]

Component Input ( StringRef content,
StringRef placeholder,
InputOption option )

用於編輯文字的輸入框。

Parameters
content可編輯的內容。
placeholder佔位符文字。
option額外的可選參數。
See also
InputBase

範例

auto screen = App::FitComponent();
std::string content= "";
std::string placeholder = "placeholder";
Component input = Input(content, placeholder);
screen.Loop(input);

輸出

placeholder

Definition at line 645 of file src/ftxui/component/input.cpp.

◆ Maybe() [1/4]

Component Maybe ( Component child,
std::function< bool()> show )

裝飾一個組件 |child|。它只在 |show| 返回 true 時顯示。

Parameters
child要裝飾的組件。
show一個函數,返回是否應顯示 |child|。

Definition at line 20 of file src/ftxui/component/maybe.cpp.

◆ Maybe() [2/4]

ComponentDecorator Maybe ( std::function< bool()> show)

裝飾一個組件。它只在 |show| 函數返回 true 時顯示。

Parameters
show一個函數,返回是否應顯示被裝飾的組件。

範例

auto component = Renderer([]{ return text("Hello World!"); });
auto maybe_component = component | Maybe([&]{ return counter == 42; });
Component Maybe(Component child, std::function< bool()> show)
裝飾一個組件 |child|。它只在 |show| 返回 true 時顯示。

Definition at line 54 of file src/ftxui/component/maybe.cpp.

◆ Maybe() [3/4]

Component Maybe ( Component child,
const bool * show )

裝飾一個組件 |child|。它只在 |show| 為 true 時顯示。

Parameters
child要裝飾的組件。
show一個布林值。當 |show| 為 true 時,顯示 |child|。

範例

auto component = Renderer([]{ return text("Hello World!"); });
auto maybe_component = Maybe(component, &show);
const bool * show

Definition at line 71 of file src/ftxui/component/maybe.cpp.

◆ Maybe() [4/4]

ComponentDecorator Maybe ( const bool * show)

裝飾一個組件。它只在 |show| 為 true 時顯示。

Parameters
show一個布林值。當 |show| 為 true 時,顯示 |child|。

範例

auto component = Renderer([]{ return text("Hello World!"); });
auto maybe_component = component | Maybe(&show);

Definition at line 85 of file src/ftxui/component/maybe.cpp.

◆ Menu() [1/2]

Component Menu ( MenuOption option)

一份文字清單。取得焦點的元素會被選取。

Parameters
option包含所有參數的結構。

範例

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Menu({
.entries = &entries,
.selected = &selected,
});
screen.Loop(menu);
Component Menu(ConstStringListRef entries, int *selected_, MenuOption options=MenuOption::Vertical())
一份文字清單。取得焦點的元素會被選取。

輸出

> entry 1
entry 2
entry 3

Definition at line 505 of file src/ftxui/component/menu.cpp.

◆ Menu() [2/2]

Component Menu ( ConstStringListRef entries,
int * selected,
MenuOption option )

一份文字清單。取得焦點的元素會被選取。

Parameters
entries選單中的項目清單。
selected目前選定元素的索引。
option額外的可選參數。

範例

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Menu(&entries, &selected);
screen.Loop(menu);

輸出

> entry 1
entry 2
entry 3

Definition at line 536 of file src/ftxui/component/menu.cpp.

◆ Toggle()

Component Toggle ( ConstStringListRef entries,
int * selected )

元素的水平列表。使用者可以在其中導航。

Parameters
entries要顯示的可選條目列表。
selected參考選定的條目。 另請參閱 |Menu|。

Definition at line 547 of file src/ftxui/component/menu.cpp.

◆ MenuEntry() [1/2]

Component MenuEntry ( ConstStringRef label,
MenuEntryOption option )

一個特定的選單項目。可以將它們放入 Container::Vertical 以 組成一個選單。

Parameters
label代表此元素所繪製的文字。
option額外的可選參數。

範例

auto screen = App::TerminalOutput();
int selected = 0;
auto menu = Container::Vertical({
MenuEntry("entry 1"),
MenuEntry("entry 2"),
MenuEntry("entry 3"),
}, &selected);
screen.Loop(menu);
Component MenuEntry(ConstStringRef label, MenuEntryOption options={})
一個特定的選單項目。可以將它們放入 Container::Vertical 以 組成一個選單。

輸出

> entry 1
entry 2
entry 3

Definition at line 577 of file src/ftxui/component/menu.cpp.

◆ MenuEntry() [2/2]

Component MenuEntry ( MenuEntryOption option)

一個特定的選單項目。可以將它們放入 Container::Vertical 以 組成一個選單。

Parameters
option參數。

範例

auto screen = App::TerminalOutput();
int selected = 0;
auto menu = Container::Vertical({
MenuEntry({.label = "entry 1"}),
MenuEntry({.label = "entry 2"}),
MenuEntry({.label = "entry 3"}),
}, &selected);
screen.Loop(menu);

輸出

> entry 1
entry 2
entry 3

Definition at line 607 of file src/ftxui/component/menu.cpp.

◆ Modal() [1/2]

Component Modal ( Component main,
Component modal,
const bool * show_modal )

Definition at line 18 of file modal.cpp.

◆ Modal() [2/2]

ComponentDecorator Modal ( Component modal,
const bool * show_modal )

Definition at line 58 of file modal.cpp.

◆ Radiobox() [1/2]

Component Radiobox ( RadioboxOption option)

一份元素清單,只能選取其中一個。

Parameters
option參數
See also
RadioboxBase

範例

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Radiobox({
.entries = entries,
.selected = &selected,
});
screen.Loop(menu);
Component Radiobox(ConstStringListRef entries, int *selected_, RadioboxOption options={})
一份元素清單,只能選取其中一個。

輸出

◉ entry 1
○ entry 2
○ entry 3

NOLINTNEXTLINE

Definition at line 204 of file src/ftxui/component/radiobox.cpp.

◆ Radiobox() [2/2]

Component Radiobox ( ConstStringListRef entries,
int * selected,
RadioboxOption option )

一份元素清單,只能選取其中一個。

Parameters
entries清單中的項目清單。
selected目前選定元素的索引。
option額外的可選參數。
See also
RadioboxBase

範例

auto screen = App::TerminalOutput();
std::vector<std::string> entries = {
"entry 1",
"entry 2",
"entry 3",
};
int selected = 0;
auto menu = Radiobox(&entries, &selected);
screen.Loop(menu);

輸出

◉ entry 1
○ entry 2
○ entry 3

Definition at line 236 of file src/ftxui/component/radiobox.cpp.

◆ Renderer() [1/4]

Component Renderer ( std::function< Element()> render)

傳回一個元件,使用 |render| 來繪製其介面。

Parameters
render繪製介面的函式。

範例

auto screen = App::TerminalOutput();
auto renderer = Renderer([] {
return text("My interface");
});
screen.Loop(renderer);

Definition at line 29 of file src/ftxui/component/renderer.cpp.

◆ Renderer() [2/4]

Component Renderer ( Component child,
std::function< Element()> render )

回傳一個新的 Component,類似 |child|,但使用 |render| 作為 Component::Render() 事件。

Parameters
child用來轉發事件的元件。
render繪製介面的函式。

範例

auto screen = App::TerminalOutput();
std::string label = "Click to quit";
auto button = Button(&label, screen.ExitLoopClosure());
auto renderer = Renderer(button, [&] {
return hbox({
text("A button:"),
button->Render(),
});
});
screen.Loop(renderer);
Element hbox(Elements children)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94

Definition at line 61 of file src/ftxui/component/renderer.cpp.

◆ Renderer() [3/4]

Component Renderer ( std::function< Element(bool)> render)

回傳一個可聚焦的元件,使用 |render| 來渲染其介面。

Parameters
render繪製介面的函式,接受一個布林值來表示 元件是否已聚焦。

範例

auto screen = App::TerminalOutput();
auto renderer = Renderer([] (bool focused) {
if (focused)
return text("My interface") | inverted;
else
return text("My interface");
});
screen.Loop(renderer);
Element inverted(Element child)
添加一個濾鏡,它將反轉前景和背景 顏色。
Definition inverted.cpp:34

Definition at line 84 of file src/ftxui/component/renderer.cpp.

◆ Renderer() [4/4]

ComponentDecorator Renderer ( ElementDecorator decorator)

透過裝飾元件所渲染的內容來裝飾該元件。

Parameters
decorator修改所渲染元素的函式。

範例

auto screen = App::TerminalOutput();
auto renderer =
Renderer([] { return text("Hello"); })
| Renderer(bold)
| Renderer(inverted);
screen.Loop(renderer);

Definition at line 125 of file src/ftxui/component/renderer.cpp.

◆ ResizableSplitLeft()

Component ResizableSplitLeft ( Component main,
Component back,
int * main_size )

兩個元件之間的水平分割,可透過 滑鼠調整大小。

Parameters
main大小為 |main_size| 的主元件,位於左側。
back佔用剩餘空間的次元件,位於右側。
main_size|main| 元件的大小。

範例

auto screen = App::Fullscreen();
int left_size = 10;
auto left = Renderer([] { return text("Left") | center;});
auto right = Renderer([] { return text("right") | center;});
auto split = ResizableSplitLeft(left, right, &left_size);
screen.Loop(split);
Component ResizableSplitLeft(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過 滑鼠調整大小。
Element center(Element child)
水平與垂直置中一個元素。
std::uint8_t left
Definition screen.cpp:147
std::uint8_t right
Definition screen.cpp:149

輸出

│
left │ right
│

Definition at line 199 of file src/ftxui/component/resizable_split.cpp.

◆ ResizableSplitRight()

Component ResizableSplitRight ( Component main,
Component back,
int * main_size )

兩個元件之間的水平分割,可透過 滑鼠調整大小。

Parameters
main大小為 |main_size| 的主元件,位於右側。
back佔用剩餘空間的次元件,位於左側。
main_size|main| 元件的大小。

範例

auto screen = App::Fullscreen();
int right_size = 10;
auto left = Renderer([] { return text("Left") | center;});
auto right = Renderer([] { return text("right") | center;});
auto split = ResizableSplitRight(right, left, &right_size)
screen.Loop(split);
Component ResizableSplitRight(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過 滑鼠調整大小。

輸出

│
left │ right
│

Definition at line 233 of file src/ftxui/component/resizable_split.cpp.

◆ ResizableSplitTop()

Component ResizableSplitTop ( Component main,
Component back,
int * main_size )

兩個元件之間的垂直分割,可透過 滑鼠調整大小。

Parameters
main大小為 |main_size| 的主元件,位於上方。
back佔用剩餘空間的次元件,位於下方。
main_size|main| 元件的大小。

範例

auto screen = App::Fullscreen();
int top_size = 1;
auto top = Renderer([] { return text("Top") | center;});
auto bottom = Renderer([] { return text("Bottom") | center;});
auto split = ResizableSplitTop(top, bottom, &top_size)
screen.Loop(split);
Component ResizableSplitTop(Component main, Component back, int *main_size)
兩個元件之間的垂直分割,可透過 滑鼠調整大小。
std::uint8_t top
Definition screen.cpp:148

輸出

top
────────────
bottom

Definition at line 267 of file src/ftxui/component/resizable_split.cpp.

◆ ResizableSplitBottom()

Component ResizableSplitBottom ( Component main,
Component back,
int * main_size )

兩個元件之間的垂直分割,可透過 滑鼠調整大小。

Parameters
main大小為 |main_size| 的主元件,位於下方。
back佔用剩餘空間的次元件,位於上方。
main_size|main| 元件的大小。

範例

auto screen = App::Fullscreen();
int bottom_size = 1;
auto top = Renderer([] { return text("Top") | center;});
auto bottom = Renderer([] { return text("Bottom") | center;});
auto split = ResizableSplit::Bottom(bottom, top, &bottom_size)
screen.Loop(split);

輸出

top
────────────
bottom

Definition at line 301 of file src/ftxui/component/resizable_split.cpp.

◆ Slider()

Component Slider ( ConstStringRef label,
Ref< int > value,
ConstRef< int > min,
ConstRef< int > max,
ConstRef< int > increment )

一個水平滑桿。

Parameters
label滑桿的名稱。
value滑桿目前的值。
min最小值。
max最大值。
increment游標使用時的增量。

範例

auto screen = App::TerminalOutput();
int value = 50;
auto slider = Slider("Value:", &value, 0, 100, 1);
screen.Loop(slider);
Component Slider(SliderOption< T > options)
任意方向的滑桿。
int value
Definition elements.hpp:192

輸出

Value:[██████████████████████████ ]

Definition at line 258 of file src/ftxui/component/slider.cpp.

◆ Window()

Component Window ( WindowOptions option)

一個可拖曳/可調整大小的視窗。要使用多個視窗,它們必須透過 Container::Stacked({...}) 元件堆疊。

Parameters
option包含所有參數的結構。
See also
Window

範例

auto window_1= Window({
.inner = DummyWindowContent(),
.title = "First window",
});
auto window_2= Window({
.inner = DummyWindowContent(),
.title = "Second window",
});
auto container = Container::Stacked({
window_1,
window_2,
});
Component Window(WindowOptions option)
一個可拖曳/可調整大小的視窗。要使用多個視窗,它們必須透過 Container::Stacked({...}) 元件堆疊。
Component DummyWindowContent()
Definition scrollbar.cpp:10

Definition at line 312 of file src/ftxui/component/window.cpp.