Degree symbol in GUI Builder

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

    • Degree symbol in GUI Builder

      I want a Text label that reads degreesC - symbol, not the word degree. The only way I've found to do it is to copy a degree symbol from Character Map and then size the Text widget accordingly, then overwrite the degree symbol with \260, leaving me with a Text label reading "\260C" (can't do this with hex, only octal) so of course it looks rubbish in GUI Builder (but ok at run time.) Is there a better way to do this?
    • Hello,

      there is only support of the base ASCII set in text editable parameters of the widgets in GUIBuilder.

      The only thing you can do is generate the degree symbol as '°' in a text editor with extended symbols support (for example, in Word) and then paste it to the field "Content" of the text widget in GUIBuilder.

      Alex.
    • Hi,

      the proper way is to use UTF8 encoding.

      As LexaGB already said the GUIBuilder supports only the ASCII range.

      You have to set other strings manually. After GUI_Init() call GUI_SetEncodeUTF8() to enable UTF8 encoding.

      C Source Code

      1. GUI_Init();
      2. GUI_UC_SetEncodeUTF8();

      When setting a string to the TEXT widget you have to pass an UTF8 encoded string.

      C Source Code

      1. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      2. TEXT_SetText(hItem, "\xc2\xb0""C");

      You can use the tool U2C.exe to convert a txt file (it has to be saved with UTF8 encoding without BOM) into a c-file with the UTF8 string.

      More information can be found in the emWin user manual chapter 32.1.1 UTF-8 encoding.

      Here is an example:

      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Externals
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * Types
      11. *
      12. **********************************************************************
      13. */
      14. /*********************************************************************
      15. *
      16. * Defines
      17. *
      18. **********************************************************************
      19. */
      20. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      21. #define ID_TEXT_0 (GUI_ID_USER + 0x01)
      22. /*********************************************************************
      23. *
      24. * Static data
      25. *
      26. **********************************************************************
      27. */
      28. /*********************************************************************
      29. *
      30. * _aDialogCreate
      31. */
      32. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      33. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      34. { TEXT_CreateIndirect, "Text", ID_TEXT_0, 20, 20, 80, 20, 0, 0x64, 0 },
      35. };
      36. /*********************************************************************
      37. *
      38. * Static code
      39. *
      40. **********************************************************************
      41. */
      42. /*********************************************************************
      43. *
      44. * _cbDialog
      45. */
      46. static void _cbDialog(WM_MESSAGE * pMsg) {
      47. WM_HWIN hItem;
      48. switch (pMsg->MsgId) {
      49. case WM_INIT_DIALOG:
      50. //
      51. // Initialization of 'Text'
      52. //
      53. hItem = WM_GetDialogItem(pMsg->hWin, ID_TEXT_0);
      54. TEXT_SetText(hItem, "\xc2\xb0""C");
      55. break;
      56. default:
      57. WM_DefaultProc(pMsg);
      58. break;
      59. }
      60. }
      61. /*********************************************************************
      62. *
      63. * _cbBk
      64. */
      65. static void _cbBk(WM_MESSAGE * pMsg) {
      66. switch (pMsg->MsgId) {
      67. case WM_PAINT:
      68. GUI_SetBkColor(GUI_BLACK);
      69. GUI_Clear();
      70. break;
      71. default:
      72. WM_DefaultProc(pMsg);
      73. break;
      74. }
      75. }
      76. /*********************************************************************
      77. *
      78. * Public code
      79. *
      80. **********************************************************************
      81. */
      82. /*********************************************************************
      83. *
      84. * MainTask
      85. */
      86. void MainTask(void) {
      87. GUI_Init();
      88. GUI_UC_SetEncodeUTF8();
      89. WM_MULTIBUF_Enable(1);
      90. WM_SetCallback(WM_HBKWIN, _cbBk);
      91. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      92. while (1) {
      93. GUI_Delay(100);
      94. }
      95. }
      96. /*************************** End of file ****************************/
      Display All
      Regards,
      Sven
      Please read the forum rules before posting.

      Keep in mind, this is *not* a support forum.
      Our engineers will try to answer your questions between their projects if possible but this can be delayed by longer periods of time.
      Should you be entitled to support you can contact us via our support system: segger.com/ticket/

      Or you can contact us via e-mail.
    • Thanks both.

      Sven: I more-or-less tried this approach with the generated C file to set the Text widget, although I used octal rather than hex - I learnt something today from the use of hex in your code above! I did know how to do it in code - and when I tried, I didn't need to set anything to UTF-8 as the font used supported the character.

      I rather suspected that I would need to do it manually if necessary, I just thought I'd check as I'm new to emWin. The approach I tried, by setting the text to "\260C" in GUI Builder works at run-time and if it only supports ASCII fonts then that's not surprising.

      Thanks

      Andrew