diff options
author | inmarket <andrewh@inmarket.com.au> | 2013-07-04 00:20:32 +1000 |
---|---|---|
committer | inmarket <andrewh@inmarket.com.au> | 2013-07-04 00:20:32 +1000 |
commit | 09a359813f0abe8f99c32dadfa1ac2c68356ddfd (patch) | |
tree | ce6bfc9861baac4ed2de9e84995f307b8fd7cffa /src/gwin/label.c | |
parent | 3f80e1f89dbeec06dd97a914d6851ad4596b1743 (diff) | |
download | uGFX-09a359813f0abe8f99c32dadfa1ac2c68356ddfd.tar.gz uGFX-09a359813f0abe8f99c32dadfa1ac2c68356ddfd.tar.bz2 uGFX-09a359813f0abe8f99c32dadfa1ac2c68356ddfd.zip |
Label, Image and Window Manager changes
Diffstat (limited to 'src/gwin/label.c')
-rw-r--r-- | src/gwin/label.c | 44 |
1 files changed, 27 insertions, 17 deletions
diff --git a/src/gwin/label.c b/src/gwin/label.c index 7f8ab814..e757892d 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -21,26 +21,36 @@ #include "gwin/class_gwin.h" -#define widget(gh) ((GLabelWidget*)gh) #define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG<<0) #define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1) -static void gwinLabelDefaultDraw(GHandle gh) { - // if( check if auto flag is set ) - // if( call current size != font size ) - // gwinResize(); +// Simple: single line with no wrapping +static coord_t getwidth(const char *txt, font_t font, coord_t maxwidth) { + (void) maxwidth; + return gdispGetStringWidth(txt, font)+2; // Allow one pixel of padding on each side +} + +// Simple: single line with no wrapping +static coord_t getheight(const char *txt, font_t font, coord_t maxwidth) { + (void) txt; + (void) maxwidth; + + return gdispGetFontMetric(font, fontHeight); +} + +static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { + (void) param; + coord_t w, h; - gdispFillString( widget(gh)->w.g.x, - widget(gh)->w.g.y, - widget(gh)->w.txt, - widget(gh)->w.g.font, - widget(gh)->w.g.color, - widget(gh)->w.g.bgcolor - ); + w = (gw->g.flags & GLABEL_FLG_WAUTO) ? getwidth(gw->txt, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.width; + h = (gw->g.flags & GLABEL_FLG_HAUTO) ? getheight(gw->txt, gw->g.font, gdispGetWidth() - gw->g.x) : gw->g.height; - gdispFillArea( widget(gh)->w.g.x, widget(gh)->w.g.y, widget(gh)->w.g.width, widget(gh)->w.g.height, Green); + if (gw->g.width != w || gw->g.height != h) { + gwinResize(&gw->g, w, h); + return; + } - printf("Text: %s\r\n", widget(gh)->w.txt); + gdispFillStringBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, gw->txt, gw->g.font, gw->g.color, gw->g.bgcolor, justifyLeft); } static const gwidgetVMT labelVMT = { @@ -78,21 +88,21 @@ GHandle gwinLabelCreate(GLabelWidget *widget, GWidgetInit *pInit) { // auto assign width if (pInit->g.width <= 0) { flags |= GLABEL_FLG_WAUTO; - pInit->g.width = gdispGetStringWidth(pInit->text, gwinGetDefaultFont()); + pInit->g.width = getwidth(pInit->text, gwinGetDefaultFont(), gdispGetWidth() - pInit->g.x); } // auto assign height if (pInit->g.height <= 0) { flags |= GLABEL_FLG_HAUTO; - pInit->g.height = gdispGetFontMetric(gwinGetDefaultFont(), fontHeight); + pInit->g.height = getheight(pInit->text, gwinGetDefaultFont(), gdispGetWidth() - pInit->g.x); } if (!(widget = (GLabelWidget *)_gwidgetCreate(&widget->w, pInit, &labelVMT))) return 0; - gwinLabelDefaultDraw((GHandle)widget); widget->w.g.flags |= flags; + gwinSetVisible(&widget->w.g, pInit->g.show); return (GHandle)widget; } |