2019-01-13 01:24:46 +08:00
|
|
|
#ifndef FTXUI_COMPONENT_CONTAINER_HPP
|
|
|
|
#define FTXUI_COMPONENT_CONTAINER_HPP
|
|
|
|
|
2021-05-10 02:32:27 +08:00
|
|
|
#include "ftxui/component/component.hpp" // for Component, Components
|
|
|
|
#include "ftxui/component/component_base.hpp" // for ComponentBase
|
|
|
|
#include "ftxui/component/event.hpp" // for Event
|
|
|
|
#include "ftxui/dom/elements.hpp" // for Element
|
2019-01-13 01:24:46 +08:00
|
|
|
|
|
|
|
namespace ftxui {
|
|
|
|
|
2020-08-16 08:24:50 +08:00
|
|
|
/// @brief A component where focus and events are automatically handled for you.
|
2021-05-15 02:56:37 +08:00
|
|
|
class ContainerBase : public ComponentBase {
|
2019-01-13 01:24:46 +08:00
|
|
|
public:
|
2021-05-10 02:32:27 +08:00
|
|
|
static Component Vertical();
|
|
|
|
static Component Vertical(Components children);
|
|
|
|
|
|
|
|
static Component Horizontal();
|
|
|
|
static Component Horizontal(Components children);
|
|
|
|
|
|
|
|
static Component Tab(int* selector);
|
2021-05-15 08:32:42 +08:00
|
|
|
static Component Tab(Components children, int* selector);
|
2019-01-13 01:24:46 +08:00
|
|
|
|
2021-05-15 02:56:37 +08:00
|
|
|
~ContainerBase() override = default;
|
2019-01-13 01:24:46 +08:00
|
|
|
|
|
|
|
// Component override.
|
|
|
|
bool OnEvent(Event event) override;
|
2019-01-13 05:25:49 +08:00
|
|
|
Element Render() override;
|
2021-05-10 02:32:27 +08:00
|
|
|
Component ActiveChild() override;
|
|
|
|
virtual void SetActiveChild(ComponentBase*) override;
|
2019-01-13 05:25:49 +08:00
|
|
|
|
2019-01-13 01:24:46 +08:00
|
|
|
protected:
|
|
|
|
// Handlers
|
2021-05-15 02:56:37 +08:00
|
|
|
using EventHandler = bool (ContainerBase::*)(Event);
|
2019-01-13 05:25:49 +08:00
|
|
|
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_;
|
|
|
|
|
2021-05-15 02:56:37 +08:00
|
|
|
using RenderHandler = Element (ContainerBase::*)();
|
2019-01-13 05:25:49 +08:00
|
|
|
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;
|
2021-04-19 04:33:41 +08:00
|
|
|
|
|
|
|
private:
|
|
|
|
bool OnMouseEvent(Event event);
|
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.
|