FTXUI/examples/component/tab_horizontal.cpp

80 lines
2.1 KiB
C++
Raw Normal View History

2021-05-10 02:32:27 +08:00
#include <memory> // for __shared_ptr_access
#include <string> // for wstring, allocator, basic_string
#include <vector> // for vector
2019-01-13 05:25:49 +08:00
2021-05-10 02:32:27 +08:00
#include "ftxui/component/captured_mouse.hpp" // for ftxui
#include "ftxui/component/component.hpp" // for Radiobox, Make, Toggle
#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, operator|, vbox, border
2019-01-13 05:25:49 +08:00
using namespace ftxui;
2021-05-10 02:32:27 +08:00
class MyComponent : public ComponentBase {
private:
std::vector<std::wstring> tab_values_ = {
L"tab_1",
L"tab_2",
L"tab_3",
};
int tab_selected_ = 0;
Component tab_toggle_ = Toggle(&tab_values_, &tab_selected_);
2019-01-13 05:25:49 +08:00
2021-05-10 02:32:27 +08:00
std::vector<std::wstring> tab_1_entries_ = {
L"Forest",
L"Water",
L"I don't know",
};
int tab_1_selected_ = 0;
2019-01-13 05:25:49 +08:00
2021-05-10 02:32:27 +08:00
std::vector<std::wstring> tab_2_entries_ = {
L"Hello",
L"Hi",
L"Hay",
};
int tab_2_selected_ = 0;
2019-01-13 05:25:49 +08:00
2021-05-10 02:32:27 +08:00
std::vector<std::wstring> tab_3_entries_ = {
L"Table",
L"Nothing",
L"Is",
L"Empty",
};
int tab_3_selected_ = 0;
2019-01-13 05:25:49 +08:00
2021-05-10 02:32:27 +08:00
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_),
});
2019-01-13 05:25:49 +08:00
2021-05-10 02:32:27 +08:00
Component container_ = Container::Vertical({
tab_toggle_,
tab_container_,
});
2019-01-19 05:41:33 +08:00
2021-05-10 02:32:27 +08:00
public:
MyComponent() { Add(container_); }
2019-01-19 05:41:33 +08:00
2020-03-23 05:32:44 +08:00
Element Render() {
2021-05-10 02:32:27 +08:00
return vbox({
tab_toggle_->Render(),
separator(),
tab_container_->Render(),
}) |
2020-03-23 05:32:44 +08:00
border;
2019-01-19 05:41:33 +08:00
}
2019-01-13 05:25:49 +08:00
};
2019-01-19 05:41:33 +08:00
int main(int argc, const char* argv[]) {
2019-01-13 05:25:49 +08:00
auto screen = ScreenInteractive::TerminalOutput();
2021-05-10 02:32:27 +08:00
screen.Loop(Make<MyComponent>());
2019-01-13 05:25:49 +08:00
}
2020-09-06 19:46:56 +08:00
// 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.