Vertical PROGBAR text won't display

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

  • Vertical PROGBAR text won't display

    The text in this progress bar displays:
    ahTempBar = PROGBAR_CreateEx(0, 150, 60, 200, 0, WM_CF_SHOW, PROGBAR_CF_HORIZONTAL, 0);
    PROGBAR_SetFont(ahTempBar, &GUI_Font8x16);
    PROGBAR_SetTextColor(ahTempBar, 0, GUI_BLACK);
    PROGBAR_SetTextColor(ahTempBar, 1, GUI_BLACK);
    PROGBAR_SetBarColor(ahTempBar, 0, GUI_GREEN);
    PROGBAR_SetBarColor(ahTempBar, 1, GUI_WHITE);
    PROGBAR_SetTextAlign(ahTempBar, GUI_TA_VCENTER);
    PROGBAR_SetText(ahTempBar, "Test");

    When I change PROGBAR_CF_HORIZONTAL to PROGBAR_CF_VERTICAL the text doesn't show no matter what I try.
  • Hello,

    Vertical PROGBAR widgets do not display any text at all. I would suggest overwriting the callback function in order to do the following:

    C Source Code

    1. ...
    2. case WM_PAINT:
    3. PROGBAR_Callback(pMsg); // Let the widget draw itself
    4. //
    5. // Display the text on top.
    6. //
    7. break;
    8. ...

    Best regards,
    Adrian
  • There is one problem with this approach. There is no PROGBAR_GetText so I have no way to know what text would be drawn in the bar if was horizontal. Of course I can use a global variable but that is just a crude workaround. Unless there is something I am missing...?
  • Hello,

    You are right. There is not function PROGBAR_GetText(). We might add it in a future emWin version.

    For now I would suggest the following approach which is implemented without a global variable:

    C Source Code

    1. #include "DIALOG.h"
    2. #define APP_SET_VALUE (WM_USER + 0)
    3. /*********************************************************************
    4. *
    5. * _IntToStr
    6. */
    7. static void _IntToStr(char * pDest, int Value) {
    8. int TempVal;
    9. U8 NumDigits;
    10. NumDigits = 1;
    11. TempVal = Value;
    12. while (TempVal > 9) {
    13. NumDigits++;
    14. TempVal /= 10;
    15. }
    16. *(pDest + NumDigits) = '\0';
    17. while (NumDigits) {
    18. NumDigits--;
    19. *(pDest + NumDigits) = (Value % 10) + '0';
    20. Value /= 10;
    21. }
    22. }
    23. /*********************************************************************
    24. *
    25. * _cbProg
    26. */
    27. static void _cbProg(WM_MESSAGE * pMsg) {
    28. static char acText[10];
    29. GUI_RECT Rect;
    30. switch (pMsg->MsgId) {
    31. case APP_SET_VALUE:
    32. _IntToStr(acText, pMsg->Data.v);
    33. WM_InvalidateWindow(pMsg->hWin);
    34. break;
    35. case WM_PAINT:
    36. PROGBAR_Callback(pMsg);
    37. WM_GetWindowRectEx(pMsg->hWin, &Rect);
    38. Rect.x1 -= Rect.x0;
    39. Rect.y1 -= Rect.y0;
    40. Rect.x0 = 0;
    41. Rect.y0 = 0;
    42. GUI_SetColor(GUI_BLUE);
    43. GUI_SetTextMode(GUI_TM_TRANS);
    44. GUI_DispStringInRect(acText, &Rect, GUI_TA_VCENTER | GUI_TA_HCENTER);
    45. break;
    46. default:
    47. PROGBAR_Callback(pMsg);
    48. }
    49. }
    50. /*********************************************************************
    51. *
    52. * MainTask
    53. */
    54. void MainTask(void) {
    55. PROGBAR_Handle hProg;
    56. WM_MESSAGE Msg;
    57. int Min;
    58. int Max;
    59. int Value;
    60. Min = 0;
    61. Max = 100;
    62. Value = Min;
    63. GUI_Init();
    64. WM_SetDesktopColor(GUI_BLACK);
    65. hProg = PROGBAR_CreateEx(10, 10, 40, 100, WM_HBKWIN, WM_CF_SHOW, PROGBAR_CF_VERTICAL, 0);
    66. PROGBAR_SetMinMax(hProg, Min, Max);
    67. PROGBAR_SetBarColor(hProg, 0, GUI_WHITE);
    68. WM_SetCallback(hProg, _cbProg);
    69. while (1) {
    70. GUI_Delay(50);
    71. PROGBAR_SetValue(hProg, Value);
    72. Msg.Data.v = Value;
    73. Msg.hWin = hProg;
    74. Msg.hWinSrc = 0;
    75. Msg.MsgId = APP_SET_VALUE;
    76. WM_SendMessage(hProg, &Msg);
    77. Value++;
    78. if (Value > Max) {
    79. Value = Min;
    80. }
    81. }
    82. }
    Display All

    Best regards,
    Adrian