FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
tab_horizontal.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni。保留所有权利。
2// 此源代码受 MIT 许可证的约束,该许可证可在
3// LICENSE 文件中找到。
4#include <memory> // for allocator, __shared_ptr_access, shared_ptr
5#include <string> // for string, basic_string
6#include <vector> // for vector
7
8#include "ftxui/component/captured_mouse.hpp" // for ftxui
9#include "ftxui/component/component.hpp" // for Radiobox, Renderer, Tab, Toggle, Vertical
10#include "ftxui/component/component_base.hpp" // for ComponentBase
11#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
12#include "ftxui/dom/elements.hpp" // for Element, separator, operator|, vbox, border
13
14using namespace ftxui;
15
16int main() {
17 std::vector<std::string> tab_values{
18 "tab_1",
19 "tab_2",
20 "tab_3",
21 };
22 int tab_selected = 0;
23 auto tab_toggle = Toggle(&tab_values, &tab_selected);
24
25 std::vector<std::string> tab_1_entries{
26 "Forest",
27 "Water",
28 "I don't know",
29 };
30 int tab_1_selected = 0;
31
32 std::vector<std::string> tab_2_entries{
33 "Hello",
34 "Hi",
35 "Hay",
36 };
37 int tab_2_selected = 0;
38
39 std::vector<std::string> tab_3_entries{
40 "Table",
41 "Nothing",
42 "Is",
43 "Empty",
44 };
45 int tab_3_selected = 0;
46 auto tab_container = Container::Tab(
47 {
48 Radiobox(&tab_1_entries, &tab_1_selected),
49 Radiobox(&tab_2_entries, &tab_2_selected),
50 Radiobox(&tab_3_entries, &tab_3_selected),
51 },
52 &tab_selected);
53
54 auto container = Container::Vertical({
55 tab_toggle,
56 tab_container,
57 });
58
59 auto renderer = Renderer(container, [&] {
60 return vbox({
61 tab_toggle->Render(),
62 separator(),
63 tab_container->Render(),
64 }) |
65 border;
66 });
67
69 screen.Loop(renderer);
70}
static ScreenInteractive TerminalOutput()
Component Toggle(ConstStringListRef entries, int *selected)
元素的水平列表。用戶可以瀏覽它們。
Component Radiobox(RadioboxOption options)
元素列表,其中只能选择一个。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
virtual void Render(Screen &screen)
在 ftxui::Screen 上显示元素。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
int main()