FTXUI/examples/component/input.cpp

49 lines
1.1 KiB
C++
Raw Normal View History

2018-10-19 04:58:38 +08:00
#include <iostream>
2019-01-13 01:24:46 +08:00
#include "ftxui/component/container.hpp"
#include "ftxui/component/input.hpp"
#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
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;
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())
)
);
}
};
int main(int argc, const char* argv[]) {
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
}