FTXUI/examples/component/menu2.cpp

79 lines
2.0 KiB
C++
Raw Normal View History

#include <chrono>
#include <iostream>
#include <thread>
2019-01-13 01:24:46 +08:00
#include "ftxui/component/container.hpp"
#include "ftxui/component/menu.hpp"
#include "ftxui/component/screen_interactive.hpp"
2019-01-13 01:24:46 +08:00
#include "ftxui/screen/string.hpp"
using namespace ftxui;
2019-01-13 01:24:46 +08:00
class MyComponent : public Component {
2020-03-23 05:32:44 +08:00
public:
MyComponent() {
Add(&container);
container.Add(&left_menu);
container.Add(&right_menu);
2019-01-13 01:24:46 +08:00
2020-03-23 05:32:44 +08:00
left_menu.entries = {
L"0%", L"10%", L"20%", L"30%", L"40%",
L"50%", L"60%", L"70%", L"80%", L"90%",
};
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%",
};
2020-03-23 05:32:44 +08:00
left_menu.on_enter = [this]() { on_enter(); };
right_menu.on_enter = [this]() { on_enter(); };
}
std::function<void()> on_enter = []() {};
2020-03-23 05:32:44 +08:00
private:
Container container = Container::Horizontal();
Menu left_menu;
Menu right_menu;
2020-03-23 05:32:44 +08:00
// clang-format off
Element Render() override {
int sum = left_menu.selected * 10 + right_menu.selected;
return
2019-01-20 05:06:05 +08:00
border(
vbox(
// -------- Top panel --------------
hbox(
// -------- Left Menu --------------
vbox(
hcenter(bold(text(L"Percentage by 10%"))),
separator(),
left_menu.Render()
) | flex,
// -------- Right Menu --------------
vbox(
hcenter(bold(text(L"Percentage by 1%"))),
separator(),
right_menu.Render()
) | flex,
filler()
),
separator(),
// -------- Bottom panel --------------
vbox(
hbox(text(L" gauge : "), gauge(sum/100.0)),
hbox(text(L" text : "), text(to_wstring(std::to_string(sum) + " %")))
) | flex
)
);
}
2020-03-23 05:32:44 +08:00
// clang-format on
};
2020-03-23 05:32:44 +08:00
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::TerminalOutput();
2019-01-13 01:24:46 +08:00
MyComponent component;
component.on_enter = screen.ExitLoopClosure();
2019-01-13 01:24:46 +08:00
screen.Loop(&component);
}