Semi-automatic resize handling by widgets

Started by netrick, 17 July 2013, 16:57:15


I'm currently working on something I really need and I call it "semi-automatic resize handling". The idea is very simple:

Code (cpp) Select

classs GuiManager
   std::map<tgui::Widget::Ptr, ResizeBehaviour> widgets; //I store pointers to widget in this class

struct ResizeBehaviour
  bool changeX = false;
  bool changeY = false;
  bool changeWidth = false;
  bool changeHeight = false;

Then we have function:

GuiManger::handleResize(int deltaX, int deltaY) //called when resize SFML event happens
   //when a widget has for example changeX set to true
   //then widget->x += deltaX etc.

This allows for very basic layouting (altough I use similar method and it works very well for handling resizing in gui!).
My problem is that tgui::Widget doesn't have virtual set/get Size function. Thus I can't make it as simple as in the above code.

What is the reason why there can't be even empty virtual setSize function in widget? Basically every widget has its size (unless it's container widget and then we can happily don't implement the virtual function body).

It's very simple way of handling basically the biggest TGUI problem (at least for me) and after some tuning (this code isn't really integrated into TGUI) I could write a patch.

However I really need that size in tgui::Widget class. Is it possible to place empty virtual function in the class? I think it won't hurt.

If it's not possible, do you have any other idea how I can workaround it?


I wouldn't mind having a setSize in Widget, I even already wanted to do this before.

But what bothered me whas that Label and Grid (and possibly others) don't have a setSize function.
I could do what you say and just not implement them, but someone might see that label has a setSize function and might try to use it. And then unexpectedly, the function call wouldn't had any effect.

Basically I didn't move the function to Widget because it wasn't needed. And I didn't see a reason to create confusion for nothing. But if it helps then I will do it. It would also allow having a setScale function for every object.

So I'll make the change and you'll hear from my again tomorrow (or in a few hours if everything goes very well).


Thanks :)

On the unexpected usage when it's empty - I don't know how doxygen works, but if you set description in widget::set/getSize() that it does nothing and don't implement it in children class, will the description from base class appear or no description at all? If it's the first case then problem is solved.


Important thing is that virtual getSize() must be implemented as well. I think it should return empty vector by default, so it's shows 0x0 dimensions ie no size at all.


It depends on how doxygen is configured. Currently it is the second situation.

What I can do is to make the function pure virtual and add empty functions to the derived classes with a documentation saying that the function does nothing.

The widgets that don't implement a setSize function are: Label, Grid, MenuBar and Tab.
And label actually already has a not-working setSize function.

Maybe I'll find some alternative uage for the function (e.g. for tabs set the height and maximum tab width for a single tab instead of width and height for the whole widget).


Pure virtual seems like a good choice.


Look at my new topic in feature requests - it adds another usage for setSize that currently does nothing.


setSize is now accessible in Widget.
The functions for Label, Tab and Grid are still empty though. MenuBar now has a setSize function instead of just its setHeight.

The new documentation will be uploaded in a few minutes.