Round for LISTBOX Widget

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

  • Round for LISTBOX Widget

    I was wondering if there was a way to radius the corners of the listbox selection rectangle? If not, is the source code available for modification, since all we need would be to use the rounded rectangle function?

    Thank you very much!
  • Thank you, I'm trying to read through and understand the layers. Would you be able to provide a simple example of how to simply change the listbox rectangle to be a round rectangle (most likely a fill).

    Thanks for the support.
  • Sorry for bringing this back up, but I am just getting back to this since I had no luck before. I previously looked through the WIDGET_ListBoxOwnerDraw.c example and seems a bit more complex than the solution I am trying to create. Can anyone provide an example of taking an existing LISTBOX and only adding the ability to use a rounded rectangle as the selection box, instead of a regular rectangle (sharp corners)?

    Thank you
  • Just wanted to give an updated and marked this as solved. I was finally able to piece everything together and this was my solution, modifying the WIDGET_ListOwnerDraw.c file:

    C Source Code

    1. #include "main.h"
    2. /*********************************************************************
    3. *
    4. * _GetItemSizeX
    5. */
    6. static int _GetItemSizeX(WM_HWIN hWin, int ItemIndex) {
    7. char acBuffer[100];
    8. int DistX;
    9. LISTBOX_GetItemText(hWin, ItemIndex, acBuffer, sizeof(acBuffer));
    10. DistX = GUI_GetStringDistX(acBuffer);
    11. return DistX + 16;
    12. }
    13. /*********************************************************************
    14. *
    15. * _GetItemSizeY
    16. */
    17. static int _GetItemSizeY(WM_HWIN hWin, int ItemIndex) {
    18. int DistY;
    19. DistY = GUI_GetFontDistY();
    20. return DistY;
    21. }
    22. /*********************************************************************
    23. *
    24. * _OwnerDraw
    25. *
    26. * Function description
    27. * This is the owner draw function.
    28. * It allows complete customization of how the items in the listbox are
    29. * drawn. A command specifies what the function should do;
    30. * The minimum is to react to the draw command (WIDGET_ITEM_DRAW);
    31. * If the item x-size differs from the default, then this information
    32. * needs to be returned in reaction to WIDGET_ITEM_GET_XSIZE.
    33. * To insure compatibility with future version, all unhandled commands
    34. * must call the default routine LISTBOX_OwnerDraw.
    35. */
    36. // Refer to page 598 in Manual
    37. int drawRoundedListBox(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
    38. WM_HWIN hWin;
    39. int Index;
    40. hWin = pDrawItemInfo->hWin;
    41. Index = pDrawItemInfo->ItemIndex;
    42. switch (pDrawItemInfo->Cmd) {
    43. case WIDGET_ITEM_GET_XSIZE:
    44. return _GetItemSizeX(hWin, Index);
    45. case WIDGET_ITEM_GET_YSIZE:
    46. return _GetItemSizeY(hWin, Index);
    47. case WIDGET_ITEM_DRAW:
    48. {
    49. int Sel;
    50. int YSize;
    51. int FontDistX;
    52. int FontDistY;
    53. int YOffset;
    54. char acBuffer[100];
    55. GUI_RECT rFocus;
    56. GUI_RECT rInside;
    57. Sel = LISTBOX_GetSel(hWin);
    58. GUI_SetBkColor(GUI_BLACK);
    59. GUI_SetColor(GUI_WHITE);
    60. YSize = _GetItemSizeY(hWin, Index);
    61. YOffset = 3;
    62. WM_GetInsideRectEx(pDrawItemInfo->hWin, &rInside);
    63. rFocus.x0 = pDrawItemInfo->x0;
    64. rFocus.y0 = pDrawItemInfo->y0 + YOffset;
    65. rFocus.x1 = rInside.x1;
    66. rFocus.y1 = pDrawItemInfo->y0 + YSize - YOffset;
    67. LISTBOX_GetItemText(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex, acBuffer, sizeof(acBuffer));
    68. GUI_Clear();
    69. // Draw focus rectangle if item is selected
    70. if ((pDrawItemInfo->ItemIndex == Sel)) {
    71. rFocus.y0-=3;
    72. rFocus.y1-=1;
    73. GUI_SetColor(GUI_GREEN);
    74. // Refer to page 948 of Manual
    75. GUI_AA_FillRoundedRectEx(&rFocus, (int)floor((rFocus.y1 - rFocus.y0)/2));
    76. GUI_SetTextMode(GUI_TEXTMODE_TRANS);
    77. GUI_SetBkColor(GUI_TRANSPARENT);
    78. GUI_SetColor(GUI_BLACK);
    79. FontDistY = GUI_GetFontDistY();
    80. FontDistX = GUI_GetStringDistX(acBuffer);
    81. // Center text
    82. GUI_DispStringAt(acBuffer, pDrawItemInfo->x0 + (pDrawItemInfo->x0 + rFocus.x1)/2 - (FontDistX/2), pDrawItemInfo->y0 + ((YSize - FontDistY) / 2) - YOffset);
    83. }
    84. else {
    85. YSize = YSize - 8;
    86. GUI_SetBkColor(GUI_BLACK);
    87. GUI_SetColor(GUI_WHITE);
    88. FontDistY = GUI_GetFontDistY();
    89. FontDistX = GUI_GetStringDistX(acBuffer);
    90. GUI_DispStringAt(acBuffer, pDrawItemInfo->x0 + (pDrawItemInfo->x0 + rFocus.x1)/2 - (FontDistX/2), pDrawItemInfo->y0 + ((YSize - FontDistY) / 2));
    91. GUI_DispCEOL();
    92. }
    93. }
    94. break;
    95. default:
    96. return LISTBOX_OwnerDraw(pDrawItemInfo);
    97. }
    98. return 0;
    99. }
    Display All


    In case it is useful to anyone, then just call

    C Source Code

    1. LISTBOX_SetOwnerDraw(hListBox, drawRoundedListBox);


    after you have created your listbox.