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 {
51 Gauge(
float progress,
Direction direction)
52 : progress_(progress), direction_(direction) {
54 if (!(progress_ > 0.F)) {
57 if (!(progress_ < 1.F)) {
62 void ComputeRequirement()
override {
66 requirement_.flex_grow_x = 1;
67 requirement_.flex_grow_y = 0;
68 requirement_.flex_shrink_x = 1;
69 requirement_.flex_shrink_y = 0;
73 requirement_.flex_grow_x = 0;
74 requirement_.flex_grow_y = 1;
75 requirement_.flex_shrink_x = 0;
76 requirement_.flex_shrink_y = 1;
79 requirement_.min_x = 1;
80 requirement_.min_y = 1;
83 void Render(Screen& screen)
override {
86 RenderHorizontal(screen,
false);
89 RenderVertical(screen,
false);
92 RenderHorizontal(screen,
true);
95 RenderVertical(screen,
true);
100 void RenderHorizontal(Screen& screen,
bool invert) {
101 if (box_.y_min > box_.y_max) {
107 : charset_horizontal_microsoft;
110 const float progress = invert ? 1.F - progress_ : progress_;
112 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
113 const int limit_int =
static_cast<int>(limit);
115 for (
int y = box_.y_min; y <= box_.y_max; y++) {
117 while (x < limit_int) {
118 screen.at(x++, y) = charset[9];
121 screen.at(x++, y) = charset[int(9 * (limit - limit_int))];
122 while (x <= box_.x_max) {
123 screen.at(x++, y) = charset[0];
132 void RenderVertical(Screen& screen,
bool invert) {
133 if (box_.x_min > box_.x_max) {
138 const float progress = invert ? progress_ : 1.F - progress_;
140 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
141 const int limit_int =
static_cast<int>(limit);
143 for (
int x = box_.x_min; x <= box_.x_max; x++) {
145 while (y < limit_int) {
146 screen.at(x, y++) = charset_vertical[8];
149 screen.at(x, y++) = charset_vertical[int(8 * (limit - limit_int))];
150 while (y <= box_.y_max) {
151 screen.at(x, y++) = charset_vertical[0];
159 void Invert(Screen& screen) {
160 for (
int y = box_.y_min; y <= box_.y_max; y++) {
161 for (
int x = box_.x_min; x <= box_.x_max; x++) {
162 screen.CellAt(x, y).inverted ^=
true;
180 return std::make_shared<Gauge>(progress, direction);
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
Direction
Direction is an enumeration that represents the four cardinal directions.
Element gaugeRight(float progress)
Draw a high definition progress bar progressing from left to right.
Element gaugeUp(float progress)
Draw a high definition progress bar progressing from bottom to top.
Element gaugeLeft(float progress)
Draw a high definition progress bar progressing from right to left.
void Render(Screen &screen, const Element &element)
Display an element on a ftxui::Screen.
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.
bool block_characters
Whether the terminal font supports the 8 Unicode block characters.
Quirks GetQuirks()
Get the terminal quirks.
The FTXUI ftxui:: namespace.
std::shared_ptr< Node > Element