FTXUI/examples/component/nested_screen.cpp

51 lines
1.7 KiB
C++
Raw Permalink Normal View History

2023-08-19 19:56:36 +08:00
// Copyright 2020 Arthur Sonzogni. All rights reserved.
// Use of this source code is governed by the MIT license that can be found in
// the LICENSE file.
2021-09-17 02:45:26 +08:00
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
#include <string> // for operator+, string, char_traits, basic_string
2021-09-01 23:47:48 +08:00
#include "ftxui/component/captured_mouse.hpp" // for ftxui
2021-09-17 02:45:26 +08:00
#include "ftxui/component/component.hpp" // for Button, Vertical, Renderer
#include "ftxui/component/component_base.hpp" // for ComponentBase
2021-09-01 23:47:48 +08:00
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
2021-09-17 02:45:26 +08:00
#include "ftxui/dom/elements.hpp" // for separator, text, Element, operator|, vbox, border
2021-09-01 23:47:48 +08:00
using namespace ftxui;
void Nested(std::string path) {
auto screen = ScreenInteractive::FitComponent();
auto back_button = Button("Back", screen.ExitLoopClosure());
auto goto_1 = Button("Goto /1", [path] { Nested(path + "/1"); });
auto goto_2 = Button("Goto /2", [path] { Nested(path + "/2"); });
auto goto_3 = Button("Goto /3", [path] { Nested(path + "/3"); });
auto layout = Container::Vertical({
back_button,
goto_1,
goto_2,
goto_3,
});
auto renderer = Renderer(layout, [&] {
return vbox({
2021-09-17 02:45:26 +08:00
text("path: " + path),
separator(),
back_button->Render(),
goto_1->Render(),
goto_2->Render(),
goto_3->Render(),
}) |
border;
2021-09-01 23:47:48 +08:00
});
screen.Loop(renderer);
}
int main() {
2021-09-01 23:47:48 +08:00
auto screen = ScreenInteractive::FitComponent();
auto button_quit = Button("Quit", screen.ExitLoopClosure());
auto button_nested = Button("Nested", [] { Nested(""); });
screen.Loop(Container::Vertical({
2021-09-17 02:45:26 +08:00
button_quit,
button_nested,
2021-09-01 23:47:48 +08:00
}));
return 0;
}