Skinning LISTVIEW HEADERs

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

    • Skinning LISTVIEW HEADERs

      Hello,

      My question is related to skinning of HEADER widgets. I've got a LISTVIEW which has a white background, created like this:

      C Source Code

      1. static void
      2. cbResultsListview (WM_MESSAGE * pMsg)
      3. {
      4. char ColumnName[COLUMN_NAME_MAX_LEN];
      5. switch (pMsg->MsgId)
      6. {
      7. case WM_CREATE:
      8. {
      9. HEADER_Handle hHeader;
      10. uint32_t XSize, YSize;
      11. int RowHeight;
      12. int ColWidth;
      13. lgListView = LISTVIEW_CreateAttached(pMsg->hWin,
      14. GUI_ID_LISTVIEW1,
      15. 0);
      16. WIDGET_SetEffect(lgListView, &WIDGET_Effect_None);
      17. LISTVIEW_SetAutoScrollV(lgListView, 1);
      18. LISTVIEW_SetGridVis(lgListView, 1);
      19. XSize = WM_GetWindowSizeX(pMsg->hWin);
      20. YSize = WM_GetWindowSizeY(pMsg->hWin);
      21. ColWidth = XSize / (PHOTOMETRY_MAX_SAMPLE_POINTS + 1);
      22. RowHeight = YSize / 8;
      23. LISTVIEW_AddColumn(lgListView,
      24. ColWidth,
      25. "SAMPLE #",
      26. GUI_TA_VCENTER | GUI_TA_HCENTER);
      27. for (uint8_t i = 1; i < PHOTOMETRY_MAX_SAMPLE_POINTS + 1; i++)
      28. {
      29. if (i <= gPhotometryScanParams.WLCount)
      30. {
      31. snprintf(ColumnName,
      32. COLUMN_NAME_MAX_LEN,
      33. "WL %d\n%.1f nm",
      34. i,
      35. gPhotometryScanParams.SampleWLs[i - 1]);
      36. }
      37. else
      38. {
      39. snprintf(ColumnName,
      40. COLUMN_NAME_MAX_LEN,
      41. "WL %d\n____",
      42. i);
      43. }
      44. LISTVIEW_AddColumn(lgListView,
      45. ColWidth,
      46. ColumnName,
      47. GUI_TA_VCENTER | GUI_TA_HCENTER);
      48. }
      49. hHeader = LISTVIEW_GetHeader(lgListView);
      50. HEADER_SetHeight(hHeader, RowHeight);
      51. //HEADER_SetFont(hHeader, GUI_FONT_16_ARIAL);
      52. HEADER_SetTextColor(hHeader, GUI_GRAY);
      53. HEADER_SetSkin(hHeader, TableOfResultsWhiteHeaderSkin);
      54. LISTVIEW_SetRowHeight(lgListView, RowHeight);
      55. break;
      56. }
      Display All




      The above code is setting the column header names as I'd like, however I'm unsure how to make this work when skinning the header. The skinning routine does this:


      C Source Code

      1. int
      2. TableOfResultsWhiteHeaderSkin (const WIDGET_ITEM_DRAW_INFO *pDrawItemInfo)
      3. {
      4. switch (pDrawItemInfo->Cmd)
      5. {
      6. case WIDGET_ITEM_DRAW_BACKGROUND:
      7. {
      8. GUI_SetBkColor(GUI_WHITE);
      9. GUI_Clear();
      10. break;
      11. }
      12. default:
      13. {
      14. break;
      15. }
      16. }
      17. return 0;
      18. }
      Display All






      So, what I'm trying to do is to have a white background header with my text on top for each column name. I would usually do this by implementing the WIDGET_ITEM_DRAW_TEXT case, however I don't know how to retrieve the previously set text here. I hope this makes some sense?


      I had hoped that simply setting HEADER_SetBkColor(hHeader, GUI_WHITE); would have done the trick but this seems to have no effect. I've also tried to change the SKINFLEX props (this almost works) but means there are some undesirable (for me) artefacts left over.


      So, the question really is how do I set the header item text fields from the skin callback?


      Cheers,
      Peter.
    • Hi,

      Please try the code below, I guess it does what you want.

      C Source Code

      1. #include "DIALOG.h"
      2. /*********************************************************************
      3. *
      4. * Externals
      5. *
      6. **********************************************************************
      7. */
      8. /*********************************************************************
      9. *
      10. * Defines
      11. *
      12. **********************************************************************
      13. */
      14. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
      15. #define ID_LISTVIEW_0 (GUI_ID_USER + 0x01)
      16. /*********************************************************************
      17. *
      18. * Static data
      19. *
      20. **********************************************************************
      21. */
      22. /*********************************************************************
      23. *
      24. * _aDialogCreate
      25. */
      26. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
      27. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 320, 240, 0, 0x0, 0 },
      28. { LISTVIEW_CreateIndirect, "Listview", ID_LISTVIEW_0, 60, 60, 180, 120, 0, 0x0, 0 },
      29. };
      30. /*********************************************************************
      31. *
      32. * Static code
      33. *
      34. **********************************************************************
      35. */
      36. /*********************************************************************
      37. *
      38. * _CustomSkin
      39. */
      40. static int _CustomSkin(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
      41. GUI_RECT Rect;
      42. char acBuffer[32];
      43. switch (pDrawItemInfo->Cmd) {
      44. case WIDGET_ITEM_DRAW_BACKGROUND:
      45. GUI_SetBkColor(GUI_WHITE);
      46. GUI_Clear();
      47. return 0;
      48. case WIDGET_ITEM_DRAW_TEXT:
      49. GUI_SetTextMode(GUI_TM_TRANS);
      50. GUI_SetColor(GUI_BLACK);
      51. HEADER_GetItemText(pDrawItemInfo->hWin, pDrawItemInfo->ItemIndex, acBuffer, sizeof(acBuffer));
      52. Rect.x0 = pDrawItemInfo->x0;
      53. Rect.y0 = pDrawItemInfo->y0;
      54. Rect.x1 = pDrawItemInfo->x1;
      55. Rect.y1 = pDrawItemInfo->y1;
      56. GUI_DispStringInRect(acBuffer, &Rect, GUI_TA_HCENTER | GUI_TA_VCENTER);
      57. return 0;
      58. default:
      59. return HEADER_DrawSkinFlex(pDrawItemInfo);
      60. }
      61. }
      62. /*********************************************************************
      63. *
      64. * _cbDialog
      65. */
      66. static void _cbDialog(WM_MESSAGE * pMsg) {
      67. WM_HWIN hItem;
      68. int NCode;
      69. int Id;
      70. switch (pMsg->MsgId) {
      71. case WM_INIT_DIALOG:
      72. //
      73. // Initialization of 'Listview'
      74. //
      75. hItem = WM_GetDialogItem(pMsg->hWin, ID_LISTVIEW_0);
      76. LISTVIEW_AddColumn(hItem, 60, "Col 0", GUI_TA_HCENTER | GUI_TA_VCENTER);
      77. LISTVIEW_AddColumn(hItem, 60, "Col 1", GUI_TA_HCENTER | GUI_TA_VCENTER);
      78. LISTVIEW_AddColumn(hItem, 60, "Col 2", GUI_TA_HCENTER | GUI_TA_VCENTER);
      79. LISTVIEW_AddRow(hItem, NULL);
      80. LISTVIEW_SetGridVis(hItem, 1);
      81. hItem = LISTVIEW_GetHeader(hItem);
      82. HEADER_SetSkin(hItem, _CustomSkin);
      83. break;
      84. default:
      85. WM_DefaultProc(pMsg);
      86. break;
      87. }
      88. }
      89. /*********************************************************************
      90. *
      91. * _cbBk
      92. */
      93. static void _cbBk(WM_MESSAGE * pMsg) {
      94. switch (pMsg->MsgId) {
      95. case WM_PAINT:
      96. GUI_SetBkColor(GUI_BLACK);
      97. GUI_Clear();
      98. break;
      99. default:
      100. WM_DefaultProc(pMsg);
      101. break;
      102. }
      103. }
      104. /*********************************************************************
      105. *
      106. * Public code
      107. *
      108. **********************************************************************
      109. */
      110. /*********************************************************************
      111. *
      112. * MainTask
      113. */
      114. void MainTask(void) {
      115. GUI_Init();
      116. WM_SetCallback(WM_HBKWIN, _cbBk);
      117. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
      118. while (1) {
      119. GUI_Delay(100);
      120. }
      121. }
      122. /*************************** 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 Sven,

      This is what I was looking for :) Unfortunately we are using stmewin and HEADER_GetItemText() is not yet available in their most recent version. I think it's time we ditched stemwin for emWin.

      Cheers,
      Peter.
    • Hi,

      good idea ;)

      As STemWin user you can buy the source code upgrade.

      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.