glcd: improve text alignment

Origin commit data
------------------
Branch: ni/coolstream
Commit: 8479b7b784
Author: vanhofen <vanhofen@gmx.de>
Date: 2020-07-01 (Wed, 01 Jul 2020)

Origin message was:
------------------
- glcd: improve text alignment

------------------
No further description and justification available within origin commit message!

------------------
This commit was generated by Migit
This commit is contained in:
vanhofen
2020-07-01 00:21:45 +02:00
parent 2d7b367ca4
commit 932de18276

View File

@@ -1517,6 +1517,7 @@ bool cGLCD::imageShow(const std::string & filename, uint32_t dx, uint32_t dy, ui
bool cGLCD::drawText(int x, int y, int xmax, int text_width, const std::string & text, const GLCD::cFont * font, uint32_t color1, uint32_t color2, bool proportional, int skipPixels, int align) bool cGLCD::drawText(int x, int y, int xmax, int text_width, const std::string & text, const GLCD::cFont * font, uint32_t color1, uint32_t color2, bool proportional, int skipPixels, int align)
{ {
int z = 0; int z = 0;
int offset = 10; // px
if (align == ALIGN_NONE) if (align == ALIGN_NONE)
{ {
@@ -1524,15 +1525,15 @@ bool cGLCD::drawText(int x, int y, int xmax, int text_width, const std::string &
} }
else if (align == ALIGN_LEFT) else if (align == ALIGN_LEFT)
{ {
z = std::max(2, (bitmap->Width() - 4 - text_width) / 24); z = offset;
} }
else if (align == ALIGN_CENTER) else if (align == ALIGN_CENTER)
{ {
z = std::max(2, (bitmap->Width() - 4 - text_width) / 2); z = std::max(offset, (bitmap->Width() - text_width) / 2);
} }
else if (align == ALIGN_RIGHT) else if (align == ALIGN_RIGHT)
{ {
z = std::max(2, (bitmap->Width() - 4 - text_width)); z = std::max(offset, (bitmap->Width() - text_width - offset));
} }
return bitmap->DrawText(z, y, xmax, text, font, color1, color2, proportional, skipPixels); return bitmap->DrawText(z, y, xmax, text, font, color1, color2, proportional, skipPixels);