Difference between revisions of "GridLayout"
m (Robot: Adding Category:Uncategorised) |
|||
Line 1: | Line 1: | ||
+ | {{VersionBadge|0.6}} | ||
+ | |||
== Introduction == | == Introduction == | ||
It is hard to hard-code a layout that is constantly looking good with different screen resolutions and for different window sizes - especially when dealing with resizable windows. | It is hard to hard-code a layout that is constantly looking good with different screen resolutions and for different window sizes - especially when dealing with resizable windows. | ||
Line 67: | Line 69: | ||
* [http://noware.info/progs/cegui/gridlayout/GridLayout.cpp GridLayout.cpp] | * [http://noware.info/progs/cegui/gridlayout/GridLayout.cpp GridLayout.cpp] | ||
− | [[Category: | + | [[Category:HowTo]] |
Revision as of 12:00, 27 February 2011
Written for CEGUI 0.6
Works with versions 0.6.x (obsolete)
Introduction
It is hard to hard-code a layout that is constantly looking good with different screen resolutions and for different window sizes - especially when dealing with resizable windows. Often, two wdgets are too close together or too far apart. The GridLayout class solves such problems: This class provides a layout manager for CEGUI that lays out a given window according to an invisible grid laid over the window's client area. The size of the grid's cells is changed according to some parameters when the window size changes. The widgets, the client application registers with the layout manager, stick to specific cells and change their size when the cells do. This concept (inspired by Trolltechs Qt) allows for many different and complex window layouts. The header file is documented with doxygen tags.
Questions, remarks, comments, blame, etc. shall be posted within the GridLayout forum thread.
Example
The following snippet is an example from the embedded documentation:
<cpp/>
// create a new window and its layout manager
CEGUI::Window *wnd = (CEGUI::FrameWindow *)CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/FrameWindow", (CEGUI::utf8*)"MyWindow");
GridLayout *layout = new GridLayout(wnd, true); // setting the second parameter to true will
// cause self-destruction of the layout manager on destruction of the window
CEGUI::Window *btn; btn = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", (CEGUI::utf8*)"Btn1"); btn->setText("1"); layout->addChildWindow(btn, 0, 0, 3, 3, UDim(1.0/512, 0.0));
btn = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", (CEGUI::utf8*)"Btn1"); btn->setText("2"); btn->setMinSize(CEGUI::UVector2(UDim(0.06, 0.0), UDim(0.03, 0.0))); layout->addChildWindow(btn, 2, 0, 1, 1, UDim(1.0/512, 0.0));
btn = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", (CEGUI::utf8*)"Btn1"); btn->setText("3"); btn->setMinSize(CEGUI::UVector2(UDim(0.06, 0.0), UDim(0.03, 0.0))); layout->addChildWindow(btn, 2, 1, 1, 1, UDim(1.0/512, 0.0));
btn = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", (CEGUI::utf8*)"Btn1"); btn->setText("4"); btn->setMinSize(CEGUI::UVector2(UDim(0.06, 0.0), UDim(0.03, 0.0))); layout->addChildWindow(btn, 1, 3, 1, 1, UDim(1.0/512, 0.0));
btn = CEGUI::WindowManager::getSingleton().createWindow("TaharezLook/Button", (CEGUI::utf8*)"Btn1"); btn->setText("5"); btn->setMinSize(CEGUI::UVector2(UDim(0.06, 0.0), UDim(0.03, 0.0))); layout->addChildWindow(btn, 2, 3, 1, 1, UDim(1.0/512, 0.0));
layout->setRowStretch(0, 0); layout->setRowStretch(1, 0); layout->setRowStretch(3, 0); layout->setColStretch(1, 0); layout->setColStretch(2, 0);
layout->setOuterMargin(UDim(1.0/256, 0.0)); // adds a margin to the window's whole client area wnd->setMinSize(layout->getMinSize()); // asks the layout manager for the window's minimum size wnd->setSize(wnd->getMinSize()); layout->layout(); // forces an initial layout
The resulting window will look like this:
1 | 2 | |
3 | ||
4 | 5 |
Only the button captioned "1" will resize when resizing the window and when viewing the window with a different resolution, everything will look the same as before
Download
The files are too big to be inlined into this page. You may download them here