20static const std::string charset_horizontal[11] = {
21#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
24 " ",
" ",
" ",
" ",
"▌",
"▌",
"▌",
"█",
"█",
"█",
26 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
33static const std::string charset_vertical[10] = {
48class Gauge :
public Node {
50 Gauge(
float progress,
Direction direction)
51 : 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 const int y = box_.y_min;
102 if (y > box_.y_max) {
109 const float progress = invert ? 1.F - progress_ : progress_;
111 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
112 const int limit_int =
static_cast<int>(limit);
114 while (x < limit_int) {
115 screen.at(x++, y) = charset_horizontal[9];
118 screen.at(x++, y) = charset_horizontal[int(9 * (limit - limit_int))];
119 while (x <= box_.x_max) {
120 screen.at(x++, y) = charset_horizontal[0];
125 for (
int x = box_.x_min; x <= box_.x_max; x++) {
126 screen.PixelAt(x, y).inverted ^=
true;
131 void RenderVertical(Screen& screen,
bool invert) {
132 const int x = box_.x_min;
133 if (x > box_.x_max) {
140 const float progress = invert ? progress_ : 1.F - progress_;
142 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
143 const int limit_int =
static_cast<int>(limit);
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];
156 for (
int y = box_.y_min; y <= box_.y_max; y++) {
157 screen.PixelAt(x, y).inverted ^=
true;
174 return std::make_shared<Gauge>(progress, direction);
Element gaugeDirection(float progress, Direction direction)
指定された方向に進行する高精細プログレスバーを描画します。
Direction
Directionは、東西南北の4つの基本方向を表す列挙型です。
Element gaugeRight(float progress)
左から右へ進行する高精細プログレスバーを描画します。
Element gaugeUp(float progress)
下から上へ進行する高精細プログレスバーを描画します。
Element gaugeLeft(float progress)
右から左へ進行する高精細プログレスバーを描画します。
void Render(Screen &screen, const Element &element)
要素をftxui::Screenに表示します。
Element gauge(float progress)
高精細プログレスバーを描画します。
Element gaugeDown(float progress)
上から下へ進行する高精細プログレスバーを描画します。
std::shared_ptr< Node > Element