2019-01-03 07:35:59 +08:00
|
|
|
#include <iostream>
|
|
|
|
#include <thread>
|
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
#include "ftxui/component/container.hpp"
|
2019-01-03 07:35:59 +08:00
|
|
|
#include "ftxui/component/menu.hpp"
|
2019-01-07 00:10:35 +08:00
|
|
|
#include "ftxui/component/screen_interactive.hpp"
|
2019-01-13 01:24:46 +08:00
|
|
|
#include "ftxui/screen/string.hpp"
|
2019-01-03 07:35:59 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
using namespace ftxui;
|
2019-01-03 07:35:59 +08:00
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
class MyComponent : public Component {
|
2019-01-03 07:35:59 +08:00
|
|
|
public:
|
2019-01-13 01:24:46 +08:00
|
|
|
MyComponent() {
|
|
|
|
Add(&container);
|
2019-01-03 07:35:59 +08:00
|
|
|
|
|
|
|
for(Menu* menu : {&menu_1, &menu_2, &menu_3, &menu_4, &menu_5, &menu_6}) {
|
2019-01-13 01:24:46 +08:00
|
|
|
container.Add(menu);
|
2019-01-03 07:35:59 +08:00
|
|
|
menu->entries = {
|
|
|
|
L"Monkey",
|
|
|
|
L"Dog",
|
|
|
|
L"Cat",
|
|
|
|
L"Bird",
|
|
|
|
L"Elephant",
|
|
|
|
};
|
|
|
|
menu->on_enter = [this]() { on_enter(); };
|
|
|
|
}
|
|
|
|
|
|
|
|
menu_2.selected_style = color(Color::Blue);
|
2019-01-05 09:03:49 +08:00
|
|
|
menu_2.active_style = bold | color(Color::Blue);
|
2019-01-03 07:35:59 +08:00
|
|
|
|
|
|
|
menu_3.selected_style = color(Color::Blue);
|
|
|
|
menu_3.active_style = bgcolor(Color::Blue);
|
|
|
|
|
|
|
|
menu_4.selected_style = bgcolor(Color::Blue);
|
|
|
|
menu_4.active_style = bgcolor(Color::BlueLight);
|
|
|
|
|
|
|
|
menu_5.normal_style = bgcolor(Color::Blue);
|
|
|
|
menu_5.selected_style = bgcolor(Color::Yellow);
|
|
|
|
menu_5.active_style = bgcolor(Color::Red);
|
|
|
|
|
2019-01-05 09:03:49 +08:00
|
|
|
menu_6.normal_style = dim | color(Color::Blue);
|
|
|
|
menu_6.selected_style = color(Color::Blue);
|
|
|
|
menu_6.active_style = bold | color(Color::Blue);
|
2019-01-03 07:35:59 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
std::function<void()> on_enter = [](){};
|
|
|
|
private:
|
2019-01-13 01:24:46 +08:00
|
|
|
Container container = Container::Horizontal();
|
2019-01-03 07:35:59 +08:00
|
|
|
Menu menu_1;
|
|
|
|
Menu menu_2;
|
|
|
|
Menu menu_3;
|
|
|
|
Menu menu_4;
|
|
|
|
Menu menu_5;
|
|
|
|
Menu menu_6;
|
|
|
|
|
|
|
|
Element Render() override {
|
|
|
|
return
|
|
|
|
hbox(
|
2019-01-05 09:03:49 +08:00
|
|
|
menu_1.Render() | flex, separator(),
|
|
|
|
menu_2.Render() | flex, separator(),
|
|
|
|
menu_3.Render() | flex, separator(),
|
|
|
|
menu_4.Render() | flex, separator(),
|
|
|
|
menu_5.Render() | flex, separator(),
|
|
|
|
menu_6.Render() | flex
|
|
|
|
) | frame;
|
2019-01-03 07:35:59 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
int main(int argc, const char *argv[])
|
|
|
|
{
|
2019-01-07 00:10:35 +08:00
|
|
|
auto screen = ScreenInteractive::TerminalOutput();
|
2019-01-13 01:24:46 +08:00
|
|
|
MyComponent component;
|
2019-01-03 07:35:59 +08:00
|
|
|
component.on_enter = screen.ExitLoopClosure();
|
2019-01-13 01:24:46 +08:00
|
|
|
screen.Loop(&component);
|
2019-01-03 07:35:59 +08:00
|
|
|
}
|