Support full-width characters (CJK)

+ 3 tests.

The goal is to fix:
https://github.com/ArthurSonzogni/FTXUI/issues/2#issuecomment-504871456
This commit is contained in:
ArthurSonzogni
2019-06-24 23:39:37 +02:00
parent 9c1913de51
commit eb6baaceea
8 changed files with 358 additions and 16 deletions

View File

@@ -1,4 +1,5 @@
#include "ftxui/dom/node.hpp"
#include "ftxui/screen/string.hpp"
namespace ftxui {
@@ -10,7 +11,7 @@ class Text : public Node {
~Text() {}
void ComputeRequirement() override {
requirement_.min.x = text_.size();
requirement_.min.x = wstring_width(text_);
requirement_.min.y = 1;
}
@@ -22,7 +23,8 @@ class Text : public Node {
for (wchar_t c : text_) {
if (x > box_.x_max)
return;
screen.at(x++, y) = c;
screen.at(x, y) = c;
x += wchar_width(c);
}
}