aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJoel Bodenmann <joel@seriouslyembedded.com>2015-11-14 19:42:58 +0100
committerJoel Bodenmann <joel@seriouslyembedded.com>2015-11-14 19:42:58 +0100
commit14b5184d60681ed92a07606185f7b4b26edbbcd1 (patch)
treea44c6296399c0206b5fc1cafebdd3988d6b3be1b /src
parent849369cceccfa3b9d70257306a8a93cfb852263e (diff)
downloaduGFX-14b5184d60681ed92a07606185f7b4b26edbbcd1.tar.gz
uGFX-14b5184d60681ed92a07606185f7b4b26edbbcd1.tar.bz2
uGFX-14b5184d60681ed92a07606185f7b4b26edbbcd1.zip
Fixing vertical center alignment issue when word-wrap is turned on
Diffstat (limited to 'src')
-rw-r--r--src/gdisp/gdisp.c27
1 files changed, 23 insertions, 4 deletions
diff --git a/src/gdisp/gdisp.c b/src/gdisp/gdisp.c
index 84215796..31f08bec 100644
--- a/src/gdisp/gdisp.c
+++ b/src/gdisp/gdisp.c
@@ -3169,6 +3169,12 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
/* Callback to render string boxes with word wrap. */
#if GDISP_NEED_TEXT_WORDWRAP
+ static bool mf_countline_callback(mf_str line, uint16_t count, void *state) {
+ int *linecount = (int*)state;
+ (*linecount)++;
+
+ return TRUE;
+ }
static bool mf_drawline_callback(mf_str line, uint16_t count, void *state) {
wrapParameters_t* wrapParameters = (wrapParameters_t*)state;
@@ -3176,7 +3182,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
wrapParameters->y += wrapParameters->font->line_height;
return TRUE;
- }
+ }
static bool mf_fillline_callback(mf_str line, uint16_t count, void *state) {
wrapParameters_t* wrapParameters = (wrapParameters_t*)state;
@@ -3258,6 +3264,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
void gdispGDrawStringBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, font_t font, color_t color, justify_t justify) {
#if GDISP_NEED_TEXT_WORDWRAP
wrapParameters_t wrapParameters;
+ uint16_t nbrLines;
#endif
MUTEX_ENTER(g);
@@ -3281,7 +3288,6 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
x += font->baseline_x;
break;
}
- y += (cy+1 - font->height)/2;
/* Render */
#if GDISP_NEED_TEXT_WORDWRAP
@@ -3291,8 +3297,14 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
wrapParameters.justify = justify;
wrapParameters.g = g;
- mf_wordwrap(font, cx, str, mf_drawline_callback, &wrapParameters);
+ // Count the number of lines
+ nbrLines = 0;
+ mf_wordwrap(font, cx, str, mf_countline_callback, &nbrLines);
+ wrapParameters.y += (cy+1 - nbrLines*font->height)/2;
+
+ mf_wordwrap(font, cx, str, mf_fillline_callback, &wrapParameters);
#else
+ y += (cy+1 - font->height)/2;
mf_render_aligned(font, x, y, justify, str, 0, drawcharglyph, g);
#endif
@@ -3303,6 +3315,7 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
void gdispGFillStringBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, const char* str, font_t font, color_t color, color_t bgcolor, justify_t justify) {
#if GDISP_NEED_TEXT_WORDWRAP
wrapParameters_t wrapParameters;
+ uint16_t nbrLines;
#endif
MUTEX_ENTER(g);
@@ -3334,7 +3347,6 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
x += font->baseline_x;
break;
}
- y += (cy+1 - font->height)/2;
/* Render */
#if GDISP_NEED_TEXT_WORDWRAP
@@ -3344,8 +3356,15 @@ void gdispGDrawBox(GDisplay *g, coord_t x, coord_t y, coord_t cx, coord_t cy, co
wrapParameters.justify = justify;
wrapParameters.g = g;
+
+ // Count the number of lines
+ nbrLines = 0;
+ mf_wordwrap(font, cx, str, mf_countline_callback, &nbrLines);
+ wrapParameters.y += (cy+1 - nbrLines*font->height)/2;
+
mf_wordwrap(font, cx, str, mf_fillline_callback, &wrapParameters);
#else
+ y += (cy+1 - font->height)/2;
mf_render_aligned(font, x, y, justify, str, 0, fillcharglyph, g);
#endif
}