2018-10-10 01:06:03 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
|
|
|
#include "ftxui/component/component_horizontal.hpp"
|
|
|
|
#include "ftxui/component/component_vertical.hpp"
|
2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/component/screen_interactive.hpp"
|
|
|
|
#include "ftxui/component/toggle.hpp"
|
2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/util/string.hpp"
|
|
|
|
|
|
|
|
using namespace ftxui::component;
|
|
|
|
using namespace ftxui::dom;
|
|
|
|
|
|
|
|
class MyComponent : ComponentVertical {
|
|
|
|
public:
|
2019-01-07 00:10:35 +08:00
|
|
|
MyComponent(Delegate* delegate)
|
2018-10-10 01:06:03 +08:00
|
|
|
: ComponentVertical(delegate),
|
|
|
|
toggle_1(delegate->NewChild()),
|
|
|
|
toggle_2(delegate->NewChild()),
|
2019-01-03 07:35:59 +08:00
|
|
|
toggle_3(delegate->NewChild()),
|
|
|
|
toggle_4(delegate->NewChild()) {
|
|
|
|
toggle_1.options = {L"On", L"Off"};
|
|
|
|
toggle_2.options = {L"Enabled", L"Disabled"};
|
|
|
|
toggle_3.options = {L"10€", L"0€"};
|
|
|
|
toggle_4.options = {L"Nothing", L"One element", L"Several elements"};
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
Focus(&toggle_1);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void()> on_enter = []() {};
|
|
|
|
|
|
|
|
private:
|
|
|
|
Toggle toggle_1;
|
|
|
|
Toggle toggle_2;
|
|
|
|
Toggle toggle_3;
|
2019-01-03 07:35:59 +08:00
|
|
|
Toggle toggle_4;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
|
|
|
Element Render() override {
|
|
|
|
return
|
|
|
|
vbox(
|
|
|
|
text(L"Choose your options:"),
|
|
|
|
text(L""),
|
|
|
|
hbox(text(L" * Poweroff on startup : "), toggle_1.Render()),
|
|
|
|
hbox(text(L" * Out of process : "), toggle_2.Render()),
|
2019-01-03 07:35:59 +08:00
|
|
|
hbox(text(L" * Price of the information : "), toggle_3.Render()),
|
|
|
|
hbox(text(L" * Number of elements : "), toggle_4.Render())
|
2018-10-10 01:06:03 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-10-19 04:58:38 +08:00
|
|
|
bool OnEvent(Event event) override {
|
|
|
|
if (ComponentVertical::OnEvent(event))
|
2018-10-10 01:06:03 +08:00
|
|
|
return true;
|
|
|
|
|
2018-10-19 04:58:38 +08:00
|
|
|
if (event == Event::Return) {
|
2018-10-10 01:06:03 +08:00
|
|
|
on_enter();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
2019-01-07 00:10:35 +08:00
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
2018-10-10 01:06:03 +08:00
|
|
|
MyComponent component(screen.delegate());
|
|
|
|
component.on_enter = screen.ExitLoopClosure();
|
|
|
|
screen.Loop();
|
|
|
|
}
|