Closed dpwiz closed 2 years ago
GHC.Foreign
is encoding-aware :thinking:
https://hackage.haskell.org/package/base-4.15.0.0/docs/GHC-Foreign.html#v:withCString
Due to how text labels are used in the dearimgui code perhaps would be better to use a special Label
data type.
There are 3 cases:
IDK if a completely empty label is allowed.
They can be set up at runtime, or compile time.
CString
.I think current String
arguments should use such a Label
instead, with IsString
(IsLabel
for type-3 labels?) instance and TH/QQ wrappers.
I was looking through C++ code and found that it assumes its text data is in UTF-8.
This may not be necessarily the case, since
Foreign.withCString
is locale-dependent and some users may have ASCII/C or some other national locales. This regularly trips up Windows users with symptoms like "invalid argument (invalid character)".Besides, using
withCString
will waste CPU on the same[Char] -> CString
conversion for every call on every frame. While the raw bindings are exempt from this churn, the library can provide smart constructors that will take in something likeText
, encode to UTF8ByteString
once and then use its pointer for raw calls. Anyway, even with Text-to-BS encoding happening every frame at least it will be correct for any environment.