2021-08-09 05:25:20 +08:00
|
|
|
#include <memory> // for allocator, shared_ptr, __shared_ptr_access
|
|
|
|
#include <string> // for wstring, basic_string, char_traits, operator+
|
2021-05-10 02:32:27 +08:00
|
|
|
#include <vector> // for vector
|
2021-05-02 02:40:35 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/captured_mouse.hpp" // for ftxui
|
2021-05-15 03:43:35 +08:00
|
|
|
#include "ftxui/component/component.hpp" // for Button, Renderer, Horizontal, Tab
|
|
|
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
|
|
|
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
|
2021-08-09 05:25:20 +08:00
|
|
|
#include "ftxui/dom/deprecated.hpp" // for text
|
|
|
|
#include "ftxui/dom/elements.hpp" // for operator|, Element, filler, hbox, separator, center, vbox, bold, border, clear_under, dbox, size, GREATER_THAN, HEIGHT
|
2020-08-26 23:58:18 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
using namespace ftxui;
|
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
2021-05-10 02:32:27 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
// There are two layers. One at depth = 0 and the modal window at depth = 1;
|
|
|
|
int depth = 0;
|
2021-05-10 02:32:27 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
// The current rating of FTXUI.
|
2021-05-10 02:32:27 +08:00
|
|
|
std::wstring rating = L"3/5 stars";
|
2020-08-26 23:58:18 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
// At depth=0, two buttons. One for rating FTXUI and one for quitting.
|
2021-05-15 03:43:35 +08:00
|
|
|
auto button_rate_ftxui = Button("Rate FTXUI", [&] { depth = 1; });
|
|
|
|
auto button_quit = Button("Quit", screen.ExitLoopClosure());
|
2020-08-26 23:58:18 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
auto depth_0_container = Container::Horizontal({
|
|
|
|
button_rate_ftxui,
|
|
|
|
button_quit,
|
|
|
|
});
|
|
|
|
auto depth_0_renderer = Renderer(depth_0_container, [&] {
|
|
|
|
return vbox({
|
|
|
|
text(L"Modal dialog example"),
|
|
|
|
separator(),
|
|
|
|
text(L"☆☆☆ FTXUI:" + rating + L" ☆☆☆") | bold,
|
|
|
|
filler(),
|
|
|
|
hbox({
|
|
|
|
button_rate_ftxui->Render(),
|
|
|
|
filler(),
|
|
|
|
button_quit->Render(),
|
|
|
|
}),
|
|
|
|
}) |
|
|
|
|
border | size(HEIGHT, GREATER_THAN, 18) | center;
|
2021-05-10 02:32:27 +08:00
|
|
|
});
|
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
// At depth=1, The "modal" window.
|
|
|
|
std::vector<std::wstring> rating_labels = {
|
|
|
|
L"1/5 stars", L"2/5 stars", L"3/5 stars", L"4/5 stars", L"5/5 stars",
|
|
|
|
};
|
|
|
|
auto on_rating = [&](std::wstring new_rating) {
|
|
|
|
rating = new_rating;
|
|
|
|
depth = 0;
|
|
|
|
};
|
|
|
|
auto depth_1_container = Container::Horizontal({
|
|
|
|
Button(&rating_labels[0], [&] { on_rating(rating_labels[0]); }),
|
|
|
|
Button(&rating_labels[1], [&] { on_rating(rating_labels[1]); }),
|
|
|
|
Button(&rating_labels[2], [&] { on_rating(rating_labels[2]); }),
|
|
|
|
Button(&rating_labels[3], [&] { on_rating(rating_labels[3]); }),
|
|
|
|
Button(&rating_labels[4], [&] { on_rating(rating_labels[4]); }),
|
|
|
|
});
|
2020-08-26 23:58:18 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
auto depth_1_renderer = Renderer(depth_1_container, [&] {
|
2020-08-26 23:58:18 +08:00
|
|
|
return vbox({
|
|
|
|
text(L"Do you like FTXUI?"),
|
|
|
|
separator(),
|
2021-05-14 06:45:03 +08:00
|
|
|
hbox(depth_1_container->Render()),
|
2020-08-26 23:58:18 +08:00
|
|
|
}) |
|
|
|
|
border;
|
2021-05-14 06:45:03 +08:00
|
|
|
});
|
2021-05-10 02:32:27 +08:00
|
|
|
|
2021-05-15 08:32:42 +08:00
|
|
|
auto main_container = Container::Tab(
|
|
|
|
{
|
|
|
|
depth_0_renderer,
|
|
|
|
depth_1_renderer,
|
|
|
|
},
|
|
|
|
&depth);
|
2020-08-26 23:58:18 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
auto main_renderer = Renderer(main_container, [&] {
|
|
|
|
Element document = depth_0_renderer->Render();
|
2021-05-10 02:32:27 +08:00
|
|
|
|
|
|
|
if (depth == 1) {
|
2020-08-26 23:58:18 +08:00
|
|
|
document = dbox({
|
|
|
|
document,
|
2021-05-14 06:45:03 +08:00
|
|
|
depth_1_renderer->Render() | clear_under | center,
|
2020-08-26 23:58:18 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
return document;
|
2021-05-14 06:45:03 +08:00
|
|
|
});
|
2020-08-26 23:58:18 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
screen.Loop(main_renderer);
|
2020-08-26 23:58:18 +08:00
|
|
|
return 0;
|
|
|
|
}
|
2020-09-06 19:46:56 +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.
|