diff --git a/include/gwin/label.h b/include/gwin/label.h index c11b5c72..3156ca71 100644 --- a/include/gwin/label.h +++ b/include/gwin/label.h @@ -39,8 +39,8 @@ extern "C" { #endif /** - * @brief Create a label widget. - * @details A label widget is a simple window which has a static text. + * @brief Create a label widget. + * @details A label widget is a simple window which has a static text. * * @param[in] widget The label structure to initialise. If this is NULL, the structure is dynamically allocated. * @param[in] pInit The initialisation parameters to use. @@ -51,6 +51,16 @@ extern "C" { */ GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit); +/** + * @brief Border settings for the default rendering routine + * + * @param[in] gh The widget handle (must be a list handle) + * @param[in] border Shall a border be rendered? + * + * @api + */ +void gwinLabelSetBorder(GHandle gh, bool_t border); + #ifdef __cplusplus } #endif diff --git a/releases.txt b/releases.txt index 20e34b4d..45ec3cbc 100644 --- a/releases.txt +++ b/releases.txt @@ -15,6 +15,7 @@ FEATURE: ED060SC4 driver by user jpa- FIX: SSD1289 area filling bug fix by user samofab FEATURE: Added gwinListGetSelectedText() FEATURE: Added gwinListSetScroll() +FEATURE: Added gwinLabelSetBorder() *** changes after 1.7 *** diff --git a/src/gwin/label.c b/src/gwin/label.c index a933b3ac..750cb4fb 100644 --- a/src/gwin/label.c +++ b/src/gwin/label.c @@ -21,16 +21,22 @@ #include "gwin/class_gwin.h" -#define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG<<0) -#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG<<1) +// macros to assist in data type conversions +#define gh2obj ((GLabelObject *)gh) -// Simple: single line with no wrapping +// flags for the GLabelObject +#define GLABEL_FLG_WAUTO (GWIN_FIRST_CONTROL_FLAG << 0) +#define GLABEL_FLG_HAUTO (GWIN_FIRST_CONTROL_FLAG << 1) +#define GLABEL_FLG_BORDER (GWIN_FIRST_CONTROL_FLAG << 2) + +// simple: single line with no wrapping static coord_t getwidth(const char *text, font_t font, coord_t maxwidth) { (void) maxwidth; + return gdispGetStringWidth(text, font)+2; // Allow one pixel of padding on each side } -// Simple: single line with no wrapping +// simple: single line with no wrapping static coord_t getheight(const char *text, font_t font, coord_t maxwidth) { (void) text; (void) maxwidth; @@ -47,12 +53,18 @@ static void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) { if (gw->g.width != w || gw->g.height != h) { gwinResize(&gw->g, w, h); + return; } + // render the text gdispFillStringBox(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); + + // render the border (if any) + if (gw->g.flags & GLABEL_FLG_BORDER) + gdispDrawBox(gw->g.x, gw->g.y, gw->g.width, gw->g.height, (gw->g.flags & GWIN_FLG_ENABLED) ? gw->pstyle->enabled.text : gw->pstyle->disabled.text); } static const gwidgetVMT labelVMT = { @@ -109,12 +121,25 @@ GHandle gwinLabelCreate(GLabelObject *widget, GWidgetInit *pInit) { if (!(widget = (GLabelObject *)_gwidgetCreate(&widget->w, pInit, &labelVMT))) return 0; - widget->w.g.flags |= flags; + // no borders by default + widget->w.g.flags &=~ GLABEL_FLG_BORDER; gwinSetVisible(&widget->w.g, pInit->g.show); + return (GHandle)widget; } +void gwinLabelSetBorder(GHandle gh, bool_t border) { + // is it a valid handle? + if (gh->vmt != (gwinVMT *)&labelVMT) + return; + + if (border) + gh2obj->w.g.flags |= GLABEL_FLG_BORDER; + else + gh2obj->w.g.flags &=~ GLABEL_FLG_BORDER; +} + #endif // GFX_USE_GWIN && GFX_NEED_LABEL /** @} */