2021-05-02 02:40:35 +08:00
|
|
|
#include <functional> // for function
|
2021-05-15 03:43:35 +08:00
|
|
|
#include <memory> // for allocator, __shared_ptr_access
|
|
|
|
#include <string> // for wstring, operator+, to_string, basic_string
|
|
|
|
#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 Menu, Horizontal, Renderer
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
|
|
|
#include "ftxui/component/menu.hpp" // for MenuBase
|
|
|
|
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
|
|
|
|
#include "ftxui/dom/elements.hpp" // for text, separator, bold, hcenter, vbox, hbox, gauge, Element, operator|, border
|
|
|
|
#include "ftxui/screen/string.hpp" // for to_wstring
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
int main(int argc, const char* argv[]) {
|
|
|
|
using namespace ftxui;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
std::vector<std::wstring> left_menu_entries = {
|
|
|
|
L"0%", L"10%", L"20%", L"30%", L"40%",
|
|
|
|
L"50%", L"60%", L"70%", L"80%", L"90%",
|
|
|
|
};
|
|
|
|
std::vector<std::wstring> right_menu_entries = {
|
|
|
|
L"0%", L"1%", L"2%", L"3%", L"4%", L"5%",
|
|
|
|
L"6%", L"7%", L"8%", L"9%", L"10%",
|
|
|
|
};
|
|
|
|
int left_menu_selected = 0;
|
|
|
|
int right_menu_selected = 0;
|
|
|
|
Component left_menu_ = Menu(&left_menu_entries, &left_menu_selected);
|
|
|
|
Component right_menu_ = Menu(&right_menu_entries, &right_menu_selected);
|
2021-05-14 06:45:03 +08:00
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
Component container = Container::Horizontal({
|
|
|
|
left_menu_,
|
|
|
|
right_menu_,
|
|
|
|
});
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2021-05-14 06:45:03 +08:00
|
|
|
auto renderer = Renderer(container, [&] {
|
2021-05-10 02:32:27 +08:00
|
|
|
int sum = left_menu_selected * 10 + right_menu_selected;
|
|
|
|
return vbox({
|
|
|
|
// -------- Top panel --------------
|
|
|
|
hbox({
|
|
|
|
// -------- Left Menu --------------
|
|
|
|
vbox({
|
|
|
|
hcenter(bold(text(L"Percentage by 10%"))),
|
|
|
|
separator(),
|
|
|
|
left_menu_->Render(),
|
|
|
|
}),
|
|
|
|
separator(),
|
|
|
|
// -------- Right Menu --------------
|
|
|
|
vbox({
|
|
|
|
hcenter(bold(text(L"Percentage by 1%"))),
|
|
|
|
separator(),
|
|
|
|
right_menu_->Render(),
|
|
|
|
}),
|
|
|
|
separator(),
|
|
|
|
}),
|
|
|
|
separator(),
|
|
|
|
// -------- Bottom panel --------------
|
|
|
|
vbox({
|
|
|
|
hbox({
|
|
|
|
text(L" gauge : "),
|
|
|
|
gauge(sum / 100.0),
|
|
|
|
}),
|
|
|
|
hbox({
|
|
|
|
text(L" text : "),
|
|
|
|
text(to_wstring(std::to_string(sum) + " %")),
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
}) |
|
|
|
|
border;
|
2021-05-14 06:45:03 +08:00
|
|
|
});
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-07 00:10:35 +08:00
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
2021-05-14 06:45:03 +08:00
|
|
|
MenuBase::From(left_menu_)->on_enter = screen.ExitLoopClosure();
|
|
|
|
MenuBase::From(right_menu_)->on_enter = screen.ExitLoopClosure();
|
|
|
|
screen.Loop(renderer);
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|
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.
|