In previous chapter we talked about how GUIPanel is a special type of a GUI element called a "layout". Layouts serve as containers for GUI elements (including other layouts), and they may also control how are elements within them positioned and sized.
There are three types of layouts:
You will find that vertical and horizontal layouts come in handy when you need to design GUI that needs to scale across various screen sizes/resolutions. By adding your GUI elements to such layouts instead of manually positioning them, ensures the GUI system can always keep them at optimal position and size, regardless of the available screen area.
In the previous chapter we have already seen how to add a GUI element to a layout (a panel, more specifically). Here is the entire interface for dealing with element addition/removal, shared by all layout types:
Here's an example of retrieving the primary GUI panel and adding some elements to it:
// Assuming "gui" is a GUI widget component
GUIPanel* mainPanel = gui->getPanel();
// Add a horizontal layout that will automatically position child elements
GUILayoutX layout = mainPanel->addNewElement<GUILayoutX>();
// Add a text label, and a button to the right of it
layout->addNewElement<GUILabel>(HString(L"This is a button: "));
layout->addNewElement<GUIButton>(HString(L"Click me"));
GUI elements can also be created separately and then added to layouts later using these methods:
Same example as above, only written differently:
// Assuming "gui" is a GUI widget component
GUIPanel* mainPanel = gui->getPanel();
// Add a horizontal layout that will automatically position child elements
GUILayoutX layout = GUILayoutX::create();
mainPanel->addElement(layout);
// Add a text label, and a button to the right of it
GUILabel* label = GUILabel::create(HString(L"This is a button: "));
GUIButton* button = GUIButton::create(HString(L"Click me"));
layout->addNewElement(label);
layout->addNewElement(button);
The matter which style you use is personal preference.
// TODO
@ref TODO_IMAGE
// TODO
@ref TODO_IMAGE
// TODO - GUIOptions, mention styles
// TODO
// TODO
@ref TODO_IMAGE
// TODO - Depth