GUI_DispStringInRectEx & Alignment Problems

This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

  • GUI_DispStringInRectEx & Alignment Problems

    GUI_DispStringInRectEx does not work as intended if ((TextAlign & GUI_TA_VCENTER) && (MaxLen < strlen(acText))).

    How to reproduce:

    C Source Code

    1. GUI_RECT Rect = {0, 0, 21, 8};
    2. char acText[] = "Text";
    3. GUI_SetFont(&GUI_Font8_1);
    4. GUI_DispStringInRectEx(acText, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER, strlen(acText) - 1, GUI_ROTATE_0);


    Here's the output if (MaxLen == strlen(acText)):
    [img]http://s17.postimg.org/4m379k7yz/ss3.jpg[/img]

    Here's the actual output:
    [img]http://s4.postimg.org/kqhogef09/ss1.jpg[/img]

    Here's the expected output:
    [img]http://s8.postimg.org/eehb7yd6p/ss2.jpg[/img]

    Actually this is not exactly the expected output. There's also a bug in the text alignment. As you see on the third screenshot "Tex" is not properly aligned to center. emWin does count last character's whitespace pixels while it's calculating a string's rectangle. There's a new function named GUI_GetTrailingBlankCols introduced recently. If emWin uses this function to calculate correct size of the string it'll be perfect.

    I know i'm talking about a few pixels but it's very important if your application works on a very low resolution screen.

    Update: After further investigation, i found that this function needs a null character at acText[MaxLen]. As a workaround i had to buffer my partial string. But as i was printing this string directly from flash memory, now i had to allocate a buffer. :(

    The post was edited 3 times, last by kneeangel ().

  • Hello,

    Thank you for reporting this behavior. You are right. In this case the function could work better. We will change this, so it will not be necessary to close the string with a '\0'-character. The corrected function will be available in the next emWin version. The release date is currently not fixed.

    Please excuse the caused inconveniences.

    If you have any further questions, please let me know.

    Best regards,
    Adrian