Adding rendering functions to label widget to control text justification
This commit is contained in:
parent
ea4cadec78
commit
5d81aa2487
2 changed files with 53 additions and 14 deletions
|
@ -48,7 +48,7 @@ static const gwidgetVMT labelVMT = {
|
||||||
_gwidgetRedraw, // The redraw routine
|
_gwidgetRedraw, // The redraw routine
|
||||||
0, // The after-clear routine
|
0, // The after-clear routine
|
||||||
},
|
},
|
||||||
gwinLabelDefaultDraw, // default drawing routine
|
gwinLabelDrawJustifiedLeft, // default drawing routine
|
||||||
#if GINPUT_NEED_MOUSE
|
#if GINPUT_NEED_MOUSE
|
||||||
{
|
{
|
||||||
0, // Process mose down events (NOT USED)
|
0, // Process mose down events (NOT USED)
|
||||||
|
@ -134,10 +134,9 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) {
|
||||||
}
|
}
|
||||||
#endif // GWIN_LABEL_ATTRIBUTE
|
#endif // GWIN_LABEL_ATTRIBUTE
|
||||||
|
|
||||||
void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) {
|
static void gwinLabelDraw(GWidgetObject *gw, justify_t justify) {
|
||||||
coord_t w, h;
|
coord_t w, h;
|
||||||
color_t c;
|
color_t c;
|
||||||
(void) param;
|
|
||||||
|
|
||||||
// is it a valid handle?
|
// is it a valid handle?
|
||||||
if (gw->g.vmt != (gwinVMT *)&labelVMT)
|
if (gw->g.vmt != (gwinVMT *)&labelVMT)
|
||||||
|
@ -163,12 +162,12 @@ void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) {
|
||||||
|
|
||||||
#if GWIN_LABEL_ATTRIBUTE
|
#if GWIN_LABEL_ATTRIBUTE
|
||||||
if (gw2obj->attr) {
|
if (gw2obj->attr) {
|
||||||
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw2obj->tab, h, gw2obj->attr, gw->g.font, c, gw->pstyle->background, justifyLeft);
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, gw2obj->tab, h, gw2obj->attr, gw->g.font, c, gw->pstyle->background, justify);
|
||||||
gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, w-gw2obj->tab, h, gw->text, gw->g.font, c, gw->pstyle->background, justifyLeft);
|
gdispGFillStringBox(gw->g.display, gw->g.x + gw2obj->tab, gw->g.y, w-gw2obj->tab, h, gw->text, gw->g.font, c, gw->pstyle->background, justify);
|
||||||
} else
|
} else
|
||||||
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justifyLeft);
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justify);
|
||||||
#else
|
#else
|
||||||
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justifyLeft);
|
gdispGFillStringBox(gw->g.display, gw->g.x, gw->g.y, w, h, gw->text, gw->g.font, c, gw->pstyle->background, justify);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// render the border (if any)
|
// render the border (if any)
|
||||||
|
@ -176,6 +175,24 @@ void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) {
|
||||||
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, w, h, (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge);
|
gdispGDrawBox(gw->g.display, gw->g.x, gw->g.y, w, h, (gw->g.flags & GWIN_FLG_SYSENABLED) ? gw->pstyle->enabled.edge : gw->pstyle->disabled.edge);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gwinLabelDrawJustifiedLeft(GWidgetObject *gw, void *param) {
|
||||||
|
(void)param;
|
||||||
|
|
||||||
|
gwinLabelDraw(gw, justifyLeft);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gwinLabelDrawJustifiedRight(GWidgetObject *gw, void *param) {
|
||||||
|
(void)param;
|
||||||
|
|
||||||
|
gwinLabelDraw(gw, justifyRight);
|
||||||
|
}
|
||||||
|
|
||||||
|
void gwinLabelDrawJustifiedCenter(GWidgetObject *gw, void *param) {
|
||||||
|
(void)param;
|
||||||
|
|
||||||
|
gwinLabelDraw(gw, justifyCenter);
|
||||||
|
}
|
||||||
|
|
||||||
#undef gh2obj
|
#undef gh2obj
|
||||||
#undef gw2obj
|
#undef gw2obj
|
||||||
#endif // GFX_USE_GWIN && GFX_NEED_LABEL
|
#endif // GFX_USE_GWIN && GFX_NEED_LABEL
|
||||||
|
|
|
@ -117,14 +117,36 @@ void gwinLabelSetBorder(GHandle gh, bool_t border);
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief The default rendering function for the label widget
|
* @brief Renders a label with the text left jestified.
|
||||||
|
*
|
||||||
|
* @note This is the default rendering function.
|
||||||
*
|
*
|
||||||
* @param[in] gw The widget object (must be a label object)
|
* @param[in] gw The widget object (must be a label object)
|
||||||
* @param[in] param A parameter passed in from the user. Ignored by this function.
|
* @param[in] param A parameter passed in from the user. Ignored by this function.
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
void gwinLabelDefaultDraw(GWidgetObject *gw, void *param);
|
void gwinLabelDrawJustifiedLeft(GWidgetObject *gw, void *param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Renders a label with the text right jestified.
|
||||||
|
*
|
||||||
|
* @param[in] gw The widget object (must be a label object)
|
||||||
|
* @param[in] param A parameter passed in from the user. Ignored by this function.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
void gwinLabelDrawJustifiedRight(GWidgetObject *gw, void *param);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Renders a label with the text center jestified.
|
||||||
|
*
|
||||||
|
* @param[in] gw The widget object (must be a label object)
|
||||||
|
* @param[in] param A parameter passed in from the user. Ignored by this function.
|
||||||
|
*
|
||||||
|
* @api
|
||||||
|
*/
|
||||||
|
void gwinLabelDrawJustifiedCenter(GWidgetObject *gw, void *param);
|
||||||
|
|
||||||
/** @} */
|
/** @} */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue