Basic auto resizing is working!
« on: 21 July 2013, 19:55:10 »
My basic auto resizing is up and running. When the window resizes, widget can change it's position and size.

class ResizeBehaviour
{
        public:
        bool changeX = false;
        bool changeY = false;
        bool changeWidth = false;
        bool changeHeight = false;
};
 

In my main Gui class (which controlls callbacks etc) I have:
std::vector<std::pair<tgui::Widget::Ptr, ResizeBehaviour>> m_widgets;

ResizeBehaviour & addWidget(tgui::Widget::Ptr wptr);
 

I use it like this inside gui class:
tgui::Wiget::Ptr widget(tgui);
auto rb = addWiget(widget);
rb.changeWidth = true;
rb.changeHeight = true;
 

And then when resizing, the widget keeps its position but changes its size according to resize delta.
There is simple code which does this:
if (m_app.input.isResized())
        {
                auto delta = m_app.input.getResizeDelta(); //it's vector2i
               
                for (auto &i : m_widgets)
                {
                        auto position = i.first->getPosition();
                        auto size = i.first->getSize();
                       
                        if (i.second.changeX)
                        {
                                i.first->setPosition(position.x + delta.x, position.y);
                                position = i.first->getPosition();
                        }
                        if (i.second.changeY) i.first->setPosition(position.x, position.y + delta.y);
                       
                        if (i.second.changeWidth)
                        {
                                i.first->setSize(size.x + delta.x, size.y);
                                size = i.first->getSize();
                        }
                        if (i.second.changeHeight) i.first->setSize(size.x, size.y + delta.y);
                }
       }
 

It works very well. It's nothing like fancy layouting but it does its job and doesn't force you to write hundreds of onResize functions (I used to do that, meh!). Actually with little effort I have now a nice resizable layout in my gui!

Now my question is if you'd like to see it in TGUI (for example until you write layouting which as you said won't be complete in 0.6). We could discuss how I can change it to integrate it into TGUI in clean way.
Of course I understand that it isn't commonly used way to handle resizing - I created it for my very specific needs. So tell me what you think, if it's worth to implement something like that inside TGUI.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Basic auto resizing is working!
« Reply #1 on: 21 July 2013, 20:22:56 »
I don't have the time to look into this right now, but I have a small question.

How do you know when the widgets need to be resized?
The resize event tells that the window gets resized, but because the view stays the same, everything gets stretched by default. The resizing and repositioning should happen when the the view gets changes, right? Then you would have to call some function to resize the gui.

Could you also send me a more full code, because I still don't completely get the picture of how the gui responds exactly.

Re: Basic auto resizing is working!
« Reply #2 on: 21 July 2013, 20:27:35 »
How do you know when the widgets need to be resized?
The resize event tells that the window gets resized, but because the view stays the same, everything gets stretched by default. The resizing and repositioning should happen when the the view gets changes, right? Then you would have to call some function to resize the gui.

My engine changes the view automatically when there is resized event. But not everyone does it. So if we want to implement it into TGUI it must be disabled by default with option to enable it if you change the view during resizing yourself.

Quote
Could you also send me a more full code, because I still don't completely get the picture of how the gui responds exactly.
I will prepare a simple one-file full code that demonstrates it. Just give me a few mins.

EDIT:
It may take a bit more time because it depends on my engine and I need to cut input class from it to make it simple.
« Last Edit: 21 July 2013, 20:31:23 by netrick »

Re: Basic auto resizing is working!
« Reply #3 on: 21 July 2013, 21:01:42 »
Minimal-yet-full code is done. However I found some strange bug and I will need to fix it. I will post here when I fix it with uploaded file. I don't know how long will it take to fix it though.

Basically in some conditions the positions and sizes mess up completely. It's strange because 90% of the time the resizing works great. I have an idea where the bug is though.
« Last Edit: 21 July 2013, 21:05:54 by netrick »

Re: Basic auto resizing is working!
« Reply #4 on: 21 July 2013, 21:20:57 »
Huh, I need to redesign it because now it doesn't work when you make the window too small... Well, I will write here tommorow with fixed design. I made it too simple...

Re: Basic auto resizing is working!
« Reply #5 on: 26 July 2013, 20:47:57 »
I won't be able to finish this anytime soon - unfortunately I have no time to work on my project currently. However when I manage to get some time, I will rewrite it.

*

texus

  • *****
  • 1161
    • View Profile
    • Texus's Blog
Re: Basic auto resizing is working!
« Reply #6 on: 26 July 2013, 22:47:25 »
Alright. Take your time, there's no hurry.