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,64 +1,77 @@
#include <functional> // for function
#include <string> // for wstring, allocator
#include <vector> // for vector
#include <memory> // for __shared_ptr_access
#include <string> // for wstring, allocator, basic_string
#include <vector> // for vector
#include "ftxui/component/component.hpp" // for Component
#include "ftxui/component/container.hpp" // for Container
#include "ftxui/component/menu.hpp" // for Menu
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/screen/box.hpp" // for ftxui
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Radiobox, Make, Menu
#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, separator, hbox, operator|, border
using namespace ftxui;
class MyComponent : public Component {
public:
MyComponent() {
Add(&container_);
container_.Add(&menu_);
menu_.entries = {
L"menu_1",
L"menu_2",
L"menu_3",
};
container_.Add(&tab_container_);
menu_1_.entries = {L"Forest", L"Water", L"I don't know"};
tab_container_.Add(&menu_1_);
menu_2_.entries = {
L"Hello",
L"Hi",
L"Hay",
};
tab_container_.Add(&menu_2_);
menu_3_.entries = {
L"Table",
L"Nothing",
L"Is",
L"Empty",
};
tab_container_.Add(&menu_3_);
}
std::function<void()> on_enter = []() {};
class MyComponent : public ComponentBase {
private:
Menu menu_;
Container container_ = Container::Horizontal();
Container tab_container_ = Container::Tab(&(menu_.selected));
Menu menu_1_;
Menu menu_2_;
Menu menu_3_;
std::vector<std::wstring> tab_values_ = {
L"tab_1",
L"tab_2",
L"tab_3",
};
int tab_selected_ = 0;
Component tab_toggle_ = Menu(&tab_values_, &tab_selected_);
std::vector<std::wstring> tab_1_entries_ = {
L"Forest",
L"Water",
L"I don't know",
};
int tab_1_selected_ = 0;
std::vector<std::wstring> tab_2_entries_ = {
L"Hello",
L"Hi",
L"Hay",
};
int tab_2_selected_ = 0;
std::vector<std::wstring> tab_3_entries_ = {
L"Table",
L"Nothing",
L"Is",
L"Empty",
};
int tab_3_selected_ = 0;
Component tab_container_ =
Container::Tab(&tab_selected_,
{
Radiobox(&tab_1_entries_, &tab_1_selected_),
Radiobox(&tab_2_entries_, &tab_2_selected_),
Radiobox(&tab_3_entries_, &tab_3_selected_),
});
Component container_ = Container::Horizontal({
tab_toggle_,
tab_container_,
});
public:
MyComponent() { Add(container_); }
Element Render() {
return hbox({
tab_toggle_->Render(),
separator(),
tab_container_->Render(),
}) |
border;
}
};
int main(int argc, const char* argv[]) {
auto screen = ScreenInteractive::TerminalOutput();
MyComponent component;
component.on_enter = screen.ExitLoopClosure();
screen.Loop(&component);
screen.Loop(Make<MyComponent>());
}
// Copyright 2020 Arthur Sonzogni. All rights reserved.