Added containers_nested demo

ugfx_release_2.6
Joel Bodenmann 2014-05-21 14:56:02 +02:00
parent 34e23320b4
commit 1edc0a2d5a
4 changed files with 250 additions and 0 deletions

View File

@ -0,0 +1,3 @@
DEMODIR = $(GFXLIB)/demos/modules/gwin/container_nested
GFXINC += $(DEMODIR)
GFXSRC += $(DEMODIR)/main.c

View File

@ -0,0 +1,88 @@
/**
* This file has a different license to the rest of the uGFX system.
* You can copy, modify and distribute this file as you see fit.
* You do not need to publish your source modifications to this file.
* The only thing you are not permitted to do is to relicense it
* under a different license.
*/
/**
* Copy this file into your project directory and rename it as gfxconf.h
* Edit your copy to turn on the uGFX features you want to use.
* The values below are the defaults. You should delete anything
* you are leaving as default.
*
* Please use spaces instead of tabs in this file.
*/
#ifndef _GFXCONF_H
#define _GFXCONF_H
/* The operating system to use. One of these must be defined - preferably in your Makefile */
//#define GFX_USE_OS_CHIBIOS TRUE
//#define GFX_USE_OS_WIN32 TRUE
//#define GFX_USE_OS_LINUX TRUE
//#define GFX_USE_OS_OSX TRUE
///////////////////////////////////////////////////////////////////////////
// GDISP //
///////////////////////////////////////////////////////////////////////////
#define GFX_USE_GDISP TRUE
#define GDISP_NEED_VALIDATION TRUE
#define GDISP_NEED_CLIP TRUE
#define GDISP_NEED_TEXT TRUE
#define GDISP_INCLUDE_FONT_UI2 TRUE
#define GDISP_NEED_MULTITHREAD TRUE
///////////////////////////////////////////////////////////////////////////
// GWIN //
///////////////////////////////////////////////////////////////////////////
#define GFX_USE_GWIN TRUE
#define GWIN_NEED_WINDOWMANAGER TRUE
#define GWIN_NEED_CONSOLE TRUE
#define GWIN_CONSOLE_USE_HISTORY TRUE
#define GWIN_CONSOLE_HISTORY_AVERAGING TRUE
#define GWIN_CONSOLE_HISTORY_ATCREATE TRUE
#define GWIN_CONSOLE_ESCSEQ TRUE
#define GWIN_CONSOLE_USE_BASESTREAM TRUE
#define GWIN_NEED_GRAPH TRUE
#define GWIN_NEED_WIDGET TRUE
#define GWIN_NEED_BUTTON TRUE
#define GWIN_BUTTON_LAZY_RELEASE TRUE
#define GWIN_NEED_CHECKBOX TRUE
#define GWIN_NEED_CONTAINERS TRUE
#define GWIN_NEED_CONTAINER TRUE
///////////////////////////////////////////////////////////////////////////
// GEVENT //
///////////////////////////////////////////////////////////////////////////
#define GFX_USE_GEVENT TRUE
///////////////////////////////////////////////////////////////////////////
// GTIMER //
///////////////////////////////////////////////////////////////////////////
#define GFX_USE_GTIMER TRUE
///////////////////////////////////////////////////////////////////////////
// GQUEUE //
///////////////////////////////////////////////////////////////////////////
#define GFX_USE_GQUEUE TRUE
#define GQUEUE_NEED_ASYNC TRUE
#define GQUEUE_NEED_GSYNC TRUE
///////////////////////////////////////////////////////////////////////////
// GINPUT //
///////////////////////////////////////////////////////////////////////////
#define GFX_USE_GINPUT TRUE
#define GINPUT_NEED_MOUSE TRUE
#endif /* _GFXCONF_H */

View File

