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
[Feature request] Relative positioning [message #48644] Fri, 11 August 2017 09:51 Go to next message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
Working on an app with resizable option I discovered that I am not able to resize/reposition the ctrls relative to their original set size/position.
What I am thinking about is a sizing/positioning option so the ctrls get resized/positioned like the following:
1. Original size
index.php?t=getfile&id=5371&private=0
2. X-Size 1.5x
index.php?t=getfile&id=5372&private=0
3. X-Size 2x
index.php?t=getfile&id=5373&private=0
4. Y-Size 1.5x
index.php?t=getfile&id=5374&private=0
5. X-Size 1.5; Y-Size 2x
index.php?t=getfile&id=5376&private=0

Source code for these layouts (a bit formatted for clean review of the important things):
LAYOUT(button_bar, 450, 50)
	ITEM(Button, generate, LeftPosZ( 10,  90).TopPosZ(10, 30))
	ITEM(Button, previous, LeftPosZ(130,  90).TopPosZ(10, 30))
	ITEM(Button, next,     LeftPosZ(230,  90).TopPosZ(10, 30))
	ITEM(Button, cancel,   LeftPosZ(350,  90).TopPosZ(10, 30))
END_LAYOUT

LAYOUT(button_bar_biggerX, 675, 50)
	ITEM(Button, generate, LeftPosZ( 15, 135).TopPosZ(10, 30))
	ITEM(Button, previous, LeftPosZ(195, 135).TopPosZ(10, 30))
	ITEM(Button, next,     LeftPosZ(345, 135).TopPosZ(10, 30))
	ITEM(Button, cancel,   LeftPosZ(525, 135).TopPosZ(10, 30))
END_LAYOUT

LAYOUT(button_bar_biggestX, 900, 50)
	ITEM(Button, generate, LeftPosZ( 20, 180).TopPosZ(10, 30))
	ITEM(Button, previous, LeftPosZ(260, 180).TopPosZ(10, 30))
	ITEM(Button, next,     LeftPosZ(460, 180).TopPosZ(10, 30))
	ITEM(Button, cancel,   LeftPosZ(700, 180).TopPosZ(10, 30))
END_LAYOUT

LAYOUT(button_bar_biggerY, 450, 75)
	ITEM(Button, generate, LeftPosZ( 10,  90).TopPosZ(15, 45))
	ITEM(Button, previous, LeftPosZ(130,  90).TopPosZ(15, 45))
	ITEM(Button, next,     LeftPosZ(230,  90).TopPosZ(15, 45))
	ITEM(Button, cancel,   LeftPosZ(350,  90).TopPosZ(15, 45))
END_LAYOUT

LAYOUT(button_bar_bigger_mixed, 675, 100)
	ITEM(Button, generate, LeftPosZ( 15, 135).TopPosZ(20, 60))
	ITEM(Button, previous, LeftPosZ(195, 135).TopPosZ(20, 60))
	ITEM(Button, next,     LeftPosZ(345, 135).TopPosZ(20, 60))
	ITEM(Button, cancel,   LeftPosZ(525, 135).TopPosZ(20, 60))
END_LAYOUT


Like you can see in the code it is basically a pretty simple thing, because everything is scaled up/positioned multiplied by the same factor: the scaling factor of the resized window.
If you can give me a hint where to find the method(s) called when resizing the window, maybe I can fit the library to my needs and/or contribute a solution.

Please correct me if there is already something to achieve that but I didn't find anything.

See this thread also.


Greetings
Daniel
Re: [Feature request] Relative positioning [message #48654 is a reply to message #48644] Mon, 14 August 2017 08:59 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Dear Daniel

Now I understand. However I do not realize now how to implement it in a simple manner.
The only way I remember would be using Splitter (watch this), blocking in any way the user to resize them by himself.


Best regards
Iñaki
Re: [Feature request] Relative positioning [message #48655 is a reply to message #48654] Mon, 14 August 2017 09:29 Go to previous messageGo to next message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
Quote:
The only way I remember would be using Splitter (watch this), blocking in any way the user to resize them by himself.

Just checked it out but it doesn't work. It works the same way the standard resizing works.

So I would like to know what methods are called when resizing to try make my own solution Wink


Greetings
Daniel
Re: [Feature request] Relative positioning [message #48673 is a reply to message #48655] Wed, 16 August 2017 10:24 Go to previous messageGo to next message
cbpporter is currently offline  cbpporter
Messages: 1401
Registered: September 2007
Ultimate Contributor
Hi rafiwui,

Layouts and automatic positioning is good enough for a lot of common task but sometimes you do need to go in and write your own positioning code.

You need to override this method in your window:

virtual void   Layout();


In this method you should query the size of the parent view-port, determine the center and align your 4 controls as in the pictures.
Re: [Feature request] Relative positioning [message #48771 is a reply to message #48673] Wed, 13 September 2017 15:49 Go to previous messageGo to next message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
I finished my work on my AutoResizer. So if anyone wants to use it simply include and inherit from AutoResizeTopWindow instead of TopWindow.
So here is the solution I came up with:
#ifndef _AutoResizeTopWindow_h_
#define _AutoResizeTopWindow_h_

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

class AutoResizeTopWindow : public TopWindow
{
public:
	virtual void Layout()
	{
		Size currentSize = GetSize();
		if(firstSizing)
			startSize = currentSize;
		
		float sizeXChange = (float)currentSize.cx / (float)startSize.cx;
		float sizeYChange = (float)currentSize.cy / (float)startSize.cy;
		
		Ctrl* pChild = GetFirstChild();
		for(int i = 0; pChild != NULL; i++)
		{
			if(firstSizing)
				startRects.Add(pChild->GetRect());
			
			float rectLeft	= startRects[i].left * sizeXChange;
			float rectTop	= startRects[i].top * sizeYChange;
			float rectSizeX	= startRects[i].Width() * sizeXChange;
			float rectSizeY	= startRects[i].Height() * sizeYChange;
			
			pChild->SetRect(rectLeft, rectTop,
							rectSizeX, rectSizeY);
			
			pChild = pChild->GetNext();
		}
		firstSizing = false;
	}

private:
	bool firstSizing = true;
	Size startSize;
	Vector<Rect> startRects;
};

#endif



Greetings
Daniel

[Updated on: Thu, 14 September 2017 08:45]

Report message to a moderator

Re: [Feature request] Relative positioning [message #48772 is a reply to message #48771] Wed, 13 September 2017 18:26 Go to previous messageGo to next message
koldo is currently offline  koldo
Messages: 3355
Registered: August 2008
Senior Veteran
Thank you Daniel for showing us your work.

Best regards
Iñaki
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

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


Current Time: Thu Mar 28 23:36:15 CET 2024

Total time taken to generate the page: 0.01792 seconds