Make component more functionnal

This commit is contained in:
ArthurSonzogni
2021-05-09 20:32:27 +02:00
parent 9d15d1c275
commit 6d75cb2748
70 changed files with 2182 additions and 1769 deletions

View File

@@ -1,50 +1,61 @@
#include <memory> // for allocator_traits<>...
#include <string> // for operator+, wstring
#include <utility> // for move
#include <vector> // for vector
#include <ext/alloc_traits.h> // for __alloc_traits<>::value_type
#include <memory> // for unique_ptr, make_unique, __shared_ptr_access
#include <string> // for operator+, wstring
#include <vector> // for vector
#include "ftxui/component/checkbox.hpp" // for CheckBox
#include "ftxui/component/component.hpp" // for Component
#include "ftxui/component/container.hpp" // for Container
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/dom/elements.hpp" // for Element, operator|
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/screen/string.hpp" // for to_wstring
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Checkbox, Make
#include "ftxui/component/component_base.hpp" // for ComponentBase
#include "ftxui/component/container.hpp" // for Container
#include "ftxui/component/screen_interactive.hpp" // for Component, ScreenInteractive
#include "ftxui/dom/elements.hpp" // for Element, operator|, size, vbox, border, frame, Elements, HEIGHT, LESS_THAN
#include "ftxui/screen/string.hpp" // for to_wstring
using namespace ftxui;
class MyComponent : public Component {
struct CheckboxAndState {
std::wstring label;
bool state;
Component component;
};
std::unique_ptr<CheckboxAndState> MakeCheckbox(std::wstring label) {
auto out = std::make_unique<CheckboxAndState>();
out->label = label;
out->state = false;
out->component = Checkbox(&out->label, &out->state);
return out;
}
class MyComponent : public ComponentBase {
public:
MyComponent() {
Add(&container);
Add(container);
checkbox.resize(30);
for (int i = 0; i < checkbox.size(); ++i) {
checkbox[i].label = (L"CheckBox " + to_wstring(i));
container.Add(&checkbox[i]);
checkbox[i] = MakeCheckbox(L"CheckBox " + to_wstring(i));
container->Add(checkbox[i]->component);
}
}
// clang-format off
Element Render() override {
Elements content;
for (auto& it : checkbox) {
content.push_back(it.Render());
}
return vbox(std::move(content))
return vbox(container->Render())
| frame
| size(HEIGHT, LESS_THAN, 10)
| border;
}
private:
std::vector<CheckBox> checkbox;
Container container = Container::Vertical();
std::vector<std::unique_ptr<CheckboxAndState>> checkbox;
Component container = Container::Vertical();
};
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::FitComponent();
MyComponent component;
screen.Loop(&component);
auto my_component = Make<MyComponent>();
screen.Loop(my_component);
return 0;
}