13static const std::string charset_horizontal[11] = {
14#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
17 " ",
" ",
" ",
" ",
"▌",
"▌",
"▌",
"█",
"█",
"█",
19 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
26static const std::string charset_vertical[10] = {
41class Gauge :
public Node {
44 : progress_(progress), direction_(direction) {
46 if (!(progress_ > 0.F)) {
49 if (!(progress_ < 1.F)) {
54 void ComputeRequirement()
override {
75 void Render(Screen& screen)
override {
78 RenderHorizontal(screen,
false);
81 RenderVertical(screen,
false);
84 RenderHorizontal(screen,
true);
87 RenderVertical(screen,
true);
92 void RenderHorizontal(Screen& screen,
bool invert) {
100 float progress = invert ? 1.F - progress_ : progress_;
103 int limit_int = (int)limit;
105 while (x < limit_int) {
106 screen.at(x++, y) = charset_horizontal[9];
109 screen.at(x++, y) = charset_horizontal[int(9 * (limit - limit_int))];
111 screen.at(x++, y) = charset_horizontal[0];
117 screen.PixelAt(x, y).inverted ^=
true;
122 void RenderVertical(Screen& screen,
bool invert) {
130 float progress = invert ? progress_ : 1.F - progress_;
133 int limit_int = (int)limit;
135 while (y < limit_int) {
136 screen.at(x, y++) = charset_vertical[8];
139 screen.at(x, y++) = charset_vertical[int(8 * (limit - limit_int))];
141 screen.at(x, y++) = charset_vertical[0];
147 screen.PixelAt(x, y).inverted ^=
true;
163 return std::make_shared<Gauge>(progress, 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 gaugeDirection(float progress, GaugeDirection)
Draw a high definition progress bar progressing in specified direction.
Element gaugeDown(float progress)
Draw a high definition progress bar progressing from top to bottom.