FTXUI/examples/component/gallery.cpp
ArthurSonzogni e1a71d5b9f Use shared_ptr instead of unique_ptr for elements.
This allow users to pass it into initializer list. Then clang-format
will produce 'acceptable' indentations.

This fixes:
https://github.com/ArthurSonzogni/FTXUI/issues/18
2020-05-20 20:51:20 +02:00

91 lines
2.2 KiB
C++

// 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.
#include "ftxui/component/checkbox.hpp"
#include "ftxui/component/container.hpp"
#include "ftxui/component/input.hpp"
#include "ftxui/component/menu.hpp"
#include "ftxui/component/radiobox.hpp"
#include "ftxui/component/screen_interactive.hpp"
#include "ftxui/component/toggle.hpp"
using namespace ftxui;
class MyComponent : public Component {
Container container = Container::Vertical();
Menu menu;
Toggle toggle;
Container checkbox_container = Container::Vertical();
CheckBox checkbox1;
CheckBox checkbox2;
RadioBox radiobox;
Input input;
public:
MyComponent() {
Add(&container);
menu.entries = {
L"Menu 1",
L"Menu 2",
L"Menu 3",
L"Menu 4",
};
container.Add(&menu);
toggle.entries = {
L"Toggle_1",
L"Toggle_2",
};
container.Add(&toggle);
container.Add(&checkbox_container);
checkbox1.label = L"checkbox1";
checkbox_container.Add(&checkbox1);
checkbox2.label = L"checkbox2";
checkbox_container.Add(&checkbox2);
radiobox.entries = {
L"Radiobox 1",
L"Radiobox 2",
L"Radiobox 3",
L"Radiobox 4",
};
container.Add(&radiobox);
input.placeholder = L"Input placeholder";
container.Add(&input);
}
Element Render(std::wstring name, Component& component) {
return hbox({
text(name) | size(WIDTH, EQUAL, 8),
separator(),
component.Render(),
});
}
Element Render() override {
return vbox({
Render(L"menu", menu),
separator(),
Render(L"toggle", toggle),
separator(),
Render(L"checkbox", checkbox_container),
separator(),
Render(L"radiobox", radiobox),
separator(),
Render(L"input", input) | size(WIDTH, LESS_THAN, 30),
}) |
border;
}
};
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::FitComponent();
MyComponent component;
screen.Loop(&component);
return 0;
}