Home » Community » Newbie corner » Zooming layout in Windows
|
|
Re: Zooming layout in Windows [message #36048 is a reply to message #36040] |
Sat, 21 April 2012 15:56   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
I am not sure if I get you right, but you may need to write customized Layout() virtual method for your container class. Layout() will be called when window is to be displayed or resized, pretty much the WM_SIZE thing in WIN32. There you have full control over how you want to allocate available space to contained Ctrls.
HTH
[Updated on: Sat, 21 April 2012 16:00] Report message to a moderator
|
|
|
|
Re: Zooming layout in Windows [message #36051 is a reply to message #36049] |
Sat, 21 April 2012 19:56   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hi Jerson:
Not sure if you're looking for something like this, but:
#include <CtrlLib/CtrlLib.h>
using namespace Upp;
struct MyApp : public TopWindow
{
MyApp()
{
lt.SetLabel("5x5");
rt.SetLabel("5x2");
lb.SetLabel("2x5");
rb.SetLabel("2x2");
Add(lt);
Add(rt);
Add(lb);
Add(rb);
}
virtual void Layout()
{
Size sz=GetSize();
int w1,h1;
w1=sz.cx*5/7;
h1=sz.cy*5/7;
lt.LeftPos(0,w1).TopPos(0,h1);
rt.LeftPos(w1,sz.cx-w1).TopPos(0,h1);
lb.LeftPos(0,w1).TopPos(h1,sz.cy-h1);
rb.LeftPos(w1, sz.cx-w1).TopPos(h1,sz.cy-h1);
}
Button lt, rt, lb, rb;
};
GUI_APP_MAIN
{
MyApp().Sizeable().Run();
}
|
|
|
Re: Zooming layout in Windows [message #36052 is a reply to message #36051] |
Sat, 21 April 2012 20:15   |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Following code does the same thing. Feel a bit slow in Ubuntu. There should be better way of achieving it.
virtual void Layout()
{
Size sz=GetSize();
int w1,h1,w2,h2;
w1=sz.cx*5/7;
h1=sz.cy*5/7;
w2=sz.cx-w1;
h2=sz.cy-h1;
lt.SetRect(0,0,w1,h1);
rt.SetRect(w1,0,w2,h1);
lb.SetRect(0,h1,w1,h2);
rb.SetRect(w1,h1,w2,h2);
}
|
|
|
Re: Zooming layout in Windows [message #36053 is a reply to message #36052] |
Sun, 22 April 2012 02:52   |
jerson
Messages: 202 Registered: June 2010 Location: Bombay, India
|
Experienced Member |

|
|
Dear Lance
Thank you very much. I reeally appreciate your help. I am considering something on the lines of this (I'm using pseudo code here).
Size Designsz = OriginalLayoutSizePos (const)
Size wsz = GetSizePos(MainWindow); // current sizepos
int ratiox = wsz.x / Designsz.x; // amount of X change
int ratioy = wsz.y / Designsz.y; // amount of Y change
// for each widget on the layout, (helps to add/remove widgets later on as the project grows)
for (Widget=0; Widget < LastWidget; Widget++)
{
// scale each widget. Maybe I need to adjust the LeftPos and TopPos too for each widget
Widgets[Widget].Size.x *= ratiox
Widgets[Widget].Size.y *= ratioy
}
// update all widgets on the layout
Refresh();
[Updated on: Sun, 22 April 2012 03:02] Report message to a moderator
|
|
|
|
|
|
Re: Zooming layout in Windows [message #36058 is a reply to message #36056] |
Sun, 22 April 2012 14:29  |
Lance
Messages: 656 Registered: March 2007
|
Contributor |
|
|
Hi Jerson:
You are very welcome. I also learned a lot from trying to solve this problem. I didn't know Layout will be called for every child Ctrl's position/size changes.
I approached the problem from a library user's perspective. I feel it's kind of clumsy but at least it works as intended.
Lance
|
|
|
Goto Forum:
Current Time: Sun Apr 27 00:21:20 CEST 2025
Total time taken to generate the page: 0.00920 seconds
|