mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2024-11-25 20:27:31 +08:00
Fix Gauge of size zero. (#200)
This commit is contained in:
parent
b99106a7c9
commit
ed28bad02a
@ -23,16 +23,17 @@ std::string GeneratorString(const char*& data, size_t& size) {
|
|||||||
while (index < size && data[index])
|
while (index < size && data[index])
|
||||||
++index;
|
++index;
|
||||||
|
|
||||||
|
auto out = std::string(data, data + index);
|
||||||
|
data += index;
|
||||||
|
size -= index;
|
||||||
|
|
||||||
|
// The input component do not support invalid UTF8 yet.
|
||||||
try {
|
try {
|
||||||
auto out = std::string(data, data + index);
|
to_wstring(out);
|
||||||
auto w_out = to_wstring(out);
|
|
||||||
data += index;
|
|
||||||
size -= index;
|
|
||||||
return std::move(out);
|
|
||||||
} catch (...) {
|
} catch (...) {
|
||||||
// The input component do not support invalid UTF8 yet.
|
|
||||||
return "0";
|
return "0";
|
||||||
}
|
}
|
||||||
|
return std::move(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
int GeneratorInt(const char* data, size_t size) {
|
int GeneratorInt(const char* data, size_t size) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
#include <cmath>
|
||||||
#include <memory> // for allocator, make_shared
|
#include <memory> // for allocator, make_shared
|
||||||
#include <string> // for string
|
#include <string> // for string
|
||||||
|
|
||||||
@ -9,7 +10,7 @@
|
|||||||
|
|
||||||
namespace ftxui {
|
namespace ftxui {
|
||||||
|
|
||||||
static std::string charset[] = {
|
static std::string charset[11] = {
|
||||||
#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
|
#if defined(FTXUI_MICROSOFT_TERMINAL_FALLBACK)
|
||||||
// Microsoft's terminals often use fonts not handling the 8 unicode
|
// Microsoft's terminals often use fonts not handling the 8 unicode
|
||||||
// characters for representing the whole gauge. Fallback with less.
|
// characters for representing the whole gauge. Fallback with less.
|
||||||
@ -23,7 +24,7 @@ static std::string charset[] = {
|
|||||||
|
|
||||||
class Gauge : public Node {
|
class Gauge : public Node {
|
||||||
public:
|
public:
|
||||||
Gauge(float progress) : progress_(progress) {}
|
Gauge(float progress) : progress_(std::min(std::max(progress, 0.f), 1.f)) {}
|
||||||
|
|
||||||
void ComputeRequirement() override {
|
void ComputeRequirement() override {
|
||||||
requirement_.flex_grow_x = 1;
|
requirement_.flex_grow_x = 1;
|
||||||
@ -35,7 +36,10 @@ class Gauge : public Node {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Render(Screen& screen) override {
|
void Render(Screen& screen) override {
|
||||||
float y = box_.y_min;
|
int y = box_.y_min;
|
||||||
|
if (y > box_.y_max)
|
||||||
|
return;
|
||||||
|
|
||||||
float limit = box_.x_min + progress_ * (box_.x_max - box_.x_min + 1);
|
float limit = box_.x_min + progress_ * (box_.x_max - box_.x_min + 1);
|
||||||
int limit_int = limit;
|
int limit_int = limit;
|
||||||
int x = box_.x_min;
|
int x = box_.x_min;
|
||||||
|
Loading…
Reference in New Issue
Block a user