Fix printing horizontal start coordinates

This commit is contained in:
Niccolò Izzo 2020-12-18 19:21:23 +01:00
parent c7e928666c
commit 85b1fb08e6
3 changed files with 17 additions and 13 deletions

View File

@ -197,11 +197,13 @@ static inline uint16_t get_line_size(GFXfont f,
* @param alinment: enum representing the text alignment
* @param line_size: the size of the current text line in pixels
*/
static inline uint16_t get_reset_x(textAlign_t alignment, uint16_t line_size) {
static inline uint16_t get_reset_x(textAlign_t alignment,
uint16_t line_size,
uint16_t startx) {
switch(alignment)
{
case TEXT_ALIGN_LEFT:
return 0;
return startx;
case TEXT_ALIGN_CENTER:
return (SCREEN_WIDTH - line_size)/2;
case TEXT_ALIGN_RIGHT:
@ -220,7 +222,7 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
// Compute size of the first row in pixels
uint16_t line_size = get_line_size(f, text, len);
uint16_t reset_x = get_reset_x(alignment, line_size);
uint16_t reset_x = get_reset_x(alignment, line_size, start.x);
start.x = reset_x;
/* For each char in the string */
@ -249,7 +251,7 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
if (start.x + glyph.xAdvance > SCREEN_WIDTH) {
// Compute size of the first row in pixels
line_size = get_line_size(f, text, len);
start.x = reset_x = get_reset_x(alignment, line_size);
start.x = reset_x = get_reset_x(alignment, line_size, start.x);
start.y += f.yAdvance;
}

View File

@ -196,11 +196,13 @@ static inline uint16_t get_line_size(GFXfont f,
* @param alinment: enum representing the text alignment
* @param line_size: the size of the current text line in pixels
*/
static inline uint16_t get_reset_x(textAlign_t alignment, uint16_t line_size) {
static inline uint16_t get_reset_x(textAlign_t alignment,
uint16_t line_size,
uint16_t startx) {
switch(alignment)
{
case TEXT_ALIGN_LEFT:
return 0;
return startx;
case TEXT_ALIGN_CENTER:
return (SCREEN_WIDTH - line_size)/2;
case TEXT_ALIGN_RIGHT:
@ -219,7 +221,7 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
// Compute size of the first row in pixels
uint16_t line_size = get_line_size(f, text, len);
uint16_t reset_x = get_reset_x(alignment, line_size);
uint16_t reset_x = get_reset_x(alignment, line_size, start.x);
start.x = reset_x;
/* For each char in the string */
@ -248,7 +250,7 @@ void gfx_print(point_t start, const char *text, fontSize_t size, textAlign_t ali
if (start.x + glyph.xAdvance > SCREEN_WIDTH) {
// Compute size of the first row in pixels
line_size = get_line_size(f, text, len);
start.x = reset_x = get_reset_x(alignment, line_size);
start.x = reset_x = get_reset_x(alignment, line_size, start.x);
start.y += f.yAdvance;
}

View File

@ -185,11 +185,11 @@ layout_t _ui_calculateLayout()
#endif
// Calculate printing positions
point_t top_pos = {0, top_h - vertical_pad};
point_t line1_pos = {0, top_h + line1_h - line_pad};
point_t line2_pos = {0, top_h + line1_h + line2_h - line_pad};
point_t line3_pos = {0, top_h + line1_h + line2_h + line3_h - line_pad};
point_t bottom_pos = {0, top_h + line1_h + line2_h + line3_h + bottom_h - vertical_pad};
point_t top_pos = {horizontal_pad, top_h - vertical_pad};
point_t line1_pos = {horizontal_pad, top_h + line1_h - line_pad};
point_t line2_pos = {horizontal_pad, top_h + line1_h + line2_h - line_pad};
point_t line3_pos = {horizontal_pad, top_h + line1_h + line2_h + line3_h - line_pad};
point_t bottom_pos = {horizontal_pad, top_h + line1_h + line2_h + line3_h + bottom_h - vertical_pad};
layout_t new_layout =
{