FTXUI 6.1.9
C++ functional terminal UI.
Loading...
Searching...
No Matches
custom_loop.cpp
Go to the documentation of this file.
1// 版權所有 2020 Arthur Sonzogni。保留所有權利。
2// 本原始碼的使用受 MIT 授權條款約束,該條款可在以下位置找到:
3// LICENSE 文件。
4#include <stdlib.h> // for EXIT_SUCCESS
5#include <chrono> // for milliseconds
6#include <ftxui/component/event.hpp> // for Event
7#include <ftxui/component/mouse.hpp> // for ftxui
8#include <ftxui/dom/elements.hpp> // for text, separator, Element, operator|, vbox, border
9#include <memory> // for allocator, shared_ptr
10#include <string> // for operator+, to_string
11#include <thread> // for sleep_for
12
13#include "ftxui/component/component.hpp" // for CatchEvent, Renderer, operator|=
14#include "ftxui/component/loop.hpp" // for Loop
15#include "ftxui/component/screen_interactive.hpp" // for ScreenInteractive
16
17int main() {
18 using namespace ftxui;
19 auto screen = ScreenInteractive::FitComponent();
20
21 // 創建一個組件來計算繪製的幀數和處理的事件數。
22 int custom_loop_count = 0;
23 int frame_count = 0;
24 int event_count = 0;
25 auto component = Renderer([&] {
26 frame_count++;
27 return vbox({
28 text("這演示了使用自定義 ftxui::Loop。它 "),
29 text("以每秒 100 次迭代的速度運行。FTXUI 事件 "),
30 text("每次迭代處理一次,並根據需要渲染新幀 "),
31 text("根據需要渲染"),
32 separator(),
33 text("ftxui event count: " + std::to_string(event_count)),
34 text("ftxui frame count: " + std::to_string(frame_count)),
35 text("Custom loop count: " + std::to_string(custom_loop_count)),
36 }) |
37 border;
38 });
39
40 component |= CatchEvent([&](Event) -> bool {
41 event_count++;
42 return false;
43 });
44
45 Loop loop(&screen, component);
46
47 while (!loop.HasQuitted()) {
48 custom_loop_count++;
49 loop.RunOnce();
50 std::this_thread::sleep_for(std::chrono::milliseconds(10));
51 }
52
53 return EXIT_SUCCESS;
54}
Loop 是一個用於管理元件事件循環的類別。
Definition loop.hpp:56
int main()
auto component
Definition gallery.cpp:127
代表一個事件。它可以是按鍵事件、終端機大小調整,或更多...
Definition event.hpp:27
FTXUI 的 ftxui:: 命名空間
Definition animation.hpp:10