Semi-automatic resize handling by widgets
« on: 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:

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?

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Semi-automatic resize handling by widgets
« Reply #1 on: 17 July 2013, 17:28:09 »
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).

Re: Semi-automatic resize handling by widgets
« Reply #2 on: 17 July 2013, 17:41:32 »
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.

Edit:

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.
« Last Edit: 17 July 2013, 17:48:21 by netrick »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Semi-automatic resize handling by widgets
« Reply #3 on: 17 July 2013, 17:47:32 »
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).

Re: Semi-automatic resize handling by widgets
« Reply #4 on: 17 July 2013, 17:51:12 »
Pure virtual seems like a good choice.

Edit:

Look at my new topic in feature requests - it adds another usage for setSize that currently does nothing.
« Last Edit: 17 July 2013, 17:54:25 by netrick »

*

texus

  • *****
  • 1143
    • View Profile
    • Texus's Blog
Re: Semi-automatic resize handling by widgets
« Reply #5 on: 17 July 2013, 19:06:05 »
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.

Re: Semi-automatic resize handling by widgets
« Reply #6 on: 17 July 2013, 21:03:55 »
Thank you.