FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
component.hpp
Go to the documentation of this file.
1// Copyright 2021 Arthur Sonzogni. 版權所有。
2// 本源代碼受 MIT 許可證約束,詳情請參閱 LICENSE 文件。
3#ifndef FTXUI_COMPONENT_HPP
4#define FTXUI_COMPONENT_HPP
5
6#include <functional> // for function
7#include <memory> // for make_shared, shared_ptr
8#include <utility> // for forward
9
11#include "ftxui/component/component_base.hpp" // for Component, Components
12#include "ftxui/component/component_options.hpp" // for ButtonOption, CheckboxOption, MenuOption
13#include "ftxui/dom/elements.hpp" // for Element
14#include "ftxui/util/ref.hpp" // for ConstRef, Ref, ConstStringRef, ConstStringListRef, StringRef
15
16namespace ftxui {
17struct ButtonOption;
18struct CheckboxOption;
19struct Event;
20struct InputOption;
21struct MenuOption;
22struct RadioboxOption;
23struct MenuEntryOption;
24
25template <class T, class... Args>
26std::shared_ptr<T> Make(Args&&... args) {
27 return std::make_shared<T>(std::forward<Args>(args)...);
28}
29
30// 用於裝飾組件的管道運算符。
31using ComponentDecorator = std::function<Component(Component)>;
32using ElementDecorator = std::function<Element(Element)>;
37
38namespace Container {
40Component Vertical(Components children, int* selector);
42Component Horizontal(Components children, int* selector);
43Component Tab(Components children, int* selector);
45} // namespace Container
46
49 std::function<void()> on_click,
51
54 bool* checked,
56
57Component Input(InputOption options = {});
58Component Input(StringRef content, InputOption options = {});
59Component Input(StringRef content,
60 StringRef placeholder,
61 InputOption options = {});
62
63Component Menu(MenuOption options);
64Component Menu(ConstStringListRef entries,
65 int* selected_,
66 MenuOption options = MenuOption::Vertical());
67Component MenuEntry(MenuEntryOption options);
68Component MenuEntry(ConstStringRef label, MenuEntryOption options = {});
69
70Component Radiobox(RadioboxOption options);
71Component Radiobox(ConstStringListRef entries,
72 int* selected_,
73 RadioboxOption options = {});
74
75Component Dropdown(ConstStringListRef entries, int* selected);
76Component Dropdown(DropdownOption options);
77
78Component Toggle(ConstStringListRef entries, int* selected);
79
80// General slider constructor:
81template <typename T>
83
84// Shorthand without the `SliderOption` constructor:
86 Ref<int> value,
87 ConstRef<int> min = 0,
88 ConstRef<int> max = 100,
89 ConstRef<int> increment = 5);
91 Ref<float> value,
92 ConstRef<float> min = 0.f,
93 ConstRef<float> max = 100.f,
94 ConstRef<float> increment = 5.f);
96 Ref<long> value,
97 ConstRef<long> min = 0L,
98 ConstRef<long> max = 100L,
99 ConstRef<long> increment = 5L);
100
104Component ResizableSplitTop(Component main, Component back, int* main_size);
106
107Component Renderer(Component child, std::function<Element()>);
108Component Renderer(std::function<Element()>);
109Component Renderer(std::function<Element(bool /* focused */)>);
111
112Component CatchEvent(Component child, std::function<bool(Event)>);
113ComponentDecorator CatchEvent(std::function<bool(Event)> on_event);
114
115Component Maybe(Component, const bool* show);
116Component Maybe(Component, std::function<bool()>);
117ComponentDecorator Maybe(const bool* show);
118ComponentDecorator Maybe(std::function<bool()>);
119
120Component Modal(Component main, Component modal, const bool* show_modal);
121ComponentDecorator Modal(Component modal, const bool* show_modal);
122
124 Component child,
125 Ref<bool> show = false);
126
129 std::function<void()> on_enter,
130 std::function<void()> on_leave);
132 std::function<void(bool)> on_change);
133ComponentDecorator Hoverable(bool* hover);
134ComponentDecorator Hoverable(std::function<void()> on_enter,
135 std::function<void()> on_leave);
136ComponentDecorator Hoverable(std::function<void(bool)> on_change);
137
139
140} // namespace ftxui
141
142#endif /* end of include guard: FTXUI_COMPONENT_HPP */
一個適配器。擁有或引用一個不可變的物件。
Definition ref.hpp:17
一個適配器。擁有或引用一個常數字串。為方便起見,此類別將多個不可變字串轉換為共享表示。
Definition ref.hpp:92
一個適配器。擁有或引用一個可變的物件。
Definition ref.hpp:46
auto component
Definition gallery.cpp:127
static CheckboxOption Simple()
標準Checkbox的選項。
static ButtonOption Simple()
創建一個 ButtonOption,在聚焦時反轉。
static MenuOption Vertical()
垂直選單的標準選項。 這對於實現一個可選項目列表很有用。
Component Horizontal(Components children)
一個元件列表,水平地一個接一個繪製,並使用左/右箭頭鍵或 'h'/'l' 鍵進行水平導航。
Component Maybe(Component, const bool *show)
裝飾一個組件 |child|。它只在 |show| 為 true 時顯示。
Component ResizableSplitTop(Component main, Component back, int *main_size)
兩個元件之間的垂直分割,可透過滑鼠設定。
Component Checkbox(CheckboxOption options)
Component Menu(MenuOption options)
文字列表。選定的元素會被聚焦。
Component MenuEntry(MenuEntryOption options)
一個特定的菜單條目。它們可以放入 Container::Vertical 中以形成菜單。
Component Toggle(ConstStringListRef entries, int *selected)
元素的水平列表。使用者可以在其中導航。
Component Radiobox(RadioboxOption options)
元素清單,只能選擇一個。
Component Button(ButtonOption options)
繪製一個按鈕。點擊時執行一個函數。
Component Modal(Component main, Component modal, const bool *show_modal)
Definition modal.cpp:18
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
Component Hoverable(Component component, bool *hover)
包裝一個元件。提供能力以判斷滑鼠是否懸停在其上方。
Definition hoverable.cpp:41
Component Window(WindowOptions option)
一個可拖曳/可調整大小的視窗。要使用多個視窗,它們必須透過 Container::Stacked({...}) 元件堆疊。
Component Vertical(Components children)
一個元件列表,垂直地一個接一個繪製,並使用上/下箭頭鍵或 'j'/'k' 鍵進行垂直導航。
Component Input(InputOption options={})
用於編輯文字的輸入框。
Component ResizableSplitRight(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過滑鼠設定。
Component Dropdown(ConstStringListRef entries, int *selected)
下拉式選單。
Component Stacked(Components children)
一個元件列表,將彼此堆疊。 事件會傳播到第一個元件,如果未處理則傳播到第二個,依此類推。 元件以給定的相反順序繪製。 當一個元件獲得焦點時,它會被放到最前面,而不改變其他元素的相對順序。
Component ResizableSplitBottom(Component main, Component back, int *main_size)
兩個元件之間的垂直分割,可透過滑鼠設定。
Component ResizableSplitLeft(Component main, Component back, int *main_size)
兩個元件之間的水平分割,可透過滑鼠設定。
Component Tab(Components children, int *selector)
一個元件列表,一次只繪製一個並與之互動。|selector| 給出所選元件的索引。這對於實作分頁很有用。
AnimatedButton 元件的選項。
核取方塊元件的選項。
代表一個事件。它可以是按鍵事件、終端機大小調整,或更多...
Definition event.hpp:27
Input 元件的選項。
FTXUI ftxui::Container:: 命名空間
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< T > Make(Args &&... args)
Definition component.hpp:26
std::shared_ptr< Node > Element
Definition elements.hpp:22
std::function< Element(Element)> ElementDecorator
Definition component.hpp:32
std::vector< Component > Components
Component ResizableSplit(ResizableSplitOption options)
兩個元件之間的分隔。
Component operator|(Component component, ComponentDecorator decorator)
Component Collapsible(ConstStringRef label, Component child, Ref< bool > show=false)
可折疊元件。它顯示一個帶有箭頭的核取方塊。一旦啟用,子元件就會顯示。
Component Slider(SliderOption< T > options)
Component & operator|=(Component &component, ComponentDecorator decorator)
std::function< Component(Component)> ComponentDecorator
Definition component.hpp:31
std::shared_ptr< ComponentBase > Component
Component CatchEvent(Component child, std::function< bool(Event)>)