diff options
author | inmarket <andrewh@inmarket.com.au> | 2014-05-01 16:45:26 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2014-05-01 16:45:26 +1000 |
commit | b37370bdb5e3f5ffa325619c78d31c9993e79745 (patch) | |
tree | d6fa26689362a70ac3e3e2034bbfdf44e855c80a /src/gwin/label.c | |
parent | 558ee7282d9f753519d7a813f1b9206c31e6f247 (diff) | |
download | uGFX-b37370bdb5e3f5ffa325619c78d31c9993e79745.tar.gz uGFX-b37370bdb5e3f5ffa325619c78d31c9993e79745.tar.bz2 uGFX-b37370bdb5e3f5ffa325619c78d31c9993e79745.zip |
Added extra safety to GWIN objects
Diffstat (limited to 'src/gwin/label.c')
-rw-r--r-- | src/gwin/label.c | 85 |
1 files changed, 44 insertions, 41 deletions
diff --git a/src/gwin/label.c b/src/gwin/label.c index 574dc8b7..8960300b 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -45,44 +45,7 @@ static coord_t getheight(const char *text, font_t font, coord_t maxwidth) { return gdispGetFontMetric(font, fontHeight); } -static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { - coord_t w, h; - (void) param; - - w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.width; - h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.height; - - if (gw->g.width != w || gw->g.height != h) { - gwinResize(&gw->g, w, h); - - return; - } - - #if GWIN_LABEL_ATTRIBUTE - if (gw2obj->attr != 0) { - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw2obj->attr, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - - gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - } else { - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - - } - #else - gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, - (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, - justifyLeft); - #endif - - // render the border (if any) - if (gw->g.flags & GLABEL_FLG_BORDER) - gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); -} +static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param); static const gwidgetVMT labelVMT = { { @@ -138,9 +101,6 @@ GHandle gwinGLabelCreate(GDisplay *g, GLabelObject *widget, GWidgetInit *pInit) if (!(widget = (GLabelObject *)_gwidgetCreate(g, &widget->w, pInit, &labelVMT))) return 0; - // no borders by default - flags &=~ GLABEL_FLG_BORDER; - #if GWIN_LABEL_ATTRIBUTE widget->tab = 0; widget->attr = 0; @@ -176,6 +136,49 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) { } #endif // GWIN_LABEL_ATTRIBUTE +static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { + coord_t w, h; + (void) param; + + // is it a valid handle? + if (gw->g.vmt != (gwinVMT *)&labelVMT) + return; + + w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.width; + h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->text, gw->g.font, gdispGGetWidth(gw->g.display) - gw->g.x) : gw->g.height; + + if (gw->g.width != w || gw->g.height != h) { + gwinResize(&gw->g, w, h); + + return; + } + + #if GWIN_LABEL_ATTRIBUTE + if (gw2obj->attr != 0) { + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw2obj->attr, gw->g.font, + (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, + justifyLeft); + + gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, + (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, + justifyLeft); + } else { + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, + (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, + justifyLeft); + + } + #else + gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->text, gw->g.font, + (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text, gw->pstyle->background, + justifyLeft); + #endif + + // render the border (if any) + if (gw->g.flags & GLABEL_FLG_BORDER) + gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge); +} + #endif // GFX_USE_GWIN && GFX_NEED_LABEL /** @} */ |