Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » U++ Library support » U++ Library : Other (not classified elsewhere) » [Feature request] Relative positioning
Re: [Feature request] Relative positioning [message #48778 is a reply to message #48644] Thu, 14 September 2017 12:27 Go to previous message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
Working with my code I realized that there is a big weak point: No widget that is not a direct child of the TopWindow is getting resized.
So I reworked my script and came up with this (IMO better) solution:
#ifndef _AutoResizeCtrl_h_
#define _AutoResizeCtrl_h_

#include <CtrlLib/CtrlLib.h>
using namespace Upp;

#include <type_traits>

template<typename T>
class AutoResizeCtrl : public T
{
    // Make sure the base class inherits or is Ctrl
    static_assert(std::is_base_of<Ctrl, T>::value, "T must inherit from Ctrl");

private:
    bool initialization;
    bool addedChildren;
    Rect initializationRect;
    Vector<Rect> childrenInitializationRects;

public:
    AutoResizeCtrl<T>()
        : T()
    {
        initialization = true;
        addedChildren = false;
    }
	
    virtual void Layout()
    {
        Rect currentRect = GetRect();
        if(initialization)
            initializationRect = currentRect;
		
        float sizeXChange = (float)currentRect.Width()	/ (float)initializationRect.Width();
        float sizeYChange = (float)currentRect.Height()	/ (float)initializationRect.Height();
		
	Ctrl* pChild = GetFirstChild();
	for(int i = 0; pChild != NULL; i++)
	{
            if(initialization)
	    {
		childrenInitializationRects.Add(pChild->GetRect());
		addedChildren = true;
	    }
			
	    float rectLeft	= childrenInitializationRects[i].left * sizeXChange;
	    float rectTop	= childrenInitializationRects[i].top * sizeYChange;
	    float rectSizeX	= childrenInitializationRects[i].Width() * sizeXChange;
	    float rectSizeY	= childrenInitializationRects[i].Height() * sizeYChange;
			
	    pChild->SetRect(rectLeft, rectTop,
	    		    rectSizeX, rectSizeY);
	    pChild->Layout();
	    pChild = pChild->GetNext();
	}
	initialization = !addedChildren;
    }
};

#endif


For an example how to use it please check the attached package.


Greetings
Daniel

[Updated on: Thu, 14 September 2017 12:31]

Report message to a moderator

 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: [Bug (minor)]: CenterScreen not working
Next Topic: reference/OpenGL crashes
Goto Forum:
  


Current Time: Sun Dec 08 04:35:56 CET 2019

Total time taken to generate the page: 0.01062 seconds