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 是一個管理元件事件迴圈的類別。
19///
20/// 它負責執行元件、處理事件,以及
21/// 更新畫面。
22///
23/// Loop 類別設計用來與代表終端機畫面的 App 物件
24/// 一起使用。
25///
26/// **範例**
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/// // 或者
39/// loop.Run(); // 阻塞直到元件結束。
40///
41/// // 或者
42/// loop.RunOnce(); // 非阻塞,立即返回。
43///
44/// // 或者
45/// loop.RunOnceBlocking(); // 阻塞直到處理一個事件為止。
46///
47/// // 或者在迴圈中:
48/// while (!loop.HasQuitted()) {
49/// loop.RunOnce();
50///
51/// // 做一些其他事情,例如執行不同函式庫的迴圈函式。
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 // 此類別不可複製/移動。
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
FTXUI ftxui:: 命名空間
Definition animation.hpp:11
std::shared_ptr< ComponentBase > Component
Definition app.hpp:23