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/input.hpp"
|
|
|
|
|
2018-10-19 04:58:38 +08:00
|
|
|
#include <iostream>
|
|
|
|
|
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-19 04:58:38 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using namespace ftxui;
|
2018-10-19 04:58:38 +08:00
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
class MyComponent : public Component {
|
2018-10-19 04:58:38 +08:00
|
|
|
public:
|
2019-01-13 01:24:46 +08:00
|
|
|
MyComponent() {
|
|
|
|
Add(&container);
|
|
|
|
container.Add(&input_1);
|
|
|
|
container.Add(&input_2);
|
|
|
|
container.Add(&input_3);
|
2018-10-21 20:18:11 +08:00
|
|
|
|
|
|
|
input_1.placeholder = L"input1";
|
|
|
|
input_2.placeholder = L"input2";
|
|
|
|
input_3.placeholder = L"input3";
|
2018-10-19 04:58:38 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void()> on_enter = []() {};
|
|
|
|
|
|
|
|
private:
|
2019-01-13 01:24:46 +08:00
|
|
|
Container container = Container::Vertical();
|
2018-10-19 04:58:38 +08:00
|
|
|
Input input_1;
|
|
|
|
Input input_2;
|
|
|
|
Input input_3;
|
|
|
|
|
2020-03-23 05:32:44 +08:00
|
|
|
// clang-format off
|
2018-10-19 04:58:38 +08:00
|
|
|
Element Render() override {
|
|
|
|
return
|
2019-01-20 05:06:05 +08:00
|
|
|
border(
|
2018-10-19 04:58:38 +08:00
|
|
|
vbox(
|
|
|
|
hbox(text(L" input_1 : "), input_1.Render()),
|
|
|
|
hbox(text(L" input_2 : "), input_2.Render()),
|
|
|
|
hbox(text(L" input_3 : "), input_3.Render())
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
2020-03-23 05:32:44 +08:00
|
|
|
// clang-format on
|
2018-10-19 04:58:38 +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-19 04:58:38 +08:00
|
|
|
component.on_enter = screen.ExitLoopClosure();
|
2019-01-13 01:24:46 +08:00
|
|
|
screen.Loop(&component);
|
2018-10-19 04:58:38 +08:00
|
|
|
}
|