FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
component_base.hpp
Go to the documentation of this file.
1// Copyright 2020 Arthur Sonzogni. All rights reserved.
2// Use of this source code is governed by the MIT license that can be found in
3// the LICENSE file.
4#ifndef FTXUI_COMPONENT_BASE_HPP
5#define FTXUI_COMPONENT_BASE_HPP
6
7#include <memory> // for unique_ptr
8#include <vector> // for vector
9
10#include "ftxui/component/captured_mouse.hpp" // for CaptureMouse
11#include "ftxui/dom/elements.hpp" // for Element
12#include "ftxui/util/export.hpp"
13
14namespace ftxui {
15
16class Delegate;
17class Focus;
18struct Event;
19
20namespace animation {
21class Params;
22} // namespace animation
23
24class ComponentBase;
25using Component = std::shared_ptr<ComponentBase>;
26using Components = std::vector<Component>;
27
28/// @brief Implementa el renderizado de sí mismo como ftxui::Element. Implementa
29/// la navegación por teclado respondiendo a ftxui::Event.
30/// @ingroup component
31class FTXUI_EXPORT(COMPONENT) ComponentBase {
32 public:
33 explicit ComponentBase(Components children);
34 virtual ~ComponentBase();
35 ComponentBase();
36
37 // Un componente no es copiable/movible.
38 ComponentBase(const ComponentBase&) = delete;
39 ComponentBase(ComponentBase&&) = delete;
40 ComponentBase& operator=(const ComponentBase&) = delete;
41 ComponentBase& operator=(ComponentBase&&) = delete;
42
43 // Jerarquía de componentes:
44 ComponentBase* Parent() const;
45 Component& ChildAt(size_t i);
46 size_t ChildCount() const;
47 int Index() const;
48 void Add(Component children);
49 void Detach();
50 void DetachAllChildren();
51
52 // Renderiza el componente.
53 Element Render();
54
55 // Sobreescribe esta función para modificar cómo funciona `Render`.
56 virtual Element OnRender();
57
58 // Maneja un evento.
59 // Por defecto, se reduce a los hijos con un OR perezoso.
60 //
61 // Devuelve si el evento fue manejado o no.
62 virtual bool OnEvent(Event);
63
64 // Maneja un paso de animación.
65 virtual void OnAnimation(animation::Params& params);
66
67 // Gestión del foco ----------------------------------------------------------
68 //
69 // Si este componente contiene hijos, esto indica cuál está activo,
70 // nullptr si ninguno está activo.
71 //
72 // Decimos que un elemento tiene el foco si la cadena de ActiveChild() desde el
73 // componente raíz contiene este objeto.
74 virtual Component ActiveChild();
75
76 // Devuelve true cuando el componente contiene elementos enfocables.
77 // El componente no enfocable se omitirá al navegar usando el
78 // teclado.
79 virtual bool Focusable() const;
80
81 // Si este es el hijo activo de su padre.
82 bool Active() const;
83 // Si todos los ancestros están activos.
84 bool Focused() const;
85
86 // Hace que el |hijo| sea el "activo".
87 virtual void SetActiveChild(ComponentBase* child);
88 void SetActiveChild(Component child);
89
90 // Configura todos los ancestros para dar foco a este componente.
91 void TakeFocus();
92
93 // Reserva ABI:
94 virtual void Reserved1();
95 virtual void Reserved2();
96 virtual void Reserved3();
97 virtual void Reserved4();
98 virtual void Reserved5();
99 virtual void Reserved6();
100 virtual void Reserved7();
101 virtual void Reserved8();
102
103 protected:
104 CapturedMouse CaptureMouse(const Event& event);
105
106 Components& children();
107 const Components& children() const;
108
109 private:
110 struct Impl;
111 std::unique_ptr<Impl> impl_;
112};
113
114} // namespace ftxui
115
116#endif /* fin de la guarda de inclusión: FTXUI_COMPONENT_BASE_HPP */
El espacio de nombres ftxui::animation:: de FTXUI.
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:11
std::unique_ptr< CapturedMouseInterface > CapturedMouse
std::shared_ptr< Node > Element
Definition elements.hpp:25
std::vector< Component > Components
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23