2018-10-10 01:06:03 +08:00
|
|
|
#include "ftxui/dom/elements.hpp"
|
2020-03-23 05:32:44 +08:00
|
|
|
#include "ftxui/dom/node.hpp"
|
2018-09-20 03:52:25 +08:00
|
|
|
|
2019-01-12 22:00:08 +08:00
|
|
|
namespace ftxui {
|
2019-01-07 00:10:35 +08:00
|
|
|
|
2018-09-22 15:49:43 +08:00
|
|
|
static wchar_t charset[] = L" ▏▎▍▌▋▊▉█";
|
|
|
|
|
2018-09-20 03:52:25 +08:00
|
|
|
class Gauge : public Node {
|
|
|
|
public:
|
|
|
|
Gauge(float progress) : progress_(progress) {}
|
2018-09-22 15:49:43 +08:00
|
|
|
~Gauge() override {}
|
2018-09-20 03:52:25 +08:00
|
|
|
|
|
|
|
void ComputeRequirement() override {
|
|
|
|
requirement_.flex.x = 1;
|
|
|
|
requirement_.min.y = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Render(Screen& screen) override {
|
2019-01-20 05:06:05 +08:00
|
|
|
float y = box_.y_min;
|
|
|
|
float limit = box_.x_min + progress_ * (box_.x_max - box_.x_min + 1);
|
2018-09-22 15:49:43 +08:00
|
|
|
int limit_int = limit;
|
2019-01-20 05:06:05 +08:00
|
|
|
int x = box_.x_min;
|
2018-09-22 15:49:43 +08:00
|
|
|
while (x < limit_int)
|
|
|
|
screen.at(x++, y) = charset[9];
|
2020-03-23 05:32:44 +08:00
|
|
|
screen.at(x++, y) = charset[int(9 * (limit - limit_int))];
|
2019-01-20 05:06:05 +08:00
|
|
|
while (x <= box_.x_max)
|
2018-09-22 15:49:43 +08:00
|
|
|
screen.at(x++, y) = charset[0];
|
2018-09-20 03:52:25 +08:00
|
|
|
}
|
2020-03-23 05:32:44 +08:00
|
|
|
|
2018-09-20 03:52:25 +08:00
|
|
|
private:
|
|
|
|
float progress_;
|
|
|
|
};
|
|
|
|
|
|
|
|
std::unique_ptr<Node> gauge(float progress) {
|
|
|
|
return std::make_unique<Gauge>(progress);
|
|
|
|
}
|
|
|
|
|
2020-02-12 04:44:55 +08:00
|
|
|
} // namespace ftxui
|