FTXUI 7.0.3
C++ functional terminal UI.
Loading...
Searching...
No Matches
loop.hpp
Go to the documentation of this file.
1// Copyright 2022 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_LOOP_HPP
5#define FTXUI_COMPONENT_LOOP_HPP
6
7#include <memory> // for shared_ptr
8
9#include "ftxui/component/component_base.hpp" // for ComponentBase
10#include "ftxui/util/export.hpp" // for FTXUI_EXPORT
11
12namespace ftxui {
13class ComponentBase;
14
15using Component = std::shared_ptr<ComponentBase>;
16class App;
17
18/// @brief Loop es una clase que gestiona el bucle de eventos de un componente.
19///
20/// Es responsable de ejecutar el componente, manejar eventos, y
21/// actualizar la pantalla.
22///
23/// La clase Loop está diseñada para usarse con un objeto App,
24/// que representa la pantalla de la terminal.
25///
26/// **Ejemplo**
27/// ```cpp
28/// #include <ftxui/component/component.hpp>
29/// #include <ftxui/component/app.hpp>
30/// #include <ftxui/component/loop.hpp>
31///
32/// int main() {
33/// auto screen = ftxui::App::TerminalOutput();
34/// auto component = ftxui::Button("Click me", [] { ... });
35///
36/// ftxui::Loop loop(screen.get(), component);
37///
38/// // O bien
39/// loop.Run(); // Bloqueante hasta que el componente termina.
40///
41/// // O bien
42/// loop.RunOnce(); // No bloqueante, retorna inmediatamente.
43///
44/// // O bien
45/// loop.RunOnceBlocking(); // Bloqueante hasta manejar un evento.
46///
47/// // O en un bucle:
48/// while (!loop.HasQuitted()) {
49/// loop.RunOnce();
50///
51/// // Hacer algo más como ejecutar una función de bucle de otra biblioteca.
52/// }
53/// }
54/// ```
55///
56/// @ingroup component
57class FTXUI_EXPORT(COMPONENT) Loop {
58 public:
59 Loop(App* screen, Component component);
60 ~Loop();
61
62 bool HasQuitted();
63 void RunOnce();
64 void RunOnceBlocking();
65 void Run();
66
67 // Esta clase no es copiable/movible.
68 Loop& operator=(Loop&&) = delete;
69 Loop& operator=(const Loop&) = delete;
70 Loop(Loop&&) = delete;
71 Loop(const Loop&) = delete;
72
73 private:
74 App* screen_;
75 Component component_;
76};
77
78} // namespace ftxui
79
80#endif // FTXUI_COMPONENT_LOOP_HPP
El espacio de nombres ftxui:: de FTXUI.
Definition animation.hpp:11
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23