FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
examples/component/maybe.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni。保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,詳情請參閱 LICENSE 檔案。
3#include <string> // for string, allocator, basic_string
4#include <vector> // for vector
5
6#include "ftxui/component/captured_mouse.hpp" // for ftxui
7#include "ftxui/component/component.hpp" // for operator|, Maybe, Checkbox, Radiobox, Renderer, Vertical
8#include "ftxui/component/component_base.hpp" // for Component
9#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
10#include "ftxui/dom/elements.hpp" // for Element, border, color, operator|, text
11#include "ftxui/screen/color.hpp" // for Color, Color::Red
12
13using namespace ftxui;
14
15int main() {
16 std::vector<std::string> entries = {
17 "entry 1",
18 "entry 2",
19 "entry 3",
20 };
21 int menu_1_selected = 0;
22 int menu_2_selected = 0;
23
24 bool menu_1_show = false;
25 bool menu_2_show = false;
26
27 auto layout = Container::Vertical({
28 Checkbox("Show menu_1", &menu_1_show),
29 Radiobox(&entries, &menu_1_selected) | border | Maybe(&menu_1_show),
30 Checkbox("Show menu_2", &menu_2_show),
31 Radiobox(&entries, &menu_2_selected) | border | Maybe(&menu_2_show),
32
33 Renderer([] {
34 return text("You found the secret combinaison!") | color(Color::Red);
35 }) | Maybe([&] { return menu_1_selected == 1 && menu_2_selected == 2; }),
36 });
37
39 screen.Loop(layout);
40}
static ScreenInteractive TerminalOutput()
Component Maybe(Component, const bool *show)
裝飾一個組件 |child|。它只在 |show| 為 true 時顯示。
Component Checkbox(CheckboxOption options)
Component Radiobox(RadioboxOption options)
元素清單,只能選擇一個。
Component Renderer(Component child, std::function< Element()>)
回傳一個新的元件,類似於 |child|,但使用 |render| 作為 Component::Render() 事件。
Element text(std::wstring text)
顯示一段 Unicode 文字。
Definition text.cpp:160
Decorator color(Color)
使用前景顏色進行裝飾。
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10