18static const std::string charset_horizontal[11] = {
19#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
22 " ",
" ",
" ",
" ",
"▌",
"▌",
"▌",
"█",
"█",
"█",
24 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
31static const std::string charset_vertical[10] = {
46class Gauge :
public Node {
48 Gauge(
float progress,
Direction direction)
49 : progress_(progress), direction_(direction) {
51 if (!(progress_ > 0.F)) {
54 if (!(progress_ < 1.F)) {
59 void ComputeRequirement()
override {
63 requirement_.flex_grow_x = 1;
64 requirement_.flex_grow_y = 0;
65 requirement_.flex_shrink_x = 1;
66 requirement_.flex_shrink_y = 0;
70 requirement_.flex_grow_x = 0;
71 requirement_.flex_grow_y = 1;
72 requirement_.flex_shrink_x = 0;
73 requirement_.flex_shrink_y = 1;
76 requirement_.min_x = 1;
77 requirement_.min_y = 1;
80 void Render(Screen& screen)
override {
83 RenderHorizontal(screen,
false);
86 RenderVertical(screen,
false);
89 RenderHorizontal(screen,
true);
92 RenderVertical(screen,
true);
97 void RenderHorizontal(Screen& screen,
bool invert) {
98 const int y = box_.y_min;
105 const float progress = invert ? 1.F - progress_ : progress_;
107 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
108 const int limit_int =
static_cast<int>(limit);
110 while (x < limit_int) {
111 screen.at(x++, y) = charset_horizontal[9];
114 screen.at(x++, y) = charset_horizontal[int(9 * (limit - limit_int))];
115 while (x <= box_.x_max) {
116 screen.at(x++, y) = charset_horizontal[0];
121 for (
int x = box_.x_min; x <= box_.x_max; x++) {
122 screen.PixelAt(x, y).inverted ^=
true;
127 void RenderVertical(Screen& screen,
bool invert) {
128 const int x = box_.x_min;
129 if (x > box_.x_max) {
135 const float progress = invert ? progress_ : 1.F - progress_;
137 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
138 const int limit_int =
static_cast<int>(limit);
140 while (y < limit_int) {
141 screen.at(x, y++) = charset_vertical[8];
144 screen.at(x, y++) = charset_vertical[int(8 * (limit - limit_int))];
145 while (y <= box_.y_max) {
146 screen.at(x, y++) = charset_vertical[0];
151 for (
int y = box_.y_min; y <= box_.y_max; y++) {
152 screen.PixelAt(x, y).inverted ^=
true;
170 return std::make_shared<Gauge>(progress, direction);
Element gaugeDirection(float progress, Direction direction)
Draw a high definition progress bar progressing in specified direction.
std::shared_ptr< Node > Element
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.