I appreciate the idea behind your project of a low level gui widget toolkit. I was looking for a SDL based toolkit like this for some time now.
Thank you Matthias.
make a simple documentation
Yes i have thought that, but then i thought, what should it be, like an explanation of the examples, or then like a reference of all functions, structures and variables. The problem with that is, that when the documentation is long, then this gives to users an impression that the project is very complex, when in fact it isn't. But thank you for suggestions, i would try to write it, when i get a clear idea what exactly to write.
What widgets are implemented?
A window, multiline label, button, select button, vertical scrollbar, horizontal scrollbar, progress bar, entry box, text box, and combo box.
How to create your own widget?
Do you mean, create your own custom widget, different from the standard widgets? There are four ways to do that. First is to create a composite widget, from several other widgets, a combo box is an example of this. Second is a user added functionality. Write your own event function and call the standard function from that. Then functionlity can be added in case when the standard function returns nonzero, but also new reactions to mouse and keyboard events can be added. This has to be done the same way it is done in the standard widget event functions though, like at least it should be first checked whether the widget is visible. Third, the functionality can also be added in case if the event is a NULL pointer. Like for games it may be important to add time dependent effects to widgets, like making them to continuously change shape, rather than being static. A progress bar is an example of this. And fourth is to write your own widget, by copying the structure and functions of a standard widget, and modifying them.
code example, how to get a basic button
The new function for a button calculates its rectangle, copies the button's text and calculates its position, assigns the window argument to the member of its structure, and initializes other members of its structure to zero. The event fuction first writes one to the draw argument when the SDL window is exposed. Then it checks whether the button or the dialog window of the button has a mouse focus, and returns from the function if neither is true. Then it checks the mouse buttons and mouse motion, changes the state of the button based on these events, and returns nonzero when the button is released. A button has three states, normal (active 0, prelight 0), prelight (prelight 1) and active (active one). Normal is when the mouse pointer is not on the button, prelight is when the mouse pointer is on the button, and active is when the button is pressed. A separate image corresponds to each of these states, like in Windows widgets these images have a 3D look. The draw function makes the button visible, when its dialog window is visible. It then renders the image that corresponds to the current state of the button, and renders text to the button.
How to manage the widgets (object oriented vs. procedural approach)?
No it is not object oriented, each widget has its own structure, it is not more complicated. There are no callbacks or signals and slots. For managing widget, one simply writes ones own event function, and calls the standard event function in that function. The standard function returns nonzero when the widget needs a reaction, like when a button is pressed, this enables to write the reaction. It is not made using callbacks, because callbacks only enable to write the reaction, while this approach enables the user to add functionality.
Another question I got, is there a focus feature implemented, e.g. can there be two widgets next to each other and you can switch from one to another?
This is not exactly what focus is. A widget has a mouse focus when it processes the mouse events. Widget has a focus when its dialog window has a focus, or when the widget itself has a focus. The former enables a window with all its widgets to take focus, like when a window pops up, then focus can be removed from the window below it. The latter enables a single widget to get focus, so that mouse events don't affect any other widgets. Yes focus can be switched from one widget to the other, the other question is when is it useful. Yes focus is implemented.
There are two buttons next to each other, the focus can be switched by tab from one to another
It is not necessary for buttons to take focus, or then i see no reason. I don't think it is necessary to select the widgets in the graphical user interface using keyboard, at least i have not seen anyone who does that. One can implement it of course, it is possible, though i don't see what need could there be for that. What concerns keyboard focus, then currently only an entry box (or an entry box in a combo box) gets the keyboard focus, when it's open. By focus i mean mouse focus though, if not explicitly said keyboard focus.
There are two widget forms (are there forms at all?), one of which is layered above the other form. By clicking on the form below it will become active and be shown in front of the other form.
There is a confusion of terms, used in one or another widget toolkit. I don't know what exactly one may mean by form. There are windows, and widgets can be on these windows, so that when a window becomes visible, all widgets on it become visible. Such window is called a dialog window i think, at least in some widget toolkits. Do you mean like tabs, when you press on one of the tabs, the corresponding dialog becomes visible? Yes this can be done, for that just the visibility member of the structure of the window below has to be assigned nonzero, and the visibility member of the structure of the window in front has to be assigned zero, it's that simple. The window below then becomes visible, the window in front becomes invisible, and it also will not react to any events.
Have fun and, when you use that toolkit, or a modified version of it, in any of your game or application, then please show us your screenshots
kiss_sdl - Simple universal GUI widget toolkit for SDL2 https://github.com/actsl/kiss_sdl