Don't really understand layouts (specifically binding)

Started by crdl_pls, 27 February 2016, 19:34:49


I was looking through the tutorials, trying to understand layouts and binding, and I just have no idea what they are or how they work. I assume they're meant to allow fixing the size/position of one widget based on another widget, but then I don't get binding ranges. Is that to make sure it stays within a specific range?

If anyone could just explain this, I would be really grateful. Thanks  :)


The layouts allow you to make the position or size of a widget relative to a different widget.

The tgui::bindWidth(widget) function for example will as far as you should be concerned just return the same as widget->getSize().x. The only difference is that when the width changes then the place where the layout is used will update as well. If you call widget2->setSize(bindSize(widget1)) then when the size of widget1 changes, the size of widget2 is automatically updated.

The bindRange function is probably the most useless function of all the bind functions (I don't even know a use case for it). If you call widget->setPosition(0, bindRange(min, max, val)) then the top position of the widget will be val unless val is less than min or higher than max. Since min, max and val are expressions that may contain bind functions, once any of the bound values changes, the top position of the widget is recalculated based on the new values.
Maybe I should should remove the bindRange function from the tutorial.


Thanks. I just wanted to be sure that I was using it correctly before I dived headlong into it.

I agree that the bindrange function doesn't have much use, maybe keep it but hide it from the basic tutorial.