Container: Difference between revisions
Appearance
Created page with "Category:Containers" |
No edit summary |
||
| Line 1: | Line 1: | ||
The container widget can be used to group together other widgets. It's a simple blank rectangle and it can be used as a parent for other widgets. | |||
A widget can be added as a child to a container by adding the containers GHandle to the childs widget init structure: | |||
<syntaxhighlight lang=c> | |||
GHandle ghContainer; | |||
GHandle ghChild; | |||
... | |||
wi.g.parent = ghContainer; | |||
... | |||
ghChild = gwinCreateXxx(0, &wi); | |||
</syntaxhighlight> | |||
Note: The childrens position (wi.g.x and wi.g.y) are always relative to its parent. | |||
== Border == | |||
The container widget can optionally be rendered with a border. To enable the border, GWIN_CONTAINER_BORDER has to be passed as a flag to the gwinContainerCreate() routine. | |||
Note: If you want to use the container as a window-like element, you might want to take a look at the frame widget instead. | |||
== Example == | |||
The following example shows how to create a container and a button to it. | |||
<syntaxhighlight lang=c> | |||
#include "gfx.h" | |||
static GHandle ghContainer; | |||
static GHandle ghButton; | |||
static void createWidgets(void) { | |||
GWidgetInit wi; | |||
// Apply some default values for GWIN | |||
gwinWidgetClearInit(&wi); | |||
// Apply the container parameters | |||
wi.g.show = FALSE; | |||
wi.g.width = 200; | |||
wi.g.height = 150; | |||
wi.g.y = 10; | |||
wi.g.x = 10; | |||
wi.text = "Container"; | |||
ghContainer = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER); | |||
wi.g.show = TRUE; | |||
// Apply the button parameters | |||
wi.g.width = 120; | |||
wi.g.height = 30; | |||
wi.g.y = 10; | |||
wi.g.x = 10; | |||
wi.text = "Button"; | |||
wi.g.parent = ghContainer; | |||
ghButton = gwinButtonCreate(0, &wi); | |||
// Make the container become visible - therefore all its children | |||
// become visible as well | |||
gwinShow(ghContainer); | |||
} | |||
int main(void) { | |||
// Initialize the display | |||
gfxInit(); | |||
// Attach the mouse input | |||
gwinAttachMouse(0); | |||
// Set the widget defaults | |||
gwinSetDefaultFont(gdispOpenFont("*")); | |||
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE); | |||
gdispClear(White); | |||
// Create the widget | |||
createWidgets(); | |||
while(1) { | |||
gfxSleepMilliseconds(1000); | |||
} | |||
return 0; | |||
} | |||
</syntaxhighlight> | |||
[[Category:Containers]] | [[Category:Containers]] | ||
Revision as of 17:34, 1 July 2014
The container widget can be used to group together other widgets. It's a simple blank rectangle and it can be used as a parent for other widgets. A widget can be added as a child to a container by adding the containers GHandle to the childs widget init structure:
GHandle ghContainer;
GHandle ghChild;
...
wi.g.parent = ghContainer;
...
ghChild = gwinCreateXxx(0, &wi);Note: The childrens position (wi.g.x and wi.g.y) are always relative to its parent.
Border
The container widget can optionally be rendered with a border. To enable the border, GWIN_CONTAINER_BORDER has to be passed as a flag to the gwinContainerCreate() routine. Note: If you want to use the container as a window-like element, you might want to take a look at the frame widget instead.
Example
The following example shows how to create a container and a button to it.
#include "gfx.h"
static GHandle ghContainer;
static GHandle ghButton;
static void createWidgets(void) {
GWidgetInit wi;
// Apply some default values for GWIN
gwinWidgetClearInit(&wi);
// Apply the container parameters
wi.g.show = FALSE;
wi.g.width = 200;
wi.g.height = 150;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Container";
ghContainer = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
wi.g.show = TRUE;
// Apply the button parameters
wi.g.width = 120;
wi.g.height = 30;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Button";
wi.g.parent = ghContainer;
ghButton = gwinButtonCreate(0, &wi);
// Make the container become visible - therefore all its children
// become visible as well
gwinShow(ghContainer);
}
int main(void) {
// Initialize the display
gfxInit();
// Attach the mouse input
gwinAttachMouse(0);
// Set the widget defaults
gwinSetDefaultFont(gdispOpenFont("*"));
gwinSetDefaultStyle(&WhiteWidgetStyle, FALSE);
gdispClear(White);
// Create the widget
createWidgets();
while(1) {
gfxSleepMilliseconds(1000);
}
return 0;
}