Files
FTXUI/include/ftxui/component/container.hpp

59 lines
1.7 KiB
C++
Raw Normal View History

2019-01-12 18:24:46 +01:00
#ifndef FTXUI_COMPONENT_CONTAINER_HPP
#define FTXUI_COMPONENT_CONTAINER_HPP
2021-05-09 20:32:27 +02: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-12 18:24:46 +01:00
namespace ftxui {
2020-08-16 02:24:50 +02:00
/// @brief A component where focus and events are automatically handled for you.
2021-05-14 20:56:37 +02:00
class ContainerBase : public ComponentBase {
2019-01-12 18:24:46 +01:00
public:
2021-05-09 20:32:27 +02:00
static Component Vertical();
static Component Vertical(Components children);
static Component Horizontal();
static Component Horizontal(Components children);
static Component Tab(int* selector);
static Component Tab(Components children, int* selector);
2019-01-12 18:24:46 +01:00
2021-05-14 20:56:37 +02:00
~ContainerBase() override = default;
2019-01-12 18:24:46 +01:00
// Component override.
bool OnEvent(Event event) override;
2019-01-12 22:25:49 +01:00
Element Render() override;
2021-05-09 20:32:27 +02:00
Component ActiveChild() override;
virtual void SetActiveChild(ComponentBase*) override;
2019-01-12 22:25:49 +01:00
2019-01-12 18:24:46 +01:00
protected:
// Handlers
2021-05-14 20:56:37 +02:00
using EventHandler = bool (ContainerBase::*)(Event);
2019-01-12 22:25:49 +01:00
bool VerticalEvent(Event event);
bool HorizontalEvent(Event event);
2019-06-30 23:59:27 +02:00
bool TabEvent(Event) { return false; }
2019-01-12 22:25:49 +01:00
EventHandler event_handler_;
2021-05-14 20:56:37 +02:00
using RenderHandler = Element (ContainerBase::*)();
2019-01-12 22:25:49 +01:00
Element VerticalRender();
Element HorizontalRender();
Element TabRender();
RenderHandler render_handler_;
2019-01-12 18:24:46 +01:00
2019-01-19 22:06:05 +01:00
int selected_ = 0;
int* selector_ = nullptr;
private:
bool OnMouseEvent(Event event);
2019-01-12 18:24:46 +01:00
};
} // namespace ftxui
#endif /* end of include guard: FTXUI_COMPONENT_CONTAINER_HPP */
// 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.