Prefer std::string over std::wstring. (#179)

In the past, FTXUI switched from std::string to std::wstring to support
fullwidth characters. The reasons was that fullwidth characters can be
stored inside a single wchar_t.

Then FTXUI added support for combining characters. A single glygh
doesn't even fit a wchar_t. Instead, a glyph can be arbitrary large.

The usage of wstring doesn't really fit the new model and have several
drawbacks:
1. It doesn't simplify the implementation of FTXUI, because of combining
   characters.
2. It reduces drawing performance by 2x.
3. It increase Screen's memory allocation by 2x.

This patch converts FTXUI to use std::string internally. It now exposes
std::string based API. The std::wstring API remains, but is now
deprecated.

Tests and examples haven't been update to show the breakage is limited.
They will be updated in a second set of patches.

Bug: https://github.com/ArthurSonzogni/FTXUI/issues/153
Co-authored-by: Tushar Maheshwari <tushar27192@gmail.com>
This commit is contained in:
Arthur Sonzogni
2021-08-08 23:25:20 +02:00
committed by GitHub
parent 1ff894f6f5
commit 3b4ab618a3
84 changed files with 1234 additions and 996 deletions

View File

@@ -17,7 +17,7 @@ namespace ftxui {
template <class T>
class SliderBase : public ComponentBase {
public:
SliderBase(StringRef label, T* value, T min, T max, T increment)
SliderBase(ConstStringRef label, T* value, T min, T max, T increment)
: label_(label),
value_(value),
min_(min),
@@ -31,9 +31,9 @@ class SliderBase : public ComponentBase {
return hbox({
text(*label_) | dim | vcenter,
hbox({
text(L"["),
text("["),
gauge(percent) | underlined | xflex | reflect(gauge_box_),
text(L"]"),
text("]"),
}) | xflex,
}) |
gauge_color | xflex | reflect(box_);
@@ -87,7 +87,7 @@ class SliderBase : public ComponentBase {
bool Focusable() const final { return true; }
private:
StringRef label_;
ConstStringRef label_;
T* value_;
T min_;
T max_;
@@ -110,7 +110,7 @@ class SliderBase : public ComponentBase {
/// ```cpp
/// auto screen = ScreenInteractive::TerminalOutput();
/// int value = 50;
/// auto slider = Slider(L"Value:", &value, 0, 100, 1);
/// auto slider = Slider("Value:", &value, 0, 100, 1);
/// screen.Loop(slider);
/// ```
///
@@ -120,23 +120,23 @@ class SliderBase : public ComponentBase {
/// Value:[██████████████████████████ ]
/// ```
template <class T>
Component Slider(StringRef label, T* value, T min, T max, T increment) {
Component Slider(ConstStringRef label, T* value, T min, T max, T increment) {
return Make<SliderBase<T>>(std::move(label), value, min, max, increment);
}
template Component Slider(StringRef label,
template Component Slider(ConstStringRef label,
int* value,
int min,
int max,
int increment);
template Component Slider(StringRef label,
template Component Slider(ConstStringRef label,
float* value,
float min,
float max,
float increment);
template Component Slider(StringRef label,
template Component Slider(ConstStringRef label,
long* value,
long min,
long max,