@ -0,0 +1,158 @@
#include "gfx.h"
static GListener gl;
static GHandle ghContainer1, ghContainer2, ghContainer3;
static GHandle ghButton1, ghButton2, ghButton3, ghButton4;
static GHandle ghCheckbox1, ghCheckbox2, ghCheckbox3;
static void createWidgets(void) {
GWidgetInit wi;
// Apply some default values for GWIN
gwinWidgetClearInit(&wi);
wi.g.show = FALSE;
// Container 1
wi.g.width = 300;
wi.g.height = 220;
wi.g.y = 40;
wi.g.x = 10;
wi.text = "Container 1";
ghContainer1 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
wi.g.show = TRUE;
// Container 2
wi.g.width = 100;
wi.g.height = 150;
wi.g.y = 55;
wi.g.x = 10;
wi.g.parent = ghContainer1;
wi.text = "Container 2";
ghContainer2 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
// Container 3
wi.g.width = 100;
wi.g.height = 150;
wi.g.y = 55;
wi.g.x = 185;
wi.g.parent = ghContainer1;
wi.text = "Container 3";
ghContainer3 = gwinContainerCreate(0, &wi, GWIN_CONTAINER_BORDER);
// Button 1
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Button 1";
wi.g.parent = ghContainer2;
ghButton1 = gwinButtonCreate(0, &wi);
// Button 2
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 40;
wi.g.x = 10;
wi.text = "Button 2";
wi.g.parent = ghContainer2;
ghButton2 = gwinButtonCreate(0, &wi);
// Button 3
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 10;
wi.g.x = 10;
wi.text = "Button 3";
wi.g.parent = ghContainer3;
ghButton3 = gwinButtonCreate(0, &wi);
// Button 4
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 40;
wi.g.x = 10;
wi.text = "Button 4";
wi.g.parent = ghContainer3;
ghButton4 = gwinButtonCreate(0, &wi);
// Checkbox 1
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 25;
wi.g.x = 10;
wi.text = " Visible C2";
wi.g.parent = ghContainer1;
ghCheckbox1 = gwinCheckboxCreate(0, &wi);
// Checkbox 2
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 25;
wi.g.x = 185;
wi.text = " Visible C3";
wi.g.parent = ghContainer1;
ghCheckbox2 = gwinCheckboxCreate(0, &wi);
// Checkbox 3
wi.g.width = 80;
wi.g.height = 20;
wi.g.y = 10;
wi.g.x = 10;
wi.text = " Visible C1";
wi.g.parent = 0;
ghCheckbox3 = gwinCheckboxCreate(0, &wi);
// Make the container become visible - therefore all its children
// become visible as well
gwinShow(ghContainer1);
}
int main(void) {
GEvent* pe;
// 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();
// We want to listen for widget events
geventListenerInit(&gl);
gwinAttachListener(&gl);
// Set the initial state of the checkboxes
gwinCheckboxCheck(ghCheckbox1, TRUE);
gwinCheckboxCheck(ghCheckbox2, TRUE);
gwinCheckboxCheck(ghCheckbox3, TRUE);
while(1) {
// Get an Event
pe = geventEventWait(&gl, TIME_INFINITE);
switch(pe->type) {
case GEVENT_GWIN_CHECKBOX:
if (((GEventGWinCheckbox*)pe)->checkbox == ghCheckbox1) {
gwinSetVisible(ghContainer2, gwinCheckboxIsChecked(ghCheckbox1));
}
else if (((GEventGWinCheckbox*)pe)->checkbox == ghCheckbox2) {
gwinSetVisible(ghContainer3, gwinCheckboxIsChecked(ghCheckbox2));
}
else if (((GEventGWinCheckbox*)pe)->checkbox == ghCheckbox3) {
gwinSetVisible(ghContainer1, gwinCheckboxIsChecked(ghCheckbox3));
}
break;
}
}
return 0;
}

View File

@ -3,6 +3,7 @@
*****************************************************************************
*** Changes After 2.1 ***
FEATURE: Added nested containers demo
*** Release 2.1 ***