20static const std::string charset_horizontal[11] = {
21 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
27static const std::string charset_horizontal_microsoft[11] = {
28 " ",
" ",
" ",
" ",
"▌",
"▌",
"▌",
"█",
"█",
"█",
34static const std::string charset_vertical[10] = {
49class Gauge :
public Node {
52 : progress_(progress),
56 if (!(progress_ > 0.F)) {
59 if (!(progress_ < 1.F)) {
64 void ComputeRequirement()
override {
68 requirement_.flex_grow_x = 1;
69 requirement_.flex_grow_y = 0;
70 requirement_.flex_shrink_x = 1;
71 requirement_.flex_shrink_y = 0;
75 requirement_.flex_grow_x = 0;
76 requirement_.flex_grow_y = 1;
77 requirement_.flex_shrink_x = 0;
78 requirement_.flex_shrink_y = 1;
81 requirement_.min_x = 1;
82 requirement_.min_y = 1;
85 void Render(Screen& screen)
override {
88 RenderHorizontal(screen,
false);
91 RenderVertical(screen,
false);
94 RenderHorizontal(screen,
true);
97 RenderVertical(screen,
true);
102 void RenderHorizontal(Screen& screen,
bool invert) {
103 if (box_.y_min > box_.y_max) {
109 const std::string* charset;
114 : charset_horizontal_microsoft;
118 full =
static_cast<int>(
charset_.size()) - 1;
122 const float progress = invert ? 1.F - progress_ : progress_;
124 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
125 const int limit_int =
static_cast<int>(limit);
127 for (
int y = box_.y_min;
y <= box_.y_max;
y++) {
129 while (x < limit_int) {
130 screen.at(x++,
y) = charset[full];
132 if (x <= box_.x_max) {
133 screen.at(x++,
y) = charset[int(full * (limit - limit_int))];
135 while (x <= box_.x_max) {
136 screen.at(x++,
y) = charset[0];
145 void RenderVertical(Screen& screen,
bool invert) {
146 if (box_.x_min > box_.x_max) {
150 const std::string* charset;
153 charset = charset_vertical;
157 full =
static_cast<int>(
charset_.size()) - 1;
161 const float progress = invert ? progress_ : 1.F - progress_;
163 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
164 const int limit_int =
static_cast<int>(limit);
166 for (
int x = box_.x_min; x <= box_.x_max; x++) {
168 while (
y < limit_int) {
169 screen.at(x,
y++) = charset[full];
171 if (
y <= box_.y_max) {
172 screen.at(x,
y++) = charset[int(full * (limit - limit_int))];
174 while (
y <= box_.y_max) {
175 screen.at(x,
y++) = charset[0];
183 void Invert(Screen& screen) {
184 for (
int y = box_.y_min;
y <= box_.y_max;
y++) {
185 for (
int x = box_.x_min; x <= box_.x_max; x++) {
186 screen.CellAt(x,
y).inverted ^=
true;
204 return std::make_shared<Gauge>(progress,
direction);
355 std::vector<std::string> charset,
357 return std::make_shared<Gauge>(progress,
direction, std::move(charset));
Element gaugeDirection(float progress, Direction direction)
Dibuja una barra de progreso de alta definición que avanza en la dirección especificada.
Element gaugeRight(float progress)
Dibuja una barra de progreso de alta definición que avanza de izquierda a derecha.
Direction
Direction es una enumeración que representa las cuatro cardinales direcciones.
Element gaugeUp(float progress)
Dibuja una barra de progreso de alta definición que avanza de abajo hacia arriba.
Element gaugeCharset(float progress, std::vector< std::string > charset, Direction direction=Direction::Right)
Dibuja una barra de progreso de alta definición usando un conjunto de caracteres personalizado.
Element gaugeLeft(float progress)
Dibuja una barra de progreso de alta definición que avanza de derecha a izquierda.
Element gauge(float progress)
Dibuja una barra de progreso de alta definición.
Element gaugeDown(float progress)
Dibuja una barra de progreso de alta definición que avanza de arriba hacia abajo.
Quirks GetQuirks()
Obtiene las peculiaridades de la terminal.
El espacio de nombres ftxui:: de FTXUI.
std::shared_ptr< Node > Element
void Render(Screen &screen, Node *node, Selection &selection)