So, I'm still working on my small GUI "library". (C++ with boost) The goal is to provide a simple solution for small SPI displays, using a Raspberry or some embedded board.
Thus, I ended up having a Widget class from which concrete widgets are derived. Examples would be a textbox or an image frame. Widgets can contain other widgets to allow groups. This is achieved via aggregation using a STL container. In the end, the complete GUI dataset can be seen as some kind of tree, with some nodes having child nodes.
Each widget shall have a draw-method which looks like
void drawMe(brush *myBrush);
A brush provides primitive drawing methods like "setPixel" or "drawRectangle" This allows the widget to draw itself, using the methods provided by the brush. A widget first draws itself, then it invokes the drawMe-method of each child widget, if any.
Now lets talk about my problem. Each widget has its coordinates, relative to the parent. This is not enough, the brush needs the absolute coordinate of the widget, because a brush does not know anything about children or parents. A brush just provides methods like setPixel(int x, int y) and draws into a pixel buffer.
But I somehow have a bad feeling letting a widgets know its absolute coordinates. This feels wrong. On the other hand, at the moment a child does not know it is owned by a parent, thus, there's no way a widget can compute its absolute coordinates.
I can implement workaround in the brush, so that the brush supports multiple layers instead of just one canvas (the pixel buffer). A parent then has to set up the layers for its child. Sounds like a dirty hack.
Also, is it a good idea to et the parent know its child coordinates?
You see, I'm somewhere lost with this issues. There are GUI frameworks out there, like QT and stuff. So, my problem should be known and solved already. Do you have any suggestions? How would you implement the drawing process?
The whole project is about learning new stuff, mainly OOP paradigms. I like to hear your opinion on that.