FTXUI 6.1.9
C++ functional terminal UI.
载入中...
搜索中...
未找到
gauge_direction.cpp
浏览该文件的文档.
1// 版权所有 2022 Arthur Sonzogni。保留所有权利。
2// 本源代码的使用受 MIT 许可证的约束,该许可证可在 LICENSE 文件中找到。
3#include <chrono> // for operator""s, chrono_literals
4#include <ftxui/dom/elements.hpp> // for filler, operator|, separator, text, border, Element, vbox, vtext, hbox, center, gaugeDown, gaugeLeft, gaugeRight, gaugeUp
5#include <ftxui/screen/screen.hpp> // for Screen
6#include <iostream> // for cout, endl, ostream
7#include <string> // for allocator, operator+, operator<<, string, to_string
8#include <thread> // for sleep_for
9
10#include "ftxui/dom/node.hpp" // for Render
11#include "ftxui/screen/color.hpp" // for ftxui
12
13int main() {
14 using namespace ftxui;
15 using namespace std::chrono_literals;
16
17 std::string reset_position;
18 for (float percentage = 0.0f; percentage <= 1.0f; percentage += 0.002f) {
19 std::string data_downloaded =
20 std::to_string(int(percentage * 5000)) + "/5000";
21
22 auto gauge_up = //
23 hbox({
24 vtext("gauge vertical"),
25 separator(),
26 gaugeUp(percentage),
27 }) |
28 border;
29
30 auto gauge_down = //
31 hbox({
32 vtext("gauge vertical"),
33 separator(),
34 gaugeDown(percentage),
35 }) |
36 border;
37
38 auto gauge_right = //
39 vbox({
40 text("gauge horizontal"),
41 separator(),
42 gaugeRight(percentage),
43 }) |
44 border;
45
46 auto gauge_left = //
47 vbox({
48 text("gauge horizontal"),
49 separator(),
50 gaugeLeft(percentage),
51 }) |
52 border;
53
54 auto document = hbox({
55 gauge_up,
56 filler(),
57 vbox({
58 gauge_right,
59 filler(),
60 text(data_downloaded) | border | center,
61 filler(),
62 gauge_left,
63 }),
64 filler(),
65 gauge_down,
66 });
67
68 auto screen = Screen(32, 16);
69 Render(screen, document);
70 std::cout << reset_position;
71 screen.Print();
72 reset_position = screen.ResetPosition();
73
74 std::this_thread::sleep_for(0.01s);
75 }
76 std::cout << std::endl;
77}
像素的矩形网格。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase