FTXUI/include/ftxui/component/container.hpp

50 lines
1.3 KiB
C++
Raw Normal View History

2020-04-20 03:00:37 +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.
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-20 05:06:05 +08:00
static Container Tab(int* 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);
2019-07-01 05:59:27 +08:00
bool TabEvent(Event) { return false; }
2019-01-13 05:25:49 +08:00
EventHandler event_handler_;
using RenderHandler = Element (Container::*)();
Element VerticalRender();
Element HorizontalRender();
Element TabRender();
RenderHandler render_handler_;
2019-01-13 01:24:46 +08:00
2019-01-20 05:06:05 +08:00
int selected_ = 0;
int* selector_ = nullptr;
2019-01-13 01:24:46 +08:00
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_CONTAINER_HPP */