FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/selection.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni. 保留所有權利。
2// 此原始碼的使用受 MIT 授權條款約束,該條款可在 LICENSE 檔案中找到。
3#include <string> // for char_traits, operator+, string, basic_string
4
5#include "ftxui/component/component.hpp" // for Input, Renderer, Vertical
6#include "ftxui/component/component_base.hpp" // for ComponentBase
7#include "ftxui/component/component_options.hpp" // for InputOption
8#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
9#include "ftxui/dom/elements.hpp" // for text, hbox, separator, Element, operator|, vbox, border
10#include "ftxui/util/ref.hpp" // for Ref
11
12using namespace ftxui;
13
15 return vbox({
16 text("FTXUI:一個用於構建使用者介面的強大函式庫。"),
17 text("享受豐富的組件和宣告式風格。"),
18 text("以最少的工作量建立美觀且回應迅速的使用者介面。"),
19 text("加入社群,體驗 FTXUI 的強大功能。"),
20 });
21}
22
23int main() {
25
26 auto quit =
27 Button("Quit", screen.ExitLoopClosure(), ButtonOption::Animated());
28
29 int selection_change_counter = 0;
30 std::string selection_content = "";
31 screen.SelectionChange([&] {
32 selection_change_counter++;
33 selection_content = screen.GetSelection();
34 });
35
36 // 組件:
37 auto renderer = Renderer(quit, [&] {
38 return vbox({
39 text("選取已變更: " + std::to_string(selection_change_counter) +
40 " 次"),
41 text("目前選取: "),
42 paragraph(selection_content) | vscroll_indicator | frame | border |
43 size(HEIGHT, EQUAL, 10),
44 window(text("水平分割"), hbox({
45 LoremIpsum(),
46 separator(),
47 LoremIpsum(),
48 separator(),
49 LoremIpsum(),
50 })),
51 window(text("垂直分割"), vbox({
52 LoremIpsum(),
53 separator(),
54 LoremIpsum(),
55 separator(),
56 LoremIpsum(),
57 })),
58 window(text("Grid split with different style"),
59 vbox({
60 hbox({
61 LoremIpsum(),
62 separator(),
63 LoremIpsum() //
67 separator(),
69 }),
70 separator(),
71 hbox({
73 separator(),
74 LoremIpsum() | selectionStyle([](Pixel& pixel) {
75 pixel.underlined_double = true;
76 }),
77 separator(),
78 LoremIpsum(),
79 }),
80 })),
81 quit->Render(),
82 });
83 });
84
85 screen.Loop(renderer);
86}
Element LoremIpsum()
static ButtonOption Animated()
創建一個 ButtonOption,使用動畫顏色。
static ScreenInteractive TerminalOutput()
Component Button(ButtonOption options)
繪製一個按鈕。點擊時執行一個函數。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
virtual void Render(Screen &screen)
Element window(Element title, Element content, BorderStyle border=ROUNDED)
繪製帶有標題和邊框的視窗。
Decorator size(WidthOrHeight, Constraint, int value)
限制元素的大小。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Element separator()
在兩個元素之間繪製垂直或水平分隔線。
Element vbox(Elements)
一個垂直一個接一個顯示元素的容器。
Definition vbox.cpp:95
bool underlined_double
Definition pixel.hpp:33
一個 Unicode 字元及其相關樣式。
Definition pixel.hpp:14
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< Node > Element
Definition elements.hpp:22
Decorator selectionStyle(std::function< void(Pixel &)> style)
設定元素被選取時的樣式。
Element hbox(Elements)
一個逐一水平顯示元素的容器。
Definition hbox.cpp:94
Decorator selectionBackgroundColor(Color foreground)
設定元素被選取時的背景顏色。 請注意,此樣式會應用在現有樣式之上。
Decorator selectionColor(Color foreground)
設定元素被選取時的顏色。
Element selectionStyleReset(Element)
重設元素的選取樣式。
Elements paragraph(std::wstring text)