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 » Zooming layout in Windows
Zooming layout in Windows [message #35999] Tue, 17 April 2012 19:49 Go to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

I've looked at all the examples and posts I could possibly study. However, I cannot find out how to fix this. Either the widgets overlap when the layout is zoomed (Hsize,Vsize springs), or they zoom mainly in one direction (Auto springs button).

I would like to (if possible) control the zooming of each widget depending on the size of the Topwindow that holds the widget. So, my strategy is to get the ratio of the size of the zoomed topwindow to its design size and apply the zoom to each child widget to adjust its X and Y pos and also its X and Y size.

What am I doing wrong? Is there some example that shows how to do this?

Pic1 and Pic2 are showing the design size layout and zoomed layout
Pic3 and pic4 are showing the same layout when I apply autosprings

index.php?t=getfile&id=3736&private=0
Re: Zooming layout in Windows [message #36040 is a reply to message #35999] Sat, 21 April 2012 03:11 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Bumped for attention. Hope someone has some hints for me.

Sad
Re: Zooming layout in Windows [message #36048 is a reply to message #36040] Sat, 21 April 2012 15:56 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
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 #36049 is a reply to message #36048] Sat, 21 April 2012 16:15 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Lance

I appreciate you taking time to help me with your reply. Would you have some pointers/any examples on how this is done? I have done quite a bit with Upp since my initial days, but, this is something with which I need some hand holding.

Regards
Jerson
Re: Zooming layout in Windows [message #36051 is a reply to message #36049] Sat, 21 April 2012 19:56 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
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 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
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 Go to previous messageGo to next message
jerson is currently offline  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 #36054 is a reply to message #36053] Sun, 22 April 2012 03:17 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
I see what you mean now. Smile
Re: Zooming layout in Windows [message #36055 is a reply to message #36054] Sun, 22 April 2012 05:12 Go to previous messageGo to next message
Lance is currently offline  Lance
Messages: 526
Registered: March 2007
Contributor
Turns out to be a lot more complicated than I had expected. There should be more elegant way of implementing it for those who know Upp better. But here you go:

See attached for an example. I am not certain if every safety guards I put there is necessary.
  • Attachment: Resize2.zip
    (Size: 1.83KB, Downloaded 202 times)
Re: Zooming layout in Windows [message #36056 is a reply to message #35999] Sun, 22 April 2012 05:49 Go to previous messageGo to next message
jerson is currently offline  jerson
Messages: 202
Registered: June 2010
Location: Bombay, India
Experienced Member

Hi Lance

That is exactly what I want to do. Brilliant example. I am glad I asked; I learnt something new. Thank you so much.

Regards
Jerson
Re: Zooming layout in Windows [message #36058 is a reply to message #36056] Sun, 22 April 2012 14:29 Go to previous message
Lance is currently offline  Lance
Messages: 526
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
Previous Topic: UDP connection
Next Topic: How to get pixels per millimeter for current screen?
Goto Forum:
  


Current Time: Fri Mar 29 16:32:38 CET 2024

Total time taken to generate the page: 0.01618 seconds