Hello,
while finishing my latest university game project using my engine, I encountered a giant flaw in my gui libary: I was using absolute positioning, which turned out to be quite a pain for writing game guis accounting different resolutions, since I had to calculate these absolute coordinates accordingly to the screen size everywhere I was using the gui. Now I begin changing from absolute to relative screen coordinates (0.0f - 1.0f), but there are some issues with that, too. Right now, the widgets calculate their absolute coordinates from their parents, if there isn't any parent, then from the screen. However, what about a scrollbar, which should have the height of its parent widget, but have a fixed width, regareless of the parents metrics? Or a square button, that might eigther need to be aligned for the height of a toolbar or the height/width of a respective oriented scrollbar. For normal cases, I could just overload a few methods in the respective widget, but what if there is the need for some interaction?
Take the scrollbar for another example. My scrollbar is made out of two buttons and a fixed slider. With the old, absolute positioning system, layouting this was no problem:
Scrollbar::Scrollbar(int height)
{
// x - y - width - height
m_pUpperButton = new Button(0, 0, 16, 16);
m_pSlider = new Slider(0, 16, 16, height-32);
m_pLowerButton = new Button(0, height-16, 16, 16);
}
Now with the new relative method, I don't have any idea how to unroll this.
Scrollbar::Scrollbar(float height)
{
// x - y - width - height
m_pUpperButton = new Button(0.0f, 0.0f, 0.0f, 0.0f); // this button needs to fit the scrollbars width, so:
m_pUpperButton->SetCapRect(16, 16, 16, 16); // one solution here was to manually cap the size
m_pSlider = new Slider(0.0f, ???, ???, ???); // but what about the slider? It needs to be sized and positioned according to the buttons
m_pLowerButton = new Button(0.0f, ???, 0.0f, 0.0f); // again, we could hack-fix the button to be width*width, but we still don't know how to position him
}
So uhm, how is this normally handled in gui libaries? Obviously there is so many combinations of widgets position parameters that eigther need to be relative, absolute, or semi (the slider actually needs to resize with the scrollbar, but keep the -buttonWidth*2 - offset off its height). I can think of some complicated solutions, requiring a dozen setters and bool flags. I'm sure there is an easier way, isn't there? Thanks in advance for any suggestion!