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 » Community » Newbie corner » How to achieve dynamic layout scaling ?
Re: How to achieve dynamic layout scaling ? [message #55952 is a reply to message #55950] Wed, 06 January 2021 17:26 Go to previous message
mingodad is currently offline  mingodad
Messages: 53
Registered: February 2008
Location: Spain
Member
With this I'm getting resembling what I mean by "Dynamic Layout Scaling", still missing font scaling and is a bit hack.

Does Ultimate++ provide something like this or have anyone done something like this ?

- CalculatorDynLayout.h
#ifndef _CalculatorDynLayout_CalculatorDynLayout_h
#define _CalculatorDynLayout_CalculatorDynLayout_h

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

#define LAYOUTFILE <CalculatorDynLayout/CalculatorDynLayout.lay>
#include <CtrlCore/lay.h>

class CalculatorDynLayout : public WithCalculatorDynLayoutLayout<TopWindow> {
	Rect initSize;
	Vector<Rect> childInitSizes;
public:
	CalculatorDynLayout();
	virtual void Layout();
};

#endif


- main.cpp
#include "CalculatorDynLayout.h"

CalculatorDynLayout::CalculatorDynLayout()
{
	CtrlLayout(*this, "Calculator");
}

void CalculatorDynLayout::Layout()
{
	if(childInitSizes.GetCount() == 0)
	{
		initSize = this->GetRect();
		for(int i=0, imax=this->GetChildCount(); i < imax; ++i)
		{
			childInitSizes.Add(this->GetIndexChild(i)->GetRect());
		}
	}
	else
	{
		Rect currSize = this->GetRect();
		double cxRatio = (currSize.right-currSize.left) / ((double)(initSize.right-initSize.left));
		double cyRatio = (currSize.bottom-currSize.top) / ((double)(initSize.bottom-initSize.top));
		entry.SetLabel(String() << initSize << "::" << currSize
			<< "::" << cxRatio << "::" << cyRatio
			<< "::" << childInitSizes.GetCount() << "::" << this->GetChildCount());
	
		for(int i=0, imax=this->GetChildCount(); i < imax; ++i)
		{
			Rect newSize, childSize;
			childSize = childInitSizes[i];
			Ctrl *childCtrl = this->GetIndexChild(i);
			newSize.left = childSize.left * cxRatio;
			newSize.top = childSize.top * cyRatio;
			newSize.right = childSize.right * cxRatio;
			newSize.bottom = childSize.bottom * cyRatio;
			childCtrl->SetRect(newSize);
		}
	}
}

GUI_APP_MAIN
{
	CalculatorDynLayout().Sizeable().Run();
}


- CalculatorDynLayout.lay
LAYOUT(CalculatorDynLayoutLayout, 160, 140)
	ITEM(Upp::Label, entry, SetFrame(BlackFrame()).LeftPosZ(12, 140).TopPosZ(8, 19))
	ITEM(Upp::Button, clear, SetLabel(t_("C")).LeftPosZ(68, 20).TopPosZ(36, 15))
	ITEM(Upp::Button, clearAll, SetLabel(t_("AC")).LeftPosZ(96, 20).TopPosZ(36, 15))
	ITEM(Upp::Button, bksp, SetLabel(t_("<-")).LeftPosZ(124, 28).TopPosZ(36, 15))
	ITEM(Upp::Button, b7, SetLabel(t_("7")).LeftPosZ(12, 20).TopPosZ(56, 15))
	ITEM(Upp::Button, b8, SetLabel(t_("8")).LeftPosZ(40, 20).TopPosZ(56, 15))
	ITEM(Upp::Button, b9, SetLabel(t_("9")).LeftPosZ(68, 20).TopPosZ(56, 15))
	ITEM(Upp::Button, bdiv, SetLabel(t_("/")).LeftPosZ(96, 20).TopPosZ(56, 15))
	ITEM(Upp::Button, bsqrt, SetLabel(t_("sqrt")).LeftPosZ(124, 28).TopPosZ(56, 15))
	ITEM(Upp::Button, b4, SetLabel(t_("4")).LeftPosZ(12, 20).TopPosZ(76, 15))
	ITEM(Upp::Button, b5, SetLabel(t_("5")).LeftPosZ(40, 20).TopPosZ(76, 15))
	ITEM(Upp::Button, b6, SetLabel(t_("6")).LeftPosZ(68, 20).TopPosZ(76, 15))
	ITEM(Upp::Button, bmul, SetLabel(t_("*")).LeftPosZ(96, 20).TopPosZ(76, 15))
	ITEM(Upp::Button, bpct, SetLabel(t_("%")).LeftPosZ(124, 28).TopPosZ(76, 15))
	ITEM(Upp::Button, b1, SetLabel(t_("1")).LeftPosZ(12, 20).TopPosZ(96, 15))
	ITEM(Upp::Button, b2, SetLabel(t_("2")).LeftPosZ(40, 20).TopPosZ(96, 15))
	ITEM(Upp::Button, b3, SetLabel(t_("3")).LeftPosZ(68, 20).TopPosZ(96, 15))
	ITEM(Upp::Button, bminus, SetLabel(t_("-")).LeftPosZ(96, 20).TopPosZ(96, 15))
	ITEM(Upp::Button, b0, SetLabel(t_("0")).LeftPosZ(12, 20).TopPosZ(116, 15))
	ITEM(Upp::Button, bsep, SetLabel(t_(".")).LeftPosZ(40, 20).TopPosZ(116, 15))
	ITEM(Upp::Button, blessplus, SetLabel(t_("-/+")).LeftPosZ(68, 20).TopPosZ(116, 15))
	ITEM(Upp::Button, bplus, SetLabel(t_("+")).LeftPosZ(96, 20).TopPosZ(116, 15))
	ITEM(Upp::Button, beq, SetLabel(t_("=")).LeftPosZ(124, 28).TopPosZ(96, 36))
END_LAYOUT
 
Read Message
Read Message
Read Message
Previous Topic: SqlSchema sch(MY_SQL) compound and or unique indexes
Next Topic: Keyboard navigation doesn't work
Goto Forum:
  


Current Time: Tue May 14 10:32:50 CEST 2024

Total time taken to generate the page: 0.02248 seconds