2019-01-13 01:24:46 +08:00
|
|
|
#ifndef FTXUI_COMPONENT_CONTAINER_HPP
|
|
|
|
#define FTXUI_COMPONENT_CONTAINER_HPP
|
|
|
|
|
|
|
|
#include "ftxui/component/component.hpp"
|
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
|
|
|
// A component where focus and events are automatically handled for you.
|
|
|
|
// List of container:
|
|
|
|
//
|
|
|
|
// Please use HorizontalContainer or VerticalContainer.
|
|
|
|
class Container : public Component {
|
|
|
|
public:
|
|
|
|
static Container Vertical();
|
|
|
|
static Container Horizontal();
|
2019-01-13 05:25:49 +08:00
|
|
|
static Container Tab(size_t* selector);
|
2019-01-13 01:24:46 +08:00
|
|
|
|
|
|
|
~Container() override = default;
|
|
|
|
|
|
|
|
// Component override.
|
|
|
|
bool OnEvent(Event event) override;
|
2019-01-13 05:25:49 +08:00
|
|
|
Element Render() override;
|
2019-01-13 01:24:46 +08:00
|
|
|
Component* ActiveChild() override;
|
2019-01-13 05:25:49 +08:00
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
protected:
|
|
|
|
// Handlers
|
2019-01-13 05:25:49 +08:00
|
|
|
using EventHandler = bool (Container::*)(Event);
|
|
|
|
bool VerticalEvent(Event event);
|
|
|
|
bool HorizontalEvent(Event event);
|
|
|
|
bool TabEvent(Event event) { return false; }
|
|
|
|
EventHandler event_handler_;
|
|
|
|
|
|
|
|
using RenderHandler = Element (Container::*)();
|
|
|
|
Element VerticalRender();
|
|
|
|
Element HorizontalRender();
|
|
|
|
Element TabRender();
|
|
|
|
RenderHandler render_handler_;
|
2019-01-13 01:24:46 +08:00
|
|
|
|
|
|
|
size_t selected_ = 0;
|
2019-01-13 05:25:49 +08:00
|
|
|
size_t* selector_ = &selected_;
|
2019-01-13 01:24:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ftxui
|
|
|
|
|
|
|
|
#endif /* end of include guard: FTXUI_COMPONENT_CONTAINER_HPP */
|