FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
examples/component/maybe.cpp
浏览该文件的文档.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
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 Radiobox(RadioboxOption options)
元素列表,其中只能选择一个。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
Component Checkbox(CheckboxOption options)
绘制可勾选元素。
Element text(std::wstring text)
显示一段Unicode文本。
Decorator color(Color)
使用前景色进行装饰。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase