18static const std::string charset_horizontal[11] = {
19#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
23 " ",
" ",
"▏",
"▎",
"▍",
"▌",
"▋",
"▊",
"▉",
"█",
29static const std::string charset_vertical[10] = {
43class Gauge :
public Node {
45 Gauge(
float progress, Direction direction)
46 : progress_(progress), direction_(direction) {
48 if (!(progress_ > 0.F)) {
51 if (!(progress_ < 1.F)) {
56 void ComputeRequirement()
override {
58 case Direction::Right:
60 requirement_.flex_grow_x = 1;
61 requirement_.flex_grow_y = 0;
62 requirement_.flex_shrink_x = 1;
63 requirement_.flex_shrink_y = 0;
67 requirement_.flex_grow_x = 0;
68 requirement_.flex_grow_y = 1;
69 requirement_.flex_shrink_x = 0;
70 requirement_.flex_shrink_y = 1;
73 requirement_.min_x = 1;
74 requirement_.min_y = 1;
79 case Direction::Right:
80 RenderHorizontal(
screen,
false);
83 RenderVertical(
screen,
false);
86 RenderHorizontal(
screen,
true);
89 RenderVertical(
screen,
true);
94 void RenderHorizontal(Screen&
screen,
bool invert) {
95 const int y = box_.y_min;
102 const float progress = invert ? 1.F - progress_ : progress_;
104 float(box_.x_min) + progress * float(box_.x_max - box_.x_min + 1);
105 const int limit_int =
static_cast<int>(limit);
107 while (x < limit_int) {
108 screen.at(x++, y) = charset_horizontal[9];
111 screen.at(x++, y) = charset_horizontal[int(9 * (limit - limit_int))];
112 while (x <= box_.x_max) {
113 screen.at(x++, y) = charset_horizontal[0];
118 for (
int x = box_.x_min; x <= box_.x_max; x++) {
119 screen.PixelAt(x, y).inverted ^=
true;
124 void RenderVertical(Screen&
screen,
bool invert) {
125 const int x = box_.x_min;
126 if (x > box_.x_max) {
132 const float progress = invert ? progress_ : 1.F - progress_;
134 float(box_.y_min) + progress * float(box_.y_max - box_.y_min + 1);
135 const int limit_int =
static_cast<int>(limit);
137 while (y < limit_int) {
138 screen.at(x, y++) = charset_vertical[8];
141 screen.at(x, y++) = charset_vertical[int(8 * (limit - limit_int))];
142 while (y <= box_.y_max) {
143 screen.at(x, y++) = charset_vertical[0];
148 for (
int y = box_.y_min; y <= box_.y_max; y++) {
149 screen.PixelAt(x, y).inverted ^=
true;
167 return std::make_shared<Gauge>(progress, direction);
Direction
Direction est une énumération qui représente les quatre directions cardinales.
void Render(Screen &screen, const Element &element)
Affiche un élément sur un ftxui::Screen.
L'espace de noms FTXUI ftxui::
Element gaugeDirection(float progress, Direction direction)
std::shared_ptr< Node > Element
Element gaugeRight(float progress)
Element gaugeUp(float progress)
Element gaugeLeft(float progress)
Element gauge(float progress)
Element gaugeDown(float progress)