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;
205 return std::make_shared<Gauge>(progress,
direction);
356 std::vector<std::string> charset,
358 return std::make_shared<Gauge>(progress,
direction, std::move(charset));
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Direction
Direction is an enumeration that represents the four cardinal directions.
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Element gaugeCharset(float progress, std::vector< std::string > charset, Direction direction=Direction::Right)
Draw a high definition progress bar using a custom charset.
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
Element gauge(float progress)
Draw a high definition progress bar.
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.
Quirks GetQuirks()
Get the terminal quirks.
The FTXUI ftxui:: namespace.
std::shared_ptr< Node > Element
void Render(Screen &screen, Node *node, Selection &selection)