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 {
52 : progress_(progress),
57 if (!(progress_ > 0.F)) {
60 if (!(progress_ < 1.F)) {
65 void ComputeRequirement()
override {
69 requirement_.flex_grow_x = 1;
70 requirement_.flex_grow_y = 0;
71 requirement_.flex_shrink_x = 1;
72 requirement_.flex_shrink_y = 0;
76 requirement_.flex_grow_x = 0;
77 requirement_.flex_grow_y = 1;
78 requirement_.flex_shrink_x = 0;
79 requirement_.flex_shrink_y = 1;
82 requirement_.min_x = 1;
83 requirement_.min_y = 1;
86 void Render(Screen& screen)
override {
89 RenderHorizontal(screen,
false);
92 RenderVertical(screen,
false);
95 RenderHorizontal(screen,
true);
98 RenderVertical(screen,
true);
103 void RenderHorizontal(Screen& screen,
bool invert) {
104 if (box_.y_min > box_.y_max) {
110 const std::string* charset;
115 : charset_horizontal_microsoft;
119 full =
static_cast<int>(
charset_.size()) - 1;
123 const float progress = invert ? 1.F - progress_ : progress_;
125 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
126 const int limit_int =
static_cast<int>(limit);
128 for (
int y = box_.y_min;
y <= box_.y_max;
y++) {
130 while (x < limit_int) {
131 screen.at(x++,
y) = charset[full];
133 if (x <= box_.x_max) {
134 screen.at(x++,
y) = charset[int(full * (limit - limit_int))];
136 while (x <= box_.x_max) {
137 screen.at(x++,
y) = charset[0];
146 void RenderVertical(Screen& screen,
bool invert) {
147 if (box_.x_min > box_.x_max) {
151 const std::string* charset;
154 charset = charset_vertical;
158 full =
static_cast<int>(
charset_.size()) - 1;
162 const float progress = invert ? progress_ : 1.F - progress_;
164 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
165 const int limit_int =
static_cast<int>(limit);
167 for (
int x = box_.x_min; x <= box_.x_max; x++) {
169 while (
y < limit_int) {
170 screen.at(x,
y++) = charset[full];
172 if (
y <= box_.y_max) {
173 screen.at(x,
y++) = charset[int(full * (limit - limit_int))];
175 while (
y <= box_.y_max) {
176 screen.at(x,
y++) = charset[0];
184 void Invert(Screen& screen) {
185 for (
int y = box_.y_min;
y <= box_.y_max;
y++) {
186 for (
int x = box_.x_min; x <= box_.x_max; x++) {
187 screen.CellAt(x,
y).inverted ^=
true;
205 return std::make_shared<Gauge>(progress,
direction);
355 std::vector<std::string> charset,
357 return std::make_shared<Gauge>(progress,
direction, std::move(charset));
Element gaugeDirection(float progress, Direction direction)
指定された方向に進行する高精細プログレスバーを描画します。
Element gaugeRight(float progress)
左から右へ進行する高精細プログレスバーを描画します。
Direction
Directionは、東西南北の4つの基本方向を表す列挙型です。
Element gaugeUp(float progress)
下から上へ進行する高精細プログレスバーを描画します。
Element gaugeCharset(float progress, std::vector< std::string > charset, Direction direction=Direction::Right)
カスタム文字セットを使って高精細なプログレスバーを描画する。
Element gaugeLeft(float progress)
右から左へ進行する高精細プログレスバーを描画します。
Element gauge(float progress)
高精細プログレスバーを描画します。
Element gaugeDown(float progress)
上から下へ進行する高精細プログレスバーを描画します。
Quirks GetQuirks()
ターミナルのクイークを取得します。
std::shared_ptr< Node > Element
void Render(Screen &screen, Node *node, Selection &selection)