Object layout example

Started by netrick, 01 July 2013, 17:56:58

netrick

I wanted to ask you about adding basic layouts to tgui (because manually resizing widgets was a PAIN in my code), but I've just realised that they had been added.

Could you write some simple example code how to use them properly?

texus

#1
What exactly are you talking about? I didn't add layouts.

There is only Grid so far, but this doesn't help against manually resizing.

Depending on what you want to do, you should use a different view to draw the gui. This will allow you to zoom without manually resizing objects.

netrick

I thought Grid was something like layouts in qt. It seems I was wrong. So what is exactly a grid?

Also, the idea with view is a good and easy one - altough that way the text will be stretched :/ And in my game there is a lot of text and I need it to be the same size on every resolution.

texus

Grid will place your objects next to each other, so you don't have to set an exact position.
With the addToRow function you add the object to the right of the previous object and you can use addRow to go to the next row. The addToRow function also optionally takes borders as parameter to put some space between objects. So Grid can be used to make a menu screen by placing buttons beneath each other, without you having to worry about the exact position of the buttons. But Grid doesn't change the size of the objects, you have to set the size yourself.

Although Grid can be compared with the layouts from qt, it still has a lot of limitations.
Support for real layouts is pretty hard. I mostly have to consider how it will be designed, which functions it will have, ...
So this can't be expected before v0.7.

The stretched text is indeed problematic. Depending on where the text is you could draw it with sfml directly with a different view than the gui, but that isn't a great solution either.