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,35 +1,36 @@
#include <string> // for wstring, operator+
#include <vector> // for vector
#include "ftxui/component/component.hpp" // for Component
#include "ftxui/component/radiobox.hpp" // for RadioBox
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Make, Radiobox
#include "ftxui/component/component_base.hpp" // for ComponentBase
#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/dom/elements.hpp" // for Element, operator|, size, border, frame, HEIGHT, LESS_THAN
#include "ftxui/screen/string.hpp" // for to_wstring
using namespace ftxui;
class MyComponent : public Component {
RadioBox radiobox;
class MyComponent : public ComponentBase {
private:
std::vector<std::wstring> entries_;
int selected_ = 0;
public:
MyComponent() {
for (int i = 0; i < 30; ++i) {
radiobox.entries.push_back(L"RadioBox " + to_wstring(i));
}
Add(&radiobox);
for (int i = 0; i < 30; ++i)
entries_.push_back(L"RadioBox " + to_wstring(i));
Add(Radiobox(&entries_, &selected_));
}
Element Render() override {
return radiobox.Render() | frame | size(HEIGHT, LESS_THAN, 10) | border;
return ComponentBase::Render() | frame | size(HEIGHT, LESS_THAN, 10) |
border;
}
};
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::FitComponent();
MyComponent component;
screen.Loop(&component);
screen.Loop(Make<MyComponent>());
return 0;
}