Skip to content

Use code point on OnTextInput #517

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

Cn-mjt44
Copy link

In SDL2/3, text input event will only return a complete unicode character. If this part use char in csharp, It can't explane a complete unicode character at one times.

@flibitijibibo
Copy link
Member

I might be mixing up types here but what we're intending to do with the current code is convert from UTF8 to wchar_t, which is what char should be in C#. The text buffer in SDL3 got expanded to support whole strings, which is how we handle console text input. Is there a specific test we can try on the various platforms to see the before/after for this change?

@Cn-mjt44
Copy link
Author

Cn-mjt44 commented Mar 24, 2025

@flibitijibibo No, I'm sorry, I don't have console. So I can't test for console.
But, even it push whole string to SDL_TEXTINPUT, it can still handel this. Because, the logic is essentially turning the UTF-8 string to UTF-32 string. And then foreach every UTF-32 character push to OnTextInput. The UTF32 character is equle to unicode codepoint. So every character will be validity in unicode.

@Cn-mjt44
Copy link
Author

Cn-mjt44 commented Mar 24, 2025

For example, 🤣 is U+1F923. If you try to repecent in c# string(utf-16 string), it take 2 char. If you only takeing one utf-16 character from there, it take no mean for text.

@flibitijibibo
Copy link
Member

Interesting - I wonder if this is a serious problem for platforms where sizeof(wchar_t) is 2 rather than 4.

The overall purpose of the patch makes sense to me but I'm surprised it requires so much manual intervention - should we isolate translation to a helper file maybe? Is this something upstream dotnet should care about?

@Cn-mjt44
Copy link
Author

Cn-mjt44 commented Mar 24, 2025

@flibitijibibo char.ConvertFromUtf32 and char.ConvertToUtf32 can translate betwen the codepoint and c# string. So you not need to do that.

@flibitijibibo
Copy link
Member

flibitijibibo commented Mar 24, 2025

Understood - I've marked this as an extension bug for the moment; if it works locally that's great, but I assume this subject has a bunch of weird caveats so I'll let others chime in to make sure we get the next revision of TextInputEXT correct, since it's hard to modify extensions unless we're really sure the change is both necessary and absolutely correct.

Expect some reviews over time, either way: Thanks for checking this out!

@Cn-mjt44
Copy link
Author

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants