diff options
author | Joel Bodenmann <joel@unormal.org> | 2014-01-04 04:41:32 +0100 |
---|---|---|
committer | Joel Bodenmann <joel@unormal.org> | 2014-01-04 04:41:32 +0100 |
commit | abe6a47c1f59941faac719770aa654d2c79cacef (patch) | |
tree | bae98fd4e90b4e1467523a26fbd1263dc78b0777 | |
parent | 07869da90938e375e71081d30757cc767596b431 (diff) | |
download | uGFX-abe6a47c1f59941faac719770aa654d2c79cacef.tar.gz uGFX-abe6a47c1f59941faac719770aa654d2c79cacef.tar.bz2 uGFX-abe6a47c1f59941faac719770aa654d2c79cacef.zip |
basic implementation of parent/child (no flag handling done yet)
-rw-r--r-- | gfxconf.example.h | 2 | ||||
-rw-r--r-- | include/gfx_rules.h | 11 | ||||
-rw-r--r-- | include/gwin/gwidget.h | 2 | ||||
-rw-r--r-- | include/gwin/gwin.h | 21 | ||||
-rw-r--r-- | include/gwin/options.h | 7 | ||||
-rw-r--r-- | src/gwin/gwin.c | 29 |
6 files changed, 69 insertions, 3 deletions
diff --git a/gfxconf.example.h b/gfxconf.example.h index 4631cddc..38e36100 100644 --- a/gfxconf.example.h +++ b/gfxconf.example.h @@ -128,8 +128,8 @@ #define GWIN_CONSOLE_USE_BASESTREAM FALSE #define GWIN_CONSOLE_USE_FLOAT FALSE #define GWIN_NEED_GRAPH FALSE - #define GWIN_NEED_WIDGET FALSE + #define GWIN_NEED_HIERARCHY FALSE #define GWIN_NEED_LABEL FALSE #define GWIN_NEED_BUTTON FALSE #define GWIN_BUTTON_LAZY_RELEASE FALSE diff --git a/include/gfx_rules.h b/include/gfx_rules.h index a129ef76..301cf263 100644 --- a/include/gfx_rules.h +++ b/include/gfx_rules.h @@ -58,11 +58,20 @@ #endif #endif #endif + #if GWIN_NEED_HIERARCHY + #if !GQUEUE_NEED_ASYNC + #if GFX_DISPLAY_RULE_WARNINGS + #warning "GWIN: GQUEUE_NEED_ASYNC is required when a GWIN_NEED_HIERARCHY is enabled. It has been turned on for you." + #endif + #undef GQUEUE_NEED_ASYNC + #define GQUEUE_NEED_ASYNC TRUE + #endif + #endif #if GWIN_NEED_BUTTON || GWIN_NEED_SLIDER || GWIN_NEED_CHECKBOX || GWIN_NEED_LABEL || GWIN_NEED_RADIO || GWIN_NEED_LIST || \ GWIN_NEED_IMAGE || GWIN_NEED_CHECKBOX || GWIN_NEED_PROGRESSBAR #if !GWIN_NEED_WIDGET #if GFX_DISPLAY_RULE_WARNINGS - #warning "GWIN: GWIN_NEED_WIDGET is required when a Widget is used. It has been turned on for you." + #warning "GWIN: GWIN_NEED_WIDGET is required when a widget is used. It has been turned on for you." #endif #undef GWIN_NEED_WIDGET #define GWIN_NEED_WIDGET TRUE diff --git a/include/gwin/gwidget.h b/include/gwin/gwidget.h index a18d69b6..fa40c51c 100644 --- a/include/gwin/gwidget.h +++ b/include/gwin/gwidget.h @@ -27,7 +27,7 @@ * @{ */ -// Forward definition +/* Forward definition */ struct GWidgetObject; /** diff --git a/include/gwin/gwin.h b/include/gwin/gwin.h index 96055376..b9d4f966 100644 --- a/include/gwin/gwin.h +++ b/include/gwin/gwin.h @@ -27,6 +27,9 @@ #if GFX_USE_GWIN || defined(__DOXYGEN__) +/* Forward declaration */ +typedef struct GWindowObject *GHandle; + /** * @brief A window object structure * @note Do not access the members directly. Treat it as a black-box and use the method functions. @@ -46,6 +49,11 @@ typedef struct GWindowObject { #if GDISP_NEED_TEXT font_t font; // @< The current font #endif + #if GWIN_NEED_HIERARCHY + GHandle *parent; // @< The pointer to the parent (or NULL) + GHandle *sibling; // @< The pointer to a widgets brother + GHandle *child; // @< The pointer to a widgets child + #endif } GWindowObject, * GHandle; /* @} */ @@ -377,6 +385,19 @@ extern "C" { */ void gwinRedraw(GHandle gh); + #if GWIN_NEED_HIERARCHY + /** + * @brief Add a child widget to a parent one + * + * @param[in] parent The parent widget (does not need to be parent yet) + * @param[in] child The child widget + * @param[in] last Should the child widget be added to the front or the back of the list? + * + * @api + */ + void gwinAddChild(GHandle parent, GHandle child, bool_t last); + #endif + #if GWIN_NEED_WINDOWMANAGER || defined (__DOXYGEN__) /** * @brief Redraw a window diff --git a/include/gwin/options.h b/include/gwin/options.h index e6d2a81e..83aaee2c 100644 --- a/include/gwin/options.h +++ b/include/gwin/options.h @@ -30,6 +30,13 @@ #define GWIN_NEED_WIDGET FALSE #endif /** + * @brief Should the widget hierarchy be included. This provides parent-child features. + * @details Defaults to FALSE + */ + #ifndef GWIN_NEED_HIERARCHY + #define GWIN_NEED_HIERARCHY FALSE + #endif + /** * @brief Should widget functions be included. Needed for any widget (eg Buttons, Sliders etc) * @details Defaults to FALSE */ diff --git a/src/gwin/gwin.c b/src/gwin/gwin.c index 6b9cb81e..3a4ae5b5 100644 --- a/src/gwin/gwin.c +++ b/src/gwin/gwin.c @@ -167,7 +167,15 @@ color_t gwinGetDefaultBgColor(void) { GHandle gwinGWindowCreate(GDisplay *g, GWindowObject *pgw, const GWindowInit *pInit) { if (!(pgw = _gwindowCreate(g, pgw, pInit, &basegwinVMT, 0))) return 0; + + #if GWIN_NEED_HIERARCHY + pgw->parent = NULL; + pgw->sibling = NULL; + pgw->child = NULL; + #endif + gwinSetVisible(pgw, pInit->show); + return pgw; } @@ -250,6 +258,27 @@ void gwinRedraw(GHandle gh) { } #endif +#if GWIN_NEED_HIERARCHY + void gwinAddChild(GHandle parent, GHandle child, bool_t last) + { + child->parent = parent; + child->sibling = NULL; + child->child = NULL; + + if(!parent) + return; + + if(last && parent->child) { + GHandle s = parent->child; + while(s->sibling) s = s->sibling; + s->sibling = child; + } else { + child->sibling = parent->child; + parent->child = child; + } + } +#endif + void gwinClear(GHandle gh) { /* * Don't render anything when the window is not visible but |