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 {
|
|
|
|
|
2020-08-16 08:24:50 +08:00
|
|
|
/// @brief A component where focus and events are automatically handled for you.
|
2019-01-13 01:24:46 +08:00
|
|
|
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;
|
2020-08-26 20:57:42 +08:00
|
|
|
virtual void SetActiveChild(Component*) 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;
|
2020-04-17 07:15:17 +08:00
|
|
|
int* selector_ = nullptr;
|
2019-01-13 01:24:46 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ftxui
|
|
|
|
|
|
|
|
#endif /* end of include guard: FTXUI_COMPONENT_CONTAINER_HPP */
|
2020-08-16 06:24:18 +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.
|