FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
loop.hpp
Go to the documentation of this file.
1// 版權所有 2022 Arthur Sonzogni. 保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,詳情請參閱
3// LICENSE 文件。
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
11namespace ftxui {
12class ComponentBase;
13
14using Component = std::shared_ptr<ComponentBase>;
15class ScreenInteractive;
16
17/// @brief Loop 是一個用於管理元件事件循環的類別。
18///
19/// 它負責執行元件、處理事件,並
20/// 更新畫面。
21///
22/// Loop 類別旨在與 ScreenInteractive 物件一起使用,
23/// 該物件代表終端機畫面。
24///
25/// **範例**
26/// ```cpp
27/// #include <ftxui/component/component.hpp>
28/// #include <ftxui/component/screen_interactive.hpp>
29/// #include <ftxui/component/loop.hpp>
30///
31/// int main() {
32/// auto screen = ftxui::ScreenInteractive::TerminalOutput();
33/// auto component = ftxui::Button("Click me", [] { ... });
34///
35/// ftxui::Loop loop(screen.get(), component);
36///
37/// // 方法一
38/// loop.Run(); // 阻塞直到元件退出。
39///
40/// // 方法二
41/// loop.RunOnce(); // 非阻塞,立即返回。
42///
43/// // 方法三
44/// loop.RunOnceBlocking(); // 阻塞直到處理一個事件。
45///
46/// // 方法四:在循環中:
47/// while (!loop.HasQuitted()) {
48/// loop.RunOnce();
49///
50/// // 執行其他操作,例如運行不同的函式庫循環函式。
51/// }
52/// }
53/// ```
54///
55/// @ingroup 元件
56class Loop {
57 public:
59 ~Loop();
60
61 bool HasQuitted();
62 void RunOnce();
63 void RunOnceBlocking();
64 void Run();
65
66 // This class is non copyable/movable.
67 Loop(const Loop&) = default;
68 Loop(Loop&&) = delete;
69 Loop& operator=(Loop&&) = delete;
70 Loop(const ScreenInteractive&) = delete;
71 Loop& operator=(const Loop&) = delete;
72
73 private:
74 ScreenInteractive* screen_;
75 Component component_;
76};
77
78} // namespace ftxui
79
80#endif // FTXUI_COMPONENT_LOOP_HPP
Loop 是一個用於管理元件事件循環的類別。
Definition loop.hpp:56
bool HasQuitted()
迴圈是否已退出。
Definition loop.cpp:30
Loop(const ScreenInteractive &)=delete
void Run()
執行迴圈,阻塞當前執行緒,直到迴圈退出。
Definition loop.cpp:48
Loop(ScreenInteractive *screen, Component component)
迴圈是 Component 和 ScreenInteractive 的包裝器。 它用於在終端機中執行元件。
Definition loop.cpp:20
Loop & operator=(const Loop &)=delete
void RunOnce()
執行迴圈。讓 component 處理所有待處理的任務/事件。 如果前一個影格失效,可能會繪製一個新影格。 在迴圈完成之前返回 true。
Definition loop.cpp:37
Loop(const Loop &)=default
Loop & operator=(Loop &&)=delete
Loop(Loop &&)=delete
void RunOnceBlocking()
等待至少一個事件被處理並執行 Loop::RunOnce()。
Definition loop.cpp:43
auto component
Definition gallery.cpp:127
ScreenInteractive 是一個可以處理事件、執行主迴圈並管理組件的 Screen。
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10
std::shared_ptr< ComponentBase > Component