Difference between revisions of "Container"

From uGFX Wiki
Jump to: navigation, search
m (Transparency)
(API reference)
Line 13: Line 13:
  
 
== API reference ==
 
== API reference ==
The API reference for the frame container can be found [http://api.ugfx.org/master/group___frame.html here].
+
The API reference for the frame container can be found [http://api.ugfx.org/master/group___container.html here].
  
 
== Custom Draw Routines ==
 
== Custom Draw Routines ==

Revision as of 00:15, 14 February 2015

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);


API reference

The API reference for the frame container can be found here.

Custom Draw Routines

The container widget predefines a number of custom draw routines. They can be set using gwinSetCustomDraw() or by specifying the custom draw routine in the GWidgetInit structure during creation. The predefined custom draw routines are:

Custom Draw Routine Description
gwinContainerDraw_Std The client area is filled with the background color.
gwinContainerDraw_Transparent The client area is not filled in at all.
gwinContainerDraw_Image The parameter is an open gdispImage that is tiled to fill the client area of the frame.

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 pop-up or top-level window element, you might want to take a look at the frame widget instead.

Transparency

The container widget can optionally be rendered transparent by using the gwinContainerDraw_Transparent custom draw routine.

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