2020-04-20 03:00:37 +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.
|
|
|
|
|
2020-03-23 05:32:44 +08:00
|
|
|
#include "ftxui/component/toggle.hpp"
|
|
|
|
|
2018-10-10 01:06:03 +08:00
|
|
|
#include <chrono>
|
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
#include "ftxui/component/container.hpp"
|
2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/component/screen_interactive.hpp"
|
2019-01-13 01:24:46 +08:00
|
|
|
#include "ftxui/screen/string.hpp"
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using namespace ftxui;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
class MyComponent : public Component {
|
2018-10-10 01:06:03 +08:00
|
|
|
public:
|
2019-01-13 01:24:46 +08:00
|
|
|
MyComponent() {
|
2019-01-13 05:25:49 +08:00
|
|
|
Add(&container_);
|
|
|
|
container_.Add(&toggle_1_);
|
|
|
|
container_.Add(&toggle_2_);
|
|
|
|
container_.Add(&toggle_3_);
|
|
|
|
container_.Add(&toggle_4_);
|
|
|
|
|
|
|
|
toggle_1_.entries = {L"On", L"Off"};
|
|
|
|
toggle_2_.entries = {L"Enabled", L"Disabled"};
|
|
|
|
toggle_3_.entries = {L"10€", L"0€"};
|
|
|
|
toggle_4_.entries = {L"Nothing", L"One element", L"Several elements"};
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void()> on_enter = []() {};
|
|
|
|
|
|
|
|
private:
|
2019-01-13 05:25:49 +08:00
|
|
|
Container container_ = Container::Vertical();
|
|
|
|
Toggle toggle_1_;
|
|
|
|
Toggle toggle_2_;
|
|
|
|
Toggle toggle_3_;
|
|
|
|
Toggle toggle_4_;
|
2018-10-10 01:06:03 +08:00
|
|
|
|
2020-03-23 05:32:44 +08:00
|
|
|
// clang-format off
|
2018-10-10 01:06:03 +08:00
|
|
|
Element Render() override {
|
|
|
|
return
|
|
|
|
vbox(
|
|
|
|
text(L"Choose your options:"),
|
|
|
|
text(L""),
|
2019-01-13 05:25:49 +08:00
|
|
|
hbox(text(L" * Poweroff on startup : "), toggle_1_.Render()),
|
|
|
|
hbox(text(L" * Out of process : "), toggle_2_.Render()),
|
|
|
|
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
|
|
|
);
|
|
|
|
}
|
2020-03-23 05:32:44 +08:00
|
|
|
// clang-format on
|
2018-10-10 01:06:03 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, const char* argv[]) {
|
2019-01-07 00:10:35 +08:00
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
2019-01-13 01:24:46 +08:00
|
|
|
MyComponent component;
|
2018-10-10 01:06:03 +08:00
|
|
|
component.on_enter = screen.ExitLoopClosure();
|
2019-01-13 01:24:46 +08:00
|
|
|
screen.Loop(&component);
|
2018-10-10 01:06:03 +08:00
|
|
|
}
|