aboutsummaryrefslogtreecommitdiffstats
path: root/src/gwin
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-11-07 00:51:23 +0100
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-11-07 00:51:23 +0100
commit5d81aa2487f8a41d64ad49bd04f29850b2371dd0 (patch)
treebd187c7df2086b332b6a66a87559ac518a466cfe /src/gwin
parentea4cadec78ba4e559f7fa1049f7d202e9e316fb7 (diff)
downloaduGFX-5d81aa2487f8a41d64ad49bd04f29850b2371dd0.tar.gz
uGFX-5d81aa2487f8a41d64ad49bd04f29850b2371dd0.tar.bz2
uGFX-5d81aa2487f8a41d64ad49bd04f29850b2371dd0.zip
Adding rendering functions to label widget to control text justification
Diffstat (limited to 'src/gwin')
-rw-r--r--src/gwin/gwin_label.c41
-rw-r--r--src/gwin/gwin_label.h26
2 files changed, 53 insertions, 14 deletions
diff --git a/src/gwin/gwin_label.c b/src/gwin/gwin_label.c
index 9b62679f..97311a3e 100644
--- a/src/gwin/gwin_label.c
+++ b/src/gwin/gwin_label.c
@@ -42,13 +42,13 @@ static coord_t getheight(const char *text, font_t font, coord_t maxwidth) {
static const gwidgetVMT labelVMT = {
{
- "Label", // The class name
- sizeof(GLabelObject), // The object size
- _gwidgetDestroy, // The destroy routine
- _gwidgetRedraw, // The redraw routine
- 0, // The after-clear routine
+ "Label", // The class name
+ sizeof(GLabelObject), // The object size
+ _gwidgetDestroy, // The destroy routine
+ _gwidgetRedraw, // The redraw routine
+ 0, // The after-clear routine
},
- gwinLabelDefaultDraw, // default drawing routine
+ gwinLabelDrawJustifiedLeft, // default drawing routine
#if GINPUT_NEED_MOUSE
{
0, // Process mose down events (NOT USED)
@@ -134,10 +134,9 @@ void gwinLabelSetBorder(GHandle gh, bool_t border) {
}
#endif // GWIN_LABEL_ATTRIBUTE
-void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) {
+static void gwinLabelDraw(GWidgetObject *gw, justify_t justify) {
coord_t w, h;
color_t c;
- (void) param;
// is it a valid handle?
if (gw->g.vmt != (gwinVMT *)&labelVMT)
@@ -163,12 +162,12 @@ void gwinLabelDefaultDraw(GWidgetObject *gw, void *param) {
#if GWIN_LABEL_ATTRIBUTE
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 + 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, 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, justify);
} 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
- 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
// 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);
}
+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 gw2obj
#endif // GFX_USE_GWIN && GFX_NEED_LABEL
diff --git a/src/gwin/gwin_label.h b/src/gwin/gwin_label.h
index aaacd253..d9abe0e0 100644
--- a/src/gwin/gwin_label.h
+++ b/src/gwin/gwin_label.h
@@ -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] param A parameter passed in from the user. Ignored by this function.
+ *
+ * @api
+ */
+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 gwinLabelDefaultDraw(GWidgetObject *gw, void *param);
+void gwinLabelDrawJustifiedCenter(GWidgetObject *gw, void *param);
/** @} */