Difference between revisions of "Container"

From uGFX Wiki
Jump to: navigation, search
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.
+
The basic container widget can be used to group other widgets together. 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:
 
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>
 
<syntaxhighlight lang=c>
Line 11: Line 11:
  
 
== Border ==
 
== 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.
+
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 <code>gwinContainerCreate()</code> 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.
+
'''''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 ==
 
== Example ==

Revision as of 17:44, 1 July 2014

The basic container widget can be used to group other widgets together. 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);

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 adding 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;
}