mirror of
https://github.com/ArthurSonzogni/FTXUI.git
synced 2025-09-19 10:08:10 +08:00
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:
@@ -1,6 +1,7 @@
|
||||
#include <algorithm> // for max
|
||||
#include <iterator> // for begin, end
|
||||
#include <memory> // for make_shared, __shared_ptr_access
|
||||
#include <memory> // for allocator, make_shared, __shared_ptr_access
|
||||
#include <string> // for basic_string, string
|
||||
#include <utility> // for move
|
||||
#include <vector> // for vector, __alloc_traits<>::value_type
|
||||
|
||||
@@ -12,10 +13,11 @@
|
||||
|
||||
namespace ftxui {
|
||||
|
||||
static wchar_t simple_border_charset[] = L"╭╮╰╯─│┬┴┤├";
|
||||
static std::string simple_border_charset[] = {"╭", "╮", "╰", "╯", "─",
|
||||
"│", "┬", "┴", "┤", "├"};
|
||||
|
||||
// For reference, here is the charset for normal border:
|
||||
// L"┌┐└┘─│┬┴┤├";
|
||||
// {"┌", "┐", "└", "┘", "─", "│", "┬", "┴", "┤", "├"};
|
||||
// TODO(arthursonzogni): Consider adding options to choose the kind of borders
|
||||
// to use.
|
||||
|
||||
@@ -29,7 +31,7 @@ class Border : public Node {
|
||||
: Node(std::move(children)), charset_pixel(10, pixel) {}
|
||||
|
||||
std::vector<Pixel> charset_pixel;
|
||||
std::vector<wchar_t> charset;
|
||||
std::vector<std::string> charset;
|
||||
|
||||
void ComputeRequirement() override {
|
||||
Node::ComputeRequirement();
|
||||
@@ -120,10 +122,10 @@ class Border : public Node {
|
||||
///
|
||||
/// ```cpp
|
||||
/// // Use 'border' as a function...
|
||||
/// Element document = border(text(L"The element"));
|
||||
/// Element document = border(text("The element"));
|
||||
///
|
||||
/// // ...Or as a 'pipe'.
|
||||
/// Element document = text(L"The element") | border;
|
||||
/// Element document = text("The element") | border;
|
||||
/// ```
|
||||
///
|
||||
/// ### Output
|
||||
@@ -146,8 +148,8 @@ Element border(Element child) {
|
||||
/// ### Example
|
||||
///
|
||||
/// ```cpp
|
||||
/// Element document = window(text(L"Title"),
|
||||
/// text(L"content")
|
||||
/// Element document = window(text("Title"),
|
||||
/// text("content")
|
||||
/// );
|
||||
/// ```
|
||||
///
|
||||
|
Reference in New Issue
Block a user