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++ Widgets - General questions or Mixed problems » [Closed] Get size and position of widget
[Closed] Get size and position of widget [message #48767] Wed, 13 September 2017 09:05 Go to next message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
I try to write an auto resizing app and so I need to know how to get the position and size of all widgets correct, because the solution I worked out has kind of a bug/problem:
index.php?t=getfile&id=5391&private=0
This is how it looks

index.php?t=getfile&id=5392&private=0
This is how it should look
And here is the Layout file:
LAYOUT(TestSimpleLayout, 400, 200)
	ITEM(Clock, m_widget, LeftPosZ(16, 368).TopPosZ(20, 156))
END_LAYOUT


The code of the resizing is shown here:
void TestWindow::Layout()
{
	float sizeXChange = (float)GetSize().cx / (float)m_startSize.cx;
	float sizeYChange = (float)GetSize().cy / (float)m_startSize.cy;
	
	Ctrl* child = GetFirstChild();
	while(child != NULL)
	{
		String temp;
		temp << child->GetSize().cx << " | " << child->GetSize().cy;
		temp << " @ " << child->GetRect().TopLeft().x << " | " << child->GetRect().TopLeft().y;
		Title(temp);
		
		child->LeftPosZ(child->GetRect().TopLeft().x * sizeXChange, child->GetSize().cx * sizeXChange);
		child->TopPosZ(child->GetRect().TopLeft().y * sizeYChange, child->GetSize().cy * sizeYChange);
		
		child = child->GetNext();
	}
}

So like you can see there is sth wrong with the size/position gathering because it is sth completely different to the values I set in the layout file.

I will add the complete testprogram as well if you want to check it out.


Greetings
Daniel

[Updated on: Wed, 13 September 2017 15:50]

Report message to a moderator

Re: Get size and position of widget [message #48768 is a reply to message #48767] Wed, 13 September 2017 13:37 Go to previous messageGo to next message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
Going through some testing I made it so a least at the beginning the widget is shown correct but when it should resize it gets resized in an not intended way (but not that far from what I want.
The main problem seems to be the positioning, because the position never changes when making the window bigger but changes when making the window smaller. The sizing of the widget is does need a fast change of the window size to rescale and I have the feeling that it is too less when upscaling and too much when downscaling but I have no idea why.
See the attached package to check it out
  • Attachment: Bugtester.7z
    (Size: 1.13KB, Downloaded 44 times)


Greetings
Daniel

[Updated on: Wed, 13 September 2017 13:43]

Report message to a moderator

Re: Get size and position of widget [message #48770 is a reply to message #48768] Wed, 13 September 2017 15:45 Go to previous message
rafiwui is currently offline  rafiwui
Messages: 105
Registered: June 2017
Location: Stuttgart, Germany
Experienced Member
Ok I solved the problem and if anyone else want to use the AutResizeTopWindow feel free to copy the code below or download the header.
#ifndef _AutoResizeTopWindow_h_
#define _AutoResizeTopWindow_h_

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

class AutoResizeTopWindow : public virtual 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
Previous Topic: Add layouts/ParentCtrl to column list
Next Topic: How to blur a Ctrl
Goto Forum:
  


Current Time: Fri Sep 20 01:34:33 CEST 2019

Total time taken to generate the page: 0.01309 seconds