Difference between revisions of "Container"
Line 1: | Line 1: | ||
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. | 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 9: | Line 10: | ||
ghChild = gwinCreateXxx(0, &wi); | ghChild = gwinCreateXxx(0, &wi); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
+ | |||
== 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___frame.html here]. | ||
+ | |||
+ | == Custom Draw Routines == | ||
+ | The container widget predefines a number of custom draw routines. They can be set using <code>gwinSetCustomDraw()</code> or by specifying the custom draw routine in the GWidgetInit structure during creation. The predefined custom draw routines are: | ||
+ | {| class="wikitable" | ||
+ | ! scope="col"|Custom Draw Routine | ||
+ | ! scope="col"|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 == | == 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 <code>gwinContainerCreate()</code> 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 | + | '''''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 == | == Transparency == | ||
− | The container widget can optionally be rendered transparent by passing ''' | + | The container widget can optionally be rendered transparent by passing using the '''gwinContainerDraw_Transparent''' custom draw routine. |
== Example == | == Example == |
Revision as of 14:23, 16 August 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);
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 passing 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; }