mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-17 16:38:09 +08:00
Support combining characters. (#121)
Modify the ftxui::Pixel. Instead of storing a wchar, store a std::wstring. Now a single pixel can store multiple codepoints. If a codepoint is of size <=0, it will be appended to the previous pixel. Only ftxui::text() is supported. ftxui::vtext support still needs to be added. This causes the following CPU and memory regression: - Memory: Pixel size increases by 200% (16 byte => 48byte). - CPU: Draw/Second decrease by 62.5% (16k draw/s => 6k draw/s on 80x80) Both regressions are acceptable. There are still two orders of magnitude (100x) before the levels where performance/memory concerns begins. This fixes: https://github.com/ArthurSonzogni/FTXUI/issues/109
This commit is contained in:
@@ -164,17 +164,14 @@ std::string Screen::ToString() {
|
||||
}
|
||||
for (int x = 0; x < dimx_;) {
|
||||
auto& pixel = pixels_[y][x];
|
||||
wchar_t c = pixel.character;
|
||||
UpdatePixelStyle(ss, previous_pixel, pixel);
|
||||
|
||||
auto width = wchar_width(c);
|
||||
if (width <= 0) {
|
||||
// Avoid an infinite loop for non-printable characters
|
||||
c = L' ';
|
||||
width = 1;
|
||||
int x_inc = 0;
|
||||
for (auto& c : pixel.character) {
|
||||
ss << c;
|
||||
x_inc += wchar_width(c);
|
||||
}
|
||||
ss << c;
|
||||
x += width;
|
||||
x += std::max(x_inc, 1);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +188,7 @@ void Screen::Print() {
|
||||
/// @param x The character position along the x-axis.
|
||||
/// @param y The character position along the y-axis.
|
||||
wchar_t& Screen::at(int x, int y) {
|
||||
return PixelAt(x, y).character;
|
||||
return PixelAt(x, y).character[0];
|
||||
}
|
||||
|
||||
/// @brief Access a Pixel at a given position.
|
||||
|
Reference in New Issue
Block a user