14static const std::string charset_horizontal[11] = {
15#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
18 " ",
" ",
" ",
" ",
"▌",
"▌",
"▌",
"█",
"█",
"█",
20 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
27static const std::string charset_vertical[10] = {
42class Gauge :
public Node {
44 Gauge(
float progress,
Direction direction)
45 : progress_(progress), direction_(direction) {
47 if (!(progress_ > 0.F)) {
50 if (!(progress_ < 1.F)) {
55 void ComputeRequirement()
override {
76 void Render(Screen& screen)
override {
79 RenderHorizontal(screen,
false);
82 RenderVertical(screen,
false);
85 RenderHorizontal(screen,
true);
88 RenderVertical(screen,
true);
93 void RenderHorizontal(Screen& screen,
bool invert) {
101 const float progress = invert ? 1.F - progress_ : progress_;
104 const int limit_int = (int)limit;
106 while (x < limit_int) {
107 screen.at(x++, y) = charset_horizontal[9];
110 screen.at(x++, y) = charset_horizontal[int(9 * (limit - limit_int))];
112 screen.at(x++, y) = charset_horizontal[0];
118 screen.PixelAt(x, y).inverted ^=
true;
123 void RenderVertical(Screen& screen,
bool invert) {
131 const float progress = invert ? progress_ : 1.F - progress_;
134 const int limit_int = (int)limit;
136 while (y < limit_int) {
137 screen.at(x, y++) = charset_vertical[8];
140 screen.at(x, y++) = charset_vertical[int(8 * (limit - limit_int))];
142 screen.at(x, y++) = charset_vertical[0];
148 screen.PixelAt(x, y).inverted ^=
true;
164 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.
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.