Round Editbox for displaying values

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

  • Round Editbox for displaying values

    Hi,

    I wanted to display values in Edit box which is round in shape. Currently the Edit Box is rectangle in shape.
    Can we do this using edit box or any other widget. I also want that widget to accepts events.

    Thanks and Regards

    Anuj
  • Hallo Anuj,

    Please note that a custom callback function (WM_SetCallback()) can be set for widgets.
    The callback function can be used to react to events.
    In the WM_PAINT event can be set a function to draw the edit box.
    Please also note that you have to set transparency for this widget (WM_SetHasTrans()).
    Detailed information can be found in the emWin user manual in section 17.2.3 Overwriting callback functions.

    Best regards,
    Thorsten
  • Hallo Anuj,

    I created a sample that overwrites the callback function of an EDIT widget.
    I have set the transparency property for the EDIT widget to draw a rounded edit box.

    C Source Code

    1. #include "EDIT.h"
    2. #define EDIT_MAX_LEN 60
    3. #define EDIT_ALIGN (GUI_TA_HCENTER | GUI_TA_VCENTER)
    4. #define RADIUS 10
    5. #define BORDER 4
    6. /*********************************************************************
    7. *
    8. * _OnPaint
    9. */
    10. static void _OnPaint(EDIT_Handle hEdit) {
    11. GUI_RECT Rect = {0};
    12. char acText[EDIT_MAX_LEN + 1];
    13. GUI_COLOR Color;
    14. const GUI_FONT * pFont;
    15. GUI_COLOR BkColor;
    16. int MaxLen;
    17. Rect.x1 = WM_GetWindowSizeX(hEdit) - 1;
    18. Rect.y1 = WM_GetWindowSizeY(hEdit) - 1;
    19. BkColor = EDIT_GetBkColor(hEdit, 0);
    20. GUI_SetColor(BkColor);
    21. GUI_FillRoundedRect(Rect.x0, Rect.y0, Rect.x1, Rect.y1, RADIUS);
    22. MaxLen = EDIT_GetNumChars(hEdit) + 1;
    23. if (MaxLen) {
    24. pFont = EDIT_GetFont(hEdit);
    25. EDIT_GetText(hEdit, acText, MaxLen);
    26. Color = EDIT_GetTextColor(hEdit, 0);
    27. GUI_SetColor(Color);
    28. GUI_SetBkColor(BkColor);
    29. Rect.x0 = BORDER;
    30. Rect.y0 = BORDER;
    31. Rect.x1 -= BORDER;
    32. Rect.y1 -= BORDER;
    33. GUI_SetFont(pFont);
    34. GUI_DispStringInRectWrap(acText, &Rect, EDIT_ALIGN, GUI_WRAPMODE_WORD);
    35. }
    36. }
    37. /*********************************************************************
    38. *
    39. * _cbEdit
    40. */
    41. static void _cbEdit(WM_MESSAGE * pMsg) {
    42. switch (pMsg->MsgId) {
    43. case WM_CREATE:
    44. EDIT_SetTextAlign(pMsg->hWin, EDIT_ALIGN);
    45. break;
    46. case WM_PAINT:
    47. _OnPaint(pMsg->hWin);
    48. break;
    49. default:
    50. EDIT_Callback(pMsg);
    51. break;
    52. }
    53. }
    54. /*********************************************************************
    55. *
    56. * MainTask
    57. */
    58. void MainTask(void) {
    59. WM_HWIN hWin;
    60. WM_SetCreateFlags(WM_CF_MEMDEV);
    61. GUI_Init();
    62. WM_SetDesktopColor(GUI_GRAY);
    63. hWin = EDIT_CreateAsChild(10, 10, 50, 40, WM_HBKWIN, 2, WM_CF_SHOW, EDIT_MAX_LEN);
    64. WM_SetHasTrans(hWin);
    65. WM_SetCallback(hWin, _cbEdit);
    66. while(1) {
    67. GUI_Delay(100);
    68. }
    69. }
    Display All


    Best regards,
    Thorsten