Displaying string with different char colors

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

    • Displaying string with different char colors


      I would like to display an UTF-8 string using different char colors with certain GUI_RECT, GUI_WRAPMODE_WORD and GUI_TA_HCENTER | GUI_TA_VCENTER defined. Is there any way to do it, except drawing char by char manually??
    • Hi,

      With the routines GUI_DispString()/GUI_DispChar() you could switch colors or fonts between strings with ease since the last char position is saved by the routines. But I'm afraid there is no easy way to do this with GUI_DispStringInRectWrap().

      You would have to calculate the position for each char/string manually. GUI_GetStringDistX() can be used to check the x-size of a string with the currently set font. Use GUI_GetCharDistX() for single characters.

      By the way, to draw UTF-8 strings you have to enable UTF-8 support. This can be done by calling GUI_UC_SetEncodeUTF8() beforehand. You can find more about this in the user manual.

      Best regards,
    • Hi,

      emWin's supported character range is Unicode 0x0000 - 0xFFFF. This means 24-bit or 32-bit UC characters are not supported.

      Unicode is enabled per default, this means you can pass any value in the 16 bit range to GUI_DispChar().

      To display non-ASCII character strings, UTF-8 support has to be enabled and the non-ASCII characters have to be in 8-bit hexadecimal form. Here you can find an encoding tool that converts any text (e.g. Arabic, Japanese...) into the 8-bit hexadecimal form. For example:

      C Source Code

      1. GUI_UC_SetEncodeUTF8();
      2. GUI_DispString("Hal\xc3\xb6le");

      And always make sure the emWin font you are currently using contains all the characters that you want to display. Otherwise, the character will be skipped.

      Best regards,