FTXUI/examples/component/tab_horizontal.cpp

74 lines
1.9 KiB
C++
Raw Normal View History

2021-05-02 02:40:35 +08:00
#include <functional> // for function
#include <string> // for wstring, allocator
#include <vector> // for vector
2019-01-13 05:25:49 +08:00
2021-05-02 02:40:35 +08:00
#include "ftxui/component/component.hpp" // for Component
#include "ftxui/component/container.hpp" // for Container
#include "ftxui/component/radiobox.hpp" // for RadioBox
#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
#include "ftxui/component/toggle.hpp" // for Toggle
#include "ftxui/dom/elements.hpp" // for Element, operator|
#include "ftxui/screen/box.hpp" // for ftxui
2019-01-13 05:25:49 +08:00
using namespace ftxui;
class MyComponent : public Component {
2019-01-19 05:41:33 +08:00
public:
MyComponent() {
Add(&container_);
container_.Add(&toggle_);
2019-01-13 05:25:49 +08:00
2019-01-19 05:41:33 +08:00
toggle_.entries = {
L"tab_1",
L"tab_2",
L"tab_3",
};
2019-01-13 05:25:49 +08:00
2019-01-19 05:41:33 +08:00
container_.Add(&tab_container_);
2019-01-13 05:25:49 +08:00
2019-01-19 05:41:33 +08:00
radiobox_1_.entries = {L"Forest", L"Water", L"I don't know"};
tab_container_.Add(&radiobox_1_);
2019-01-13 05:25:49 +08:00
2019-01-19 05:41:33 +08:00
radiobox_2_.entries = {
L"Hello",
L"Hi",
L"Hay",
};
tab_container_.Add(&radiobox_2_);
2019-01-13 05:25:49 +08:00
2019-01-19 05:41:33 +08:00
radiobox_3_.entries = {
L"Table",
L"Nothing",
L"Is",
L"Empty",
};
tab_container_.Add(&radiobox_3_);
}
std::function<void()> on_enter = []() {};
2020-03-23 05:32:44 +08:00
Element Render() {
return vbox(toggle_.Render(), separator(), tab_container_.Render()) |
border;
2019-01-19 05:41:33 +08:00
}
private:
Toggle toggle_;
Container container_ = Container::Vertical();
Container tab_container_ = Container::Tab(&(toggle_.selected));
RadioBox radiobox_1_;
RadioBox radiobox_2_;
RadioBox radiobox_3_;
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();
MyComponent component;
component.on_enter = screen.ExitLoopClosure();
screen.Loop(&component);
}
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.