I'm not really sure where to direct this question, so I guessed graphics as the most appropriate subforum.
I'm attempting to implement a kind of GUI toolkit for SFML. This project actually started some months ago now. I'm aware that such things already exist but I wanted a GUI library to do a specific thing which is why I started my own.
I put this project on hold and then had another idea for something else recently so I've started work on it again. I didn't actually get very far in the first place.
So far I have something like this:
1: A base class which inherits sf::Drawable. This class also adds an "event" function which events are passed to
2: Some gui objects, textbox, button, context menu, which inherit from the base class
3: Some of my gui objects are nested, ie; the context menu has context menu items
My question is about drawing these objects.
All the gui objects have a sf::RectangleShape which is used to draw the background of the object.
The override draw method calls
sf::RenderTarget target;
target.draw(background);
This is just to show the basic principle of how everything is going to work.
At the moment, for all my objects, I have a setPosition method which changes the sf::RectangleShape position.
For my example of context menu, which has a parent-child relationship in that several context menu items are children of the parent, I am unsure of how to proceed here.
One possibly solution is to use absolute positions, which is what sfml seems to want to use. In this way, if the position of the context menu is changed, then the positions of all the child items would also have to be changed.
This doesn't seem like a good solution, since I would prefer to store the relative locations of the child objects relative to the parent rather than the absolute position in the window.
Is there a better way of approaching this problem?