i would like to know how to create a textbox with SDL2, in C. I can't figure something out. I've looked for gui libs for SDL2, but they are all written in C++. I've thought of using things like gtk, but have no idea about how it will interact with SDL2,and nobody really talk about it.
Asked
Active
Viewed 318 times
1
-
There are several options. ImGui can work on top of SDL2, but it's in C++ (though I don't see why this would be a problem), maybe there are some less-known libraries that do this too. Googling `sdl2 gtk` shows several examples, but I find this slightly questionable: if you remove the window-management part of SDL2 (by replacing it with GTK), what's left? The renderer? I'd replace it with OpenGL, which is more flexible (regardless of whether you switch to GTK or not). – HolyBlackCat Jul 24 '22 at 15:22
-
1A web search on `sdl2 textbox` produces: [How to create editable text input boxes](https://gamedev.stackexchange.com/q/197232) which outlines the basic approach. Here's an answer of mine that has 100% C code: [How can I display a sudoku solution as an image using C](https://stackoverflow.com/a/67726303/5382650) Also, some C++ examples are _mostly_ C _except_ for some debug msgs with `cout`: https://thenumb.at/cpp-course/sdl2/07/07.html – Craig Estey Jul 24 '22 at 15:56
-
https://github.com/nothings/stb/blob/master/stb_textedit.h – genpfault Jul 24 '22 at 16:10
-
@HolyBlackCat, thx for your answer, first of all, i'm not really at ease with the graphic part of programmation. So i'm trying to get a simple solution, and i must say adding opengl in the eaquation complicates things for me. Also, for the c++ libs, it's sayed i need a wrapper (i guess) and i am seriously lost in all of this – dMight Jul 24 '22 at 16:27
-
ImGui is the easiest option. Forget wrappers. Use a C++ compiler, and if it's so important to you, just avoid C++ features everywhere else. – HolyBlackCat Jul 24 '22 at 16:28
-
@dMight take a look at https://github.com/Immediate-Mode-UI/Nuklear , it even have rendering through SDL2 renderer geometry pipe. If textbox is all you need it'd probably be easier to implement it yourself; it certainly will be a good learning experience. Other than that, I don't suppose any of us know your specific requirements, i.e. what functionality you want from textbox, do you have font rendering, do you use SDL2 renderer or surface blit, etc. – keltar Jul 26 '22 at 07:42
-
@keltar, great, thanks. What i actually want from the textbox is to accept numers only, and numbers from a certain lenght yes, i use a sdl2 renderer – dMight Jul 27 '22 at 09:28