-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
[text] Add DrawText() functions that take a specified length #1527
Comments
@schveiguy Sorry, no plans to redesign the library to accept an extra input paramater that, actually, it's not required in C language by design. In any case, raylib uses a custom |
Unfortunately no, because the parameter is still only a There are plenty of precedents of C functions that do not require null termination for character data, but you are right that the "normal" string type in C is simply a null-terminated The more wide-spread use case (even for C) is when you have data that does not contain a null character that you can't modify for some reason. Like if you only wanted to show the first N characters of a string. And FWIW, I wasn't requesting a redesign, just additional overloads. |
Sorry then, no plans to add those additional functions for the moment... |
Issue description
I am using raylib as a teaching tool for the D programming language. It is a wonderfully thought out and simple library, and I'm enjoying my time with it. One thing that sticks out to me when using from D is the requirement for text to be Null terminated. In most modern programming languages (D included), text consists of an array, which carries a length attribute, which makes null termination awkward and cumbersome.
Indeed, in the first line of
DrawText
, the code figures out the length of the text by scanning for the null terminator. A set of overloads that would accept pointer + length would be most appreciated, and the existing functions changed to wrappers that first fetch the length by searching for Null.In D, it is quite cumbersome to work with string data that is null terminated, and generally the requirement is to call
toStringz
which allocates a new string that is null terminated when needed. Given that raylib doesn't really require null termination (and immediately converts it to a length variable in the first line of code), I think this should be a simple change. I'm willing to generate a PR if you wish.I would recommend
DrawTextN*
for the name variant, for precedents likestrncopy
andsnprintf
.I will also note that I think this is only relevant for the
DrawText
family of functions, because it is the only reasonable place where generated text is needed. Literals for passing to e.g.InitWindow
can include the null character in the literal easily enough.Environment
N/A
Issue Screenshot
N/A
Code Example
In D:
The text was updated successfully, but these errors were encountered: