NotNotTech / Raylib-CsLo

autogen bindings to Raylib 4.x and convenience wrappers on top. Requires use of `unsafe`
Mozilla Public License 2.0
115 stars 10 forks source link

Bug: Can't change text on GuiTextInputBox #35

Closed mjones409 closed 5 months ago

mjones409 commented 1 year ago

Raylib_CsLo.RayGui.GuiTextInputBox(Rectangle bounds, string? title, string? message, string? buttons, string? text, int textMaxSize = 255) should allow for the editing of the text like the overload version of the method. I suggest adding the ref keyword to the string? text parameter.

jasonswearingen commented 1 year ago

sorry I don't understand what you mean. strings are immutable so ref string wouldn't matter?

could you paste a link to the line you are talking about? and an example showing what your expected behavior is?

mjones409 commented 1 year ago

If you use the bindings to display a GuiTextInputBox, you can not actually input text. It allows you to click in to it, but not change the text in the box by typing like you can in the C version of raygui. Screenshot below of the code:

image

I propose changing all of these bindings where raygui edits the value of the strings and of the ints to be passed by reference and that allows us to keep the functionality and also not have any unsafe methods in the bindings at all unless we want to continue overloading them with sbyte* to keep that option open as well. I've already done the work of converting my code using a library but I do think it would be better if it was baked in to the bindings but I have no idea how to go about autogenerating them so I did it by hand. Here is an example of what I am talking about:

image

You can pass strings and ints by reference with this ref keyword and it works nicely.

image

mjones409 commented 1 year ago

Also, these functions crash when passed a null string, but the others don't. image

I think the C version of raygui can tolerate nulls but I didn't check every function, just a couple. In the case that they can't, I think replacing the 'string?' with 'string' types makes sense so people know not to pass nulls, but the second best thing to do would be this (but I think it could lead to slightly different results between csLo and C): image

I think the best option would be to replace the spanOwners with code like this: image

jasonswearingen commented 5 months ago

it has been a while since I wrote the string marshaling code, and it's complicated, but works. A good workaround to your problem seems to be that You should sanitize your inputs prior to calling the raylib functions.