FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
nested_screen.cpp
浏览该文件的文档.
1// 版权所有 2020 Arthur Sonzogni。保留所有权利。
2// 此源代码的使用受 MIT 许可证的约束,
3// 该许可证可在 LICENSE 文件中找到。
4#include <memory> // for allocator, shared_ptr, __shared_ptr_access
5#include <string> // for operator+, string, char_traits, basic_string
6
7#include "ftxui/component/captured_mouse.hpp" // for ftxui
8#include "ftxui/component/component.hpp" // for Button, Vertical, Renderer
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
11#include "ftxui/dom/elements.hpp" // for separator, text, Element, operator|, vbox, border
12
13using namespace ftxui;
14
15void Nested(std::string path) {
16 auto screen = ScreenInteractive::FitComponent();
17 auto back_button = Button("Back", screen.ExitLoopClosure());
18 auto goto_1 = Button("Goto /1", [path] { Nested(path + "/1"); });
19 auto goto_2 = Button("Goto /2", [path] { Nested(path + "/2"); });
20 auto goto_3 = Button("Goto /3", [path] { Nested(path + "/3"); });
21 auto layout = Container::Vertical({
22 back_button,
23 goto_1,
24 goto_2,
25 goto_3,
26 });
27 auto renderer = Renderer(layout, [&] {
28 return vbox({
29 text("path: " + path),
30 separator(),
31 back_button->Render(),
32 goto_1->Render(),
33 goto_2->Render(),
34 goto_3->Render(),
35 }) |
36 border;
37 });
38 screen.Loop(renderer);
39}
40
41int main() {
42 auto screen = ScreenInteractive::FitComponent();
43 auto button_quit = Button("Quit", screen.ExitLoopClosure());
44 auto button_nested = Button("Nested", [] { Nested(""); });
45 screen.Loop(Container::Vertical({
46 button_quit,
47 button_nested,
48 }));
49 return 0;
50}
static ScreenInteractive FitComponent()
创建一个 ScreenInteractive,其宽度和高度与正在绘制的组件匹配。
Component Button(ButtonOption options)
绘制一个按钮。点击时执行一个函数。
Component Renderer(Component child, std::function< Element()>)
返回一个新组件,类似于 |child|,但使用 |render| 作为 Component::Render() 事件。
virtual void Render(Screen &screen)
在 ftxui::Screen 上显示元素。
Element text(std::wstring text)
显示一段Unicode文本。
Element separator()
在两个其他元素之间绘制垂直或水平分隔线。
Element vbox(Elements)
垂直一个接一个显示元素的容器。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
void Nested(std::string path)
int main()