17static const std::string charset_horizontal[11] = {
18#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
21 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
28static const std::string charset_vertical[10] = {
43class Gauge :
public Node {
45 Gauge(
float progress,
Direction direction)
46 : progress_(progress), direction_(direction) {
48 if (!(progress_ > 0.F)) {
51 if (!(progress_ < 1.F)) {
56 void ComputeRequirement()
override {
60 requirement_.flex_grow_x = 1;
61 requirement_.flex_grow_y = 0;
62 requirement_.flex_shrink_x = 1;
63 requirement_.flex_shrink_y = 0;
67 requirement_.flex_grow_x = 0;
68 requirement_.flex_grow_y = 1;
69 requirement_.flex_shrink_x = 0;
70 requirement_.flex_shrink_y = 1;
73 requirement_.min_x = 1;
74 requirement_.min_y = 1;
77 void Render(Screen& screen)
override {
80 RenderHorizontal(screen,
false);
83 RenderVertical(screen,
false);
86 RenderHorizontal(screen,
true);
89 RenderVertical(screen,
true);
94 void RenderHorizontal(Screen& screen,
bool invert) {
95 const int y = box_.y_min;
102 const float progress = invert ? 1.F - progress_ : progress_;
104 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
105 const int limit_int =
static_cast<int>(limit);
107 while (x < limit_int) {
108 screen.at(x++, y) = charset_horizontal[9];
111 screen.at(x++, y) = charset_horizontal[int(9 * (limit - limit_int))];
112 while (x <= box_.x_max) {
113 screen.at(x++, y) = charset_horizontal[0];
118 for (
int x = box_.x_min; x <= box_.x_max; x++) {
119 screen.PixelAt(x, y).inverted ^=
true;
124 void RenderVertical(Screen& screen,
bool invert) {
125 const int x = box_.x_min;
126 if (x > box_.x_max) {
132 const float progress = invert ? progress_ : 1.F - progress_;
134 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
135 const int limit_int =
static_cast<int>(limit);
137 while (y < limit_int) {
138 screen.at(x, y++) = charset_vertical[8];
141 screen.at(x, y++) = charset_vertical[int(8 * (limit - limit_int))];
142 while (y <= box_.y_max) {
143 screen.at(x, y++) = charset_vertical[0];
148 for (
int y = box_.y_min; y <= box_.y_max; y++) {
149 screen.PixelAt(x, y).inverted ^=
true;
166 return std::make_shared<Gauge>(progress, direction);
Element gaugeDirection(float progress, Direction direction)
绘制一个向指定方向推进的高清进度条。
Direction
Direction 是一个枚举,表示四个基本方向。
void Render(Screen &screen, const Element &element)
在 ftxui::Screen 上显示元素。
#include "ftxui/component/component_base.hpp" // 用于 ComponentBase
std::shared_ptr< Node > Element
Element gaugeRight(float progress)
绘制一个从左到右推进的高清进度条。
Element gaugeUp(float progress)
绘制一个从下到上推进的高清进度条。
Element gaugeLeft(float progress)
绘制一个从右到左推进的高清进度条。
Element gauge(float progress)
绘制一个高清进度条。
Element gaugeDown(float progress)
绘制一个从上到下推进的高清进度条。