How to add Radio buttons in owner draw ListBox ?

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

  • Hi amit,

    this wouldn't be easy. But how about the swipelist widget?

    There you can attach widgets/windows to the items of the swipelist.

    Here is an example where I have attached a radio widget to the first subitem and a checkbox to the second one. I played around with owner draw, thats why it looks strange (maybe). But it should show how it works.

    C Source Code

    1. /*********************************************************************
    2. * SEGGER MICROCONTROLLER SYSTEME GmbH *
    3. * Solutions for real time microcontroller applications *
    4. **********************************************************************
    5. * *
    6. * 2016 SEGGER Microcontroller Systeme GmbH *
    7. * *
    8. * Internet: www.segger.com Support: support@segger.com *
    9. * *
    10. **********************************************************************
    11. ----------------------------------------------------------------------
    12. File : GUIDRV_Lin.h
    13. Purpose : Interface definition for GUIDRV_Lin driver
    14. ---------------------------END-OF-HEADER------------------------------
    15. */
    16. #include <stdio.h>
    17. #include "DIALOG.h"
    18. /*********************************************************************
    19. *
    20. * Defines
    21. *
    22. **********************************************************************
    23. */
    24. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
    25. #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
    26. /*********************************************************************
    27. *
    28. * Static data
    29. *
    30. **********************************************************************
    31. */
    32. /*********************************************************************
    33. *
    34. * _aDialogCreate
    35. */
    36. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    37. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
    38. { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
    39. };
    40. /*********************************************************************
    41. *
    42. * Static code
    43. *
    44. **********************************************************************
    45. */
    46. /*********************************************************************
    47. *
    48. * _SwipeOwnerDraw
    49. */
    50. static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
    51. //
    52. // Distinguish between different commands
    53. //
    54. switch (pDrawItemInfo->Cmd) {
    55. case WIDGET_ITEM_DRAW_SEP:
    56. GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
    57. GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
    58. break;
    59. case WIDGET_ITEM_DRAW_TEXT:
    60. //
    61. // Just set a text mode but let the default owner draw routine handle the rest
    62. //
    63. GUI_SetTextMode(GUI_TM_TRANS);
    64. SWIPELIST_OwnerDraw(pDrawItemInfo);
    65. break;
    66. case WIDGET_ITEM_DRAW_BITMAP:
    67. break;
    68. case WIDGET_ITEM_DRAW_BACKGROUND:
    69. //
    70. // Handle drawing of the background of the items
    71. //
    72. switch (pDrawItemInfo->ItemIndex) {
    73. case 0: // 1st separator
    74. case 5: // 2nd separator
    75. case 10: // 3rd separator
    76. case 15: // 4th separator
    77. GUI_SetColor(GUI_BLACK);
    78. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    79. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
    80. GUI_SetColor(GUI_LIGHTGRAY);
    81. GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
    82. return 0;
    83. default: // Any other item
    84. //
    85. // Determin if the item to drawn is the currently selected
    86. //
    87. if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
    88. //
    89. // Draw the selected one different
    90. //
    91. GUI_SetColor(GUI_DARKRED);
    92. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    93. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
    94. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
    95. } else {
    96. //
    97. // Draw any other items this way
    98. //
    99. GUI_SetColor(GUI_DARKGRAY);
    100. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    101. }
    102. }
    103. break;
    104. default:
    105. //
    106. // Anything we do not catch in this routine gets handled by the default owner draw
    107. //
    108. return SWIPELIST_OwnerDraw(pDrawItemInfo);
    109. }
    110. return 0;
    111. }
    112. /*********************************************************************
    113. *
    114. * _cbDialog
    115. */
    116. static void _cbDialog(WM_MESSAGE * pMsg) {
    117. WM_HWIN hItem;
    118. GUI_RECT Rect;
    119. int NCode;
    120. int Id;
    121. char aText[30];
    122. int i;
    123. int j;
    124. int Item;
    125. static int ItemIndex = 0;
    126. static GUI_RECT TRect;
    127. WM_HWIN hAttachItem;
    128. switch (pMsg->MsgId) {
    129. case WM_INIT_DIALOG:
    130. //
    131. // Init SWIPELIST
    132. //
    133. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    134. //
    135. // Four separator
    136. //
    137. Item = 1;
    138. for (j = 0; j < 4; j++) {
    139. sprintf(aText, "Separator %i", j);
    140. SWIPELIST_AddSepItem(hItem, aText, 30);
    141. //
    142. // Four subitems for each separator
    143. //
    144. for (i = 0; i < 4; i++) {
    145. sprintf(aText, "Item %i", j + Item++);
    146. SWIPELIST_AddItem(hItem, aText, 60);
    147. }
    148. }
    149. hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, 0, 3, 15);
    150. SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
    151. hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, 0);
    152. SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
    153. //
    154. // Set an owner draw function
    155. //
    156. SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
    157. //
    158. // Set Text rect
    159. //
    160. TRect.x0 = LCD_GetXSize() / 2;
    161. TRect.y0 = 0;
    162. TRect.x1 = LCD_GetXSize();
    163. TRect.y1 = LCD_GetYSize();
    164. break;
    165. case WM_PAINT:
    166. //
    167. // Draw the background of the dialog window
    168. //
    169. WM_GetClientRect(&Rect);
    170. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
    171. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    172. //
    173. // Draw a frame around the SWIPELIST
    174. //
    175. WM_GetWindowRectEx(hItem, &Rect);
    176. Rect.x0 -= 1;
    177. Rect.y0 -= 1;
    178. Rect.x1 += 1;
    179. Rect.y1 += 1;
    180. GUI_SetColor(GUI_LIGHTGRAY);
    181. GUI_DrawRectEx(&Rect);
    182. if (ItemIndex) {
    183. sprintf(aText, "Item %i selected", ItemIndex); // build a string
    184. } else {
    185. sprintf(aText, "no item selected"); // build a string
    186. }
    187. GUI_SetTextMode(GUI_TM_TRANS);
    188. GUI_SetFont(GUI_FONT_24B_1);
    189. GUI_SetColor(GUI_WHITE);
    190. GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
    191. break;
    192. case WM_NOTIFY_PARENT:
    193. //
    194. // Get Id of the child got something
    195. //
    196. Id = WM_GetId(pMsg->hWinSrc);
    197. //
    198. // Get an idea of what it got
    199. //
    200. NCode = pMsg->Data.v;
    201. switch(Id) {
    202. //
    203. // Which child
    204. //
    205. case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
    206. switch(NCode) {
    207. //
    208. // got what
    209. //
    210. case WM_NOTIFICATION_CLICKED:
    211. break;
    212. case WM_NOTIFICATION_RELEASED:
    213. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    214. ItemIndex = SWIPELIST_GetReleasedItem(hItem);
    215. WM_InvalidateRect(pMsg->hWin, &TRect);
    216. break;
    217. }
    218. break;
    219. }
    220. break;
    221. default:
    222. WM_DefaultProc(pMsg);
    223. break;
    224. }
    225. }
    226. /*********************************************************************
    227. *
    228. * Public code
    229. *
    230. **********************************************************************
    231. */
    232. /*********************************************************************
    233. *
    234. * MainTask
    235. */
    236. void MainTask(void) {
    237. WM_SetCreateFlags(WM_CF_MEMDEV);
    238. GUI_Init();
    239. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    240. while (1) {
    241. GUI_Delay(100);
    242. }
    243. }
    244. /*************************** End of file ****************************/
    Display All


    I hope this helps.

    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.
  • Hi Schoenen,
    aha!! Its, looks awesome actually.. Thank you.. One problem, i ported the code given by you on our hardware. But I'm not able to scroll on swipe list. What additional changes i have to make so that i would be able to scroll ?
  • Hi,

    I'm sorry I forgott to enable motion support and enable motion in y direction for the swipelist. I have created the sample with slightly different sources of emWin :whistling:

    This should work:

    C Source Code

    1. /*********************************************************************
    2. * SEGGER MICROCONTROLLER SYSTEME GmbH *
    3. * Solutions for real time microcontroller applications *
    4. **********************************************************************
    5. * *
    6. * 2016 SEGGER Microcontroller Systeme GmbH *
    7. * *
    8. * Internet: www.segger.com Support: support@segger.com *
    9. * *
    10. **********************************************************************
    11. ----------------------------------------------------------------------
    12. File : GUIDRV_Lin.h
    13. Purpose : Interface definition for GUIDRV_Lin driver
    14. ---------------------------END-OF-HEADER------------------------------
    15. */
    16. #include <stdio.h>
    17. #include "DIALOG.h"
    18. #include "SWIPELIST.h"
    19. /*********************************************************************
    20. *
    21. * Defines
    22. *
    23. **********************************************************************
    24. */
    25. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
    26. #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
    27. /*********************************************************************
    28. *
    29. * Static data
    30. *
    31. **********************************************************************
    32. */
    33. /*********************************************************************
    34. *
    35. * _aDialogCreate
    36. */
    37. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    38. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
    39. { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
    40. };
    41. /*********************************************************************
    42. *
    43. * Static code
    44. *
    45. **********************************************************************
    46. */
    47. /*********************************************************************
    48. *
    49. * _SwipeOwnerDraw
    50. */
    51. static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
    52. //
    53. // Distinguish between different commands
    54. //
    55. switch (pDrawItemInfo->Cmd) {
    56. case WIDGET_ITEM_DRAW_SEP:
    57. GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
    58. GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
    59. break;
    60. case WIDGET_ITEM_DRAW_TEXT:
    61. //
    62. // Just set a text mode but let the default owner draw routine handle the rest
    63. //
    64. GUI_SetTextMode(GUI_TM_TRANS);
    65. SWIPELIST_OwnerDraw(pDrawItemInfo);
    66. break;
    67. case WIDGET_ITEM_DRAW_BITMAP:
    68. break;
    69. case WIDGET_ITEM_DRAW_BACKGROUND:
    70. //
    71. // Handle drawing of the background of the items
    72. //
    73. switch (pDrawItemInfo->ItemIndex) {
    74. case 0: // 1st separator
    75. case 5: // 2nd separator
    76. case 10: // 3rd separator
    77. case 15: // 4th separator
    78. GUI_SetColor(GUI_BLACK);
    79. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    80. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
    81. GUI_SetColor(GUI_LIGHTGRAY);
    82. GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
    83. return 0;
    84. default: // Any other item
    85. //
    86. // Determin if the item to drawn is the currently selected
    87. //
    88. if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
    89. //
    90. // Draw the selected one different
    91. //
    92. GUI_SetColor(GUI_DARKRED);
    93. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    94. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
    95. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
    96. } else {
    97. //
    98. // Draw any other items this way
    99. //
    100. GUI_SetColor(GUI_DARKGRAY);
    101. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    102. }
    103. }
    104. break;
    105. default:
    106. //
    107. // Anything we do not catch in this routine gets handled by the default owner draw
    108. //
    109. return SWIPELIST_OwnerDraw(pDrawItemInfo);
    110. }
    111. return 0;
    112. }
    113. /*********************************************************************
    114. *
    115. * _cbDialog
    116. */
    117. static void _cbDialog(WM_MESSAGE * pMsg) {
    118. WM_HWIN hItem;
    119. GUI_RECT Rect;
    120. int NCode;
    121. int Id;
    122. char aText[30];
    123. int i;
    124. int j;
    125. int Item;
    126. static int ItemIndex = 0;
    127. static GUI_RECT TRect;
    128. WM_HWIN hAttachItem;
    129. switch (pMsg->MsgId) {
    130. case WM_INIT_DIALOG:
    131. //
    132. // Init SWIPELIST
    133. //
    134. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    135. WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
    136. //
    137. // Four separator
    138. //
    139. Item = 1;
    140. for (j = 0; j < 4; j++) {
    141. sprintf(aText, "Separator %i", j);
    142. SWIPELIST_AddSepItem(hItem, aText, 30);
    143. //
    144. // Four subitems for each separator
    145. //
    146. for (i = 0; i < 4; i++) {
    147. sprintf(aText, "Item %i", j + Item++);
    148. SWIPELIST_AddItem(hItem, aText, 60);
    149. }
    150. }
    151. hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, 0, 3, 15);
    152. SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
    153. hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, 0);
    154. SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
    155. //
    156. // Set an owner draw function
    157. //
    158. SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
    159. //
    160. // Set Text rect
    161. //
    162. TRect.x0 = LCD_GetXSize() / 2;
    163. TRect.y0 = 0;
    164. TRect.x1 = LCD_GetXSize();
    165. TRect.y1 = LCD_GetYSize();
    166. break;
    167. case WM_PAINT:
    168. //
    169. // Draw the background of the dialog window
    170. //
    171. WM_GetClientRect(&Rect);
    172. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
    173. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    174. //
    175. // Draw a frame around the SWIPELIST
    176. //
    177. WM_GetWindowRectEx(hItem, &Rect);
    178. Rect.x0 -= 1;
    179. Rect.y0 -= 1;
    180. Rect.x1 += 1;
    181. Rect.y1 += 1;
    182. GUI_SetColor(GUI_LIGHTGRAY);
    183. GUI_DrawRectEx(&Rect);
    184. if (ItemIndex) {
    185. sprintf(aText, "Item %i selected", ItemIndex); // build a string
    186. } else {
    187. sprintf(aText, "no item selected"); // build a string
    188. }
    189. GUI_SetTextMode(GUI_TM_TRANS);
    190. GUI_SetFont(GUI_FONT_24B_1);
    191. GUI_SetColor(GUI_WHITE);
    192. GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
    193. break;
    194. case WM_NOTIFY_PARENT:
    195. //
    196. // Get Id of the child got something
    197. //
    198. Id = WM_GetId(pMsg->hWinSrc);
    199. //
    200. // Get an idea of what it got
    201. //
    202. NCode = pMsg->Data.v;
    203. switch(Id) {
    204. //
    205. // Which child
    206. //
    207. case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
    208. switch(NCode) {
    209. //
    210. // got what
    211. //
    212. case WM_NOTIFICATION_CLICKED:
    213. break;
    214. case WM_NOTIFICATION_RELEASED:
    215. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    216. ItemIndex = SWIPELIST_GetReleasedItem(hItem);
    217. WM_InvalidateRect(pMsg->hWin, &TRect);
    218. break;
    219. }
    220. break;
    221. }
    222. break;
    223. default:
    224. WM_DefaultProc(pMsg);
    225. break;
    226. }
    227. }
    228. /*********************************************************************
    229. *
    230. * Public code
    231. *
    232. **********************************************************************
    233. */
    234. /*********************************************************************
    235. *
    236. * MainTask
    237. */
    238. void MainTask(void) {
    239. WM_SetCreateFlags(WM_CF_MEMDEV);
    240. GUI_Init();
    241. WM_MOTION_Enable(1);
    242. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    243. while (1) {
    244. GUI_Delay(100);
    245. }
    246. }
    247. /*************************** 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.
  • Hi Sven, I found that Swipe for the swipelist is not working on our STM32F4 hardware. We are able to detect touch using our touch driver. Touch is working perfectly for all other items. This code is working well in Simulator. Please provide me some pointers so that this code will also work on our hardware.
  • Hi Sven,


    The code snippet shared by you is perfectly attaching 3 radio buttons to ITEM 1.Thanks for that.
    Now How can i attach one radio button to each separate Item ? i.e. 1st radio button for item 1, 2nd for Item 2 and so on.
    I did not find any API for it.


    It would be grateful if you share some code snippet.


    Thank you :)
  • Hello Amit,

    to attache a widget to an item of the SWIPELIST widget just call SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5).

    The second paramter describes to which item the widget should be attached. With the function above you would attache it to item 1.

    Regarding the SWIPELIST on your hardware, I can't say why this is not working. I checked it on this eval board and this project and it worked without any issues.

    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.
  • Hello,
    I've been learning from your exemple and I was trying to acces the Radio Button values or the checkbox status .
    I think I am not using the WM_NOTIFICATION_XXXX properly with the radiobutton when its value is changed in _cbDialog callback , but I don't get how do you grab the value of a radiobutton other than with RADIO_GetValue() function. In the DIALOG_Radio.c exemple, the radio's value is grab through the text being focus or not, instead of the radiobutton changing value.
    Is it because I am not accessing the radiobuton in the callback ? or is because it's a subitem of Swipelist and the callback method I'm trying to use is wrong ?

    How would you grab the information of the radiobuttons in your exemple ?
    The code is your exemple with the radiobutton modified to open new windows (1/2/3) with background color changed; swipelist subitem 2,3 and 4 destroys the windows.
    (I am working on a 800x480 screen , so the windows might be out of bound )

    Edit: I had to cut the code since it's over 10 000 chars... so no window 2 and 3 , and only swipelist 2 destroy the window


    C Source Code

    1. #include <stdio.h>
    2. #include "RADIO.h"
    3. #include "DIALOG.h"
    4. #include "SWIPELIST.h"
    5. /*
    6. Defines
    7. */
    8. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
    9. #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
    10. #define ID_RADIO_0 (GUI_ID_USER + 0x02)
    11.  
    12. static WM_HWIN _hWindow1;
    13.  
    14.  
    15. static GUI_COLOR _FrameColor1 = GUI_BLUE;
    16. /*
    17. Static data
    18. */
    19. /*
    20. _aDialogCreate
    21. */
    22. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    23. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
    24. { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 400, 440, 0, 0x0, 0 },
    25. };
    26. /*
    27. Static code
    28. */
    29. /*
    30. _cbWindow1
    31. */
    32. static void _cbWindow1(WM_MESSAGE * pMsg) {
    33. GUI_RECT Rect;
    34. int x;
    35. int y;
    36. switch (pMsg->MsgId) {
    37. case WM_PAINT:
    38. WM_GetInsideRect(&Rect);
    39. GUI_SetBkColor(GUI_RED);
    40. GUI_SetColor(_FrameColor1);
    41. GUI_ClearRectEx(&Rect);
    42. GUI_DrawRectEx(&Rect);
    43. GUI_SetColor(GUI_WHITE);
    44. GUI_SetFont(&GUI_Font24_ASCII);
    45. x = WM_GetWindowSizeX(pMsg->hWin);
    46. y = WM_GetWindowSizeY(pMsg->hWin);
    47. GUI_DispStringHCenterAt("Window 1", x / 2, (y / 2) - 12);
    48. break;
    49. default:
    50. WM_DefaultProc(pMsg);
    51. }
    52. }
    53. /*
    54. _SwipeOwnerDraw
    55. */
    56. static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
    57. //
    58. // Distinguish between different commands
    59. //
    60. switch (pDrawItemInfo->Cmd) {
    61. case WIDGET_ITEM_DRAW_SEP:
    62. GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
    63. GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
    64. break;
    65. case WIDGET_ITEM_DRAW_TEXT:
    66. //
    67. // Just set a text mode but let the default owner draw routine handle the rest
    68. //
    69. GUI_SetTextMode(GUI_TM_TRANS);
    70. SWIPELIST_OwnerDraw(pDrawItemInfo);
    71. break;
    72. case WIDGET_ITEM_DRAW_BITMAP:
    73. break;
    74. case WIDGET_ITEM_DRAW_BACKGROUND:
    75. //
    76. // Handle drawing of the background of the items
    77. //
    78. switch (pDrawItemInfo->ItemIndex) {
    79. case 0: // 1st separator
    80. case 5: // 2nd separator
    81. case 10: // 3rd separator
    82. case 15: // 4th separator
    83. GUI_SetColor(GUI_BLACK);
    84. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    85. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
    86. GUI_SetColor(GUI_LIGHTGRAY);
    87. GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
    88. return 0;
    89. default: // Any other item
    90. //
    91. // Determin if the item to drawn is the currently selected
    92. //
    93. if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
    94. //
    95. // Draw the selected one different
    96. //
    97. GUI_SetColor(GUI_DARKRED);
    98. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    99. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
    100. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
    101. } else {
    102. //
    103. // Draw any other items this way
    104. //
    105. GUI_SetColor(GUI_DARKGRAY);
    106. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    107. }
    108. }
    109. break;
    110. default:
    111. //
    112. // Anything we do not catch in this routine gets handled by the default owner draw
    113. //
    114. return SWIPELIST_OwnerDraw(pDrawItemInfo);
    115. }
    116. return 0;
    117. }
    118. /*
    119. _cbDialog
    120. */
    121. static void _cbDialog(WM_MESSAGE * pMsg) {
    122. WM_HWIN hItem;
    123. GUI_RECT Rect;
    124. int NCode;
    125. int Id;
    126. char aText[30];
    127. int i;
    128. int j;
    129. int Item;
    130. static int ItemIndex = 0;
    131. static int RadioValue = 0;
    132. static GUI_RECT TRect;
    133. WM_HWIN hAttachItem;
    134. switch (pMsg->MsgId) {
    135. case WM_INIT_DIALOG:
    136. //
    137. // Init SWIPELIST
    138. //
    139. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    140. WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
    141. //
    142. // Four separator
    143. //
    144. Item = 1;
    145. for (j = 0; j < 4; j++) {
    146. sprintf(aText, "Separator %i", j);
    147. SWIPELIST_AddSepItem(hItem, aText, 30);
    148. //
    149. // Four subitems for each separator
    150. //
    151. for (i = 0; i < 4; i++) {
    152. sprintf(aText, "Item %i", j + Item++);
    153. SWIPELIST_AddItem(hItem, aText, 60);
    154. }
    155. }
    156. hAttachItem = RADIO_CreateEx(0, 0, 60, 50, pMsg->hWin, WM_CF_SHOW, 0, ID_RADIO_0, 3, 15);
    157. RADIO_SetTextColor(hAttachItem,GUI_WHITE);
    158. RADIO_SetText(hAttachItem, "Red",0);
    159. RADIO_SetText(hAttachItem, "Blue",1);
    160. RADIO_SetText(hAttachItem, "Green",2);
    161. SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 40, 50);
    162. //
    163. // Set an owner draw function
    164. //
    165. SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
    166. //
    167. // Set Text rect
    168. //
    169. TRect.x0 = LCD_GetXSize() / 2;
    170. TRect.y0 = 0;
    171. TRect.x1 = LCD_GetXSize();
    172. TRect.y1 = LCD_GetYSize();
    173. break;
    174. case WM_PAINT:
    175. //
    176. // Draw the background of the dialog window
    177. //
    178. WM_GetClientRect(&Rect);
    179. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
    180. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    181. //
    182. // Draw a frame around the SWIPELIST
    183. //
    184. WM_GetWindowRectEx(hItem, &Rect);
    185. Rect.x0 -= 1;
    186. Rect.y0 -= 1;
    187. Rect.x1 += 1;
    188. Rect.y1 += 1;
    189. GUI_SetColor(GUI_LIGHTGRAY);
    190. GUI_DrawRectEx(&Rect);
    191. if (ItemIndex) {
    192. sprintf(aText, "Item %i selected", ItemIndex); // build a string
    193. } else {
    194. sprintf(aText, "no item selected"); // build a string
    195. }
    196. GUI_SetTextMode(GUI_TM_TRANS);
    197. GUI_SetFont(GUI_FONT_24B_1);
    198. GUI_SetColor(GUI_WHITE);
    199. GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
    200. break;
    201. case WM_TOUCH_CHILD:
    202. break;
    203. case WM_NOTIFY_PARENT:
    204. //
    205. // Get Id of the child got something
    206. //
    207. Id = WM_GetId(pMsg->hWinSrc);
    208. //
    209. // Get an idea of what it got
    210. //
    211. NCode = pMsg->Data.v;
    212. switch(Id) {
    213. //
    214. // Which child
    215. //
    216. case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
    217. switch(NCode) {
    218. //
    219. // got what
    220. //
    221. case WM_NOTIFICATION_CLICKED:
    222. break;
    223. case WM_NOTIFICATION_RELEASED:
    224. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    225. ItemIndex = SWIPELIST_GetReleasedItem(hItem);
    226.  
    227. switch(ItemIndex){
    228. case 1:
    229. break;
    230. case 2 :
    231. WM_DeleteWindow(_hWindow1);
    232. break;
    233. }
    234. WM_InvalidateRect(pMsg->hWin, &TRect);
    235. break;
    236. }
    237. break;
    238. case ID_RADIO_0: // Notifications sent by 'Radio'
    239. switch(NCode) {
    240.  
    241. case WM_NOTIFICATION_VALUE_CHANGED:
    242. // USER START (Optionally insert code for reacting on notification message)
    243. hItem= WM_GetDialogItem(pMsg->hWin,ID_RADIO_0);
    244. RadioValue=RADIO_GetValue(hItem);
    245. switch(RadioValue){
    246. case 0:
    247. _hWindow1 = WM_CreateWindow( 500, 5, 400, 460, WM_CF_SHOW | WM_CF_MEMDEV, _cbWindow1, 0);
    248. break;
    249. }
    250. // USER END
    251. break;
    252. // USER START (Optionally insert additional code for further notification handling)
    253. // USER END
    254. }
    255. break;
    256. }
    257. break;
    258. default:
    259. WM_DefaultProc(pMsg);
    260. break;
    261. }
    262. }
    263.  
    264.  
    265. void MainTask(void) {
    266. WM_SetCreateFlags(WM_CF_MEMDEV);
    267. WM_EnableMemdev(WM_HBKWIN);
    268. GUI_Init();
    269. WM_MOTION_Enable(1);
    270. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    271. while (1) {
    272. GUI_Delay(100);
    273. }
    274. }
    Display All

    The post was edited 2 times, last by Schrödinger ().

  • Hi Schrödinger,

    To get the values of the a widget which is attached to SWIPELIST you can proceed in the same way as getting a state from the SWIPELIST.

    The CHECKBOX and the RADIO widgets are child windows of the SWIPELIST. So the easiest way is to set a callback for the SWIPELIST and catch the WM_NOTIFY_PARENT message comming from its childs.

    First, add a callback for the SWIPELIST:

    C Source Code

    1. /*********************************************************************
    2. *
    3. * _cbSwipe
    4. */
    5. static void _cbSwipe(WM_MESSAGE * pMsg) {
    6. int NCode;
    7. int Id;
    8. WM_HWIN hItem;
    9. int Value;
    10. switch (pMsg->MsgId) {
    11. case WM_NOTIFY_PARENT:
    12. //
    13. // Get Id of the child got something
    14. //
    15. Id = WM_GetId(pMsg->hWinSrc);
    16. //
    17. // Get an idea of what it got
    18. //
    19. NCode = pMsg->Data.v;
    20. switch(Id) {
    21. case ID_RADIO_0: // Notifications sent by the RADIO widget
    22. switch(NCode) {
    23. case WM_NOTIFICATION_VALUE_CHANGED:
    24. hItem = WM_GetDialogItem(pMsg->hWin, ID_RADIO_0);
    25. Value = RADIO_GetValue(hItem);
    26. break;
    27. }
    28. break;
    29. case ID_CHECK_0: // Notifications sent by CHECKBOX widget
    30. switch(NCode) {
    31. case WM_NOTIFICATION_VALUE_CHANGED:
    32. hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECK_0);
    33. Value = CHECKBOX_GetState(hItem);
    34. break;
    35. }
    36. break;
    37. }
    38. break;
    39. default:
    40. SWIPELIST_Callback(pMsg);
    41. break;
    42. }
    43. }
    Display All


    After that set the callback for the SWIPELIST. This is done in _cbDialog() under the WM_INIT_DIALOG case right after we receive the SWIPELIST handle:

    C Source Code

    1. case WM_INIT_DIALOG:
    2. //
    3. // Init SWIPELIST
    4. //
    5. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    6. WM_SetCallback(hItem, _cbSwipe);


    Thats all. In _cbSwipe() we react on the different widgets and get their values.

    The final application would look like this:

    C Source Code

    1. #include <stdio.h>
    2. #include "DIALOG.h"
    3. #include "SWIPELIST.h"
    4. /*********************************************************************
    5. *
    6. * Defines
    7. *
    8. **********************************************************************
    9. */
    10. #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
    11. #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
    12. #define ID_RADIO_0 (GUI_ID_USER + 0x02)
    13. #define ID_CHECK_0 (GUI_ID_USER + 0x03)
    14. /*********************************************************************
    15. *
    16. * Static data
    17. *
    18. **********************************************************************
    19. */
    20. /*********************************************************************
    21. *
    22. * _aDialogCreate
    23. */
    24. static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
    25. { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
    26. { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
    27. };
    28. /*********************************************************************
    29. *
    30. * Static code
    31. *
    32. **********************************************************************
    33. */
    34. /*********************************************************************
    35. *
    36. * _SwipeOwnerDraw
    37. */
    38. static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
    39. //
    40. // Distinguish between different commands
    41. //
    42. switch (pDrawItemInfo->Cmd) {
    43. case WIDGET_ITEM_DRAW_SEP:
    44. GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
    45. GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
    46. break;
    47. case WIDGET_ITEM_DRAW_TEXT:
    48. //
    49. // Just set a text mode but let the default owner draw routine handle the rest
    50. //
    51. GUI_SetTextMode(GUI_TM_TRANS);
    52. SWIPELIST_OwnerDraw(pDrawItemInfo);
    53. break;
    54. case WIDGET_ITEM_DRAW_BITMAP:
    55. break;
    56. case WIDGET_ITEM_DRAW_BACKGROUND:
    57. //
    58. // Handle drawing of the background of the items
    59. //
    60. switch (pDrawItemInfo->ItemIndex) {
    61. case 0: // 1st separator
    62. case 5: // 2nd separator
    63. case 10: // 3rd separator
    64. case 15: // 4th separator
    65. GUI_SetColor(GUI_BLACK);
    66. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    67. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
    68. GUI_SetColor(GUI_LIGHTGRAY);
    69. GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
    70. return 0;
    71. default: // Any other item
    72. //
    73. // Determin if the item to drawn is the currently selected
    74. //
    75. if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
    76. //
    77. // Draw the selected one different
    78. //
    79. GUI_SetColor(GUI_DARKRED);
    80. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    81. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
    82. GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
    83. } else {
    84. //
    85. // Draw any other items this way
    86. //
    87. GUI_SetColor(GUI_DARKGRAY);
    88. GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
    89. }
    90. }
    91. break;
    92. default:
    93. //
    94. // Anything we do not catch in this routine gets handled by the default owner draw
    95. //
    96. return SWIPELIST_OwnerDraw(pDrawItemInfo);
    97. }
    98. return 0;
    99. }
    100. /*********************************************************************
    101. *
    102. * _cbSwipe
    103. */
    104. static void _cbSwipe(WM_MESSAGE * pMsg) {
    105. int NCode;
    106. int Id;
    107. WM_HWIN hItem;
    108. int Value;
    109. switch (pMsg->MsgId) {
    110. case WM_NOTIFY_PARENT:
    111. //
    112. // Get Id of the child got something
    113. //
    114. Id = WM_GetId(pMsg->hWinSrc);
    115. //
    116. // Get an idea of what it got
    117. //
    118. NCode = pMsg->Data.v;
    119. switch(Id) {
    120. case ID_RADIO_0: // Notifications sent by the RADIO widget
    121. switch(NCode) {
    122. case WM_NOTIFICATION_VALUE_CHANGED:
    123. hItem = WM_GetDialogItem(pMsg->hWin, ID_RADIO_0);
    124. Value = RADIO_GetValue(hItem);
    125. break;
    126. }
    127. break;
    128. case ID_CHECK_0: // Notifications sent by CHECKBOX widget
    129. switch(NCode) {
    130. case WM_NOTIFICATION_VALUE_CHANGED:
    131. hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECK_0);
    132. Value = CHECKBOX_GetState(hItem);
    133. break;
    134. }
    135. break;
    136. }
    137. break;
    138. default:
    139. SWIPELIST_Callback(pMsg);
    140. break;
    141. }
    142. }
    143. /*********************************************************************
    144. *
    145. * _cbDialog
    146. */
    147. static void _cbDialog(WM_MESSAGE * pMsg) {
    148. WM_HWIN hItem;
    149. GUI_RECT Rect;
    150. int NCode;
    151. int Id;
    152. char aText[30];
    153. int i;
    154. int j;
    155. int Item;
    156. static int ItemIndex = 0;
    157. static GUI_RECT TRect;
    158. WM_HWIN hAttachItem;
    159. switch (pMsg->MsgId) {
    160. case WM_INIT_DIALOG:
    161. //
    162. // Init SWIPELIST
    163. //
    164. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    165. WM_SetCallback(hItem, _cbSwipe);
    166. WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
    167. //
    168. // Four separator
    169. //
    170. Item = 1;
    171. for (j = 0; j < 4; j++) {
    172. sprintf(aText, "Separator %i", j);
    173. SWIPELIST_AddSepItem(hItem, aText, 30);
    174. //
    175. // Four subitems for each separator
    176. //
    177. for (i = 0; i < 4; i++) {
    178. sprintf(aText, "Item %i", j + Item++);
    179. SWIPELIST_AddItem(hItem, aText, 60);
    180. }
    181. }
    182. hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, ID_RADIO_0, 3, 15);
    183. SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
    184. hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, ID_CHECK_0);
    185. SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
    186. //
    187. // Set an owner draw function
    188. //
    189. SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
    190. //
    191. // Set Text rect
    192. //
    193. TRect.x0 = LCD_GetXSize() / 2;
    194. TRect.y0 = 0;
    195. TRect.x1 = LCD_GetXSize();
    196. TRect.y1 = LCD_GetYSize();
    197. break;
    198. case WM_PAINT:
    199. //
    200. // Draw the background of the dialog window
    201. //
    202. WM_GetClientRect(&Rect);
    203. GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
    204. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    205. //
    206. // Draw a frame around the SWIPELIST
    207. //
    208. WM_GetWindowRectEx(hItem, &Rect);
    209. Rect.x0 -= 1;
    210. Rect.y0 -= 1;
    211. Rect.x1 += 1;
    212. Rect.y1 += 1;
    213. GUI_SetColor(GUI_LIGHTGRAY);
    214. GUI_DrawRectEx(&Rect);
    215. if (ItemIndex) {
    216. sprintf(aText, "Item %i selected", ItemIndex); // build a string
    217. } else {
    218. sprintf(aText, "no item selected"); // build a string
    219. }
    220. GUI_SetTextMode(GUI_TM_TRANS);
    221. GUI_SetFont(GUI_FONT_24B_1);
    222. GUI_SetColor(GUI_WHITE);
    223. GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
    224. break;
    225. case WM_NOTIFY_PARENT:
    226. //
    227. // Get Id of the child got something
    228. //
    229. Id = WM_GetId(pMsg->hWinSrc);
    230. //
    231. // Get an idea of what it got
    232. //
    233. NCode = pMsg->Data.v;
    234. switch(Id) {
    235. //
    236. // Which child
    237. //
    238. case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
    239. switch(NCode) {
    240. //
    241. // got what
    242. //
    243. case WM_NOTIFICATION_CLICKED:
    244. break;
    245. case WM_NOTIFICATION_RELEASED:
    246. hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
    247. ItemIndex = SWIPELIST_GetReleasedItem(hItem);
    248. WM_InvalidateRect(pMsg->hWin, &TRect);
    249. break;
    250. }
    251. break;
    252. }
    253. break;
    254. default:
    255. WM_DefaultProc(pMsg);
    256. break;
    257. }
    258. }
    259. /*********************************************************************
    260. *
    261. * Public code
    262. *
    263. **********************************************************************
    264. */
    265. /*********************************************************************
    266. *
    267. * MainTask
    268. */
    269. void MainTask(void) {
    270. WM_SetCreateFlags(WM_CF_MEMDEV);
    271. GUI_Init();
    272. WM_MOTION_Enable(1);
    273. GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
    274. while (1) {
    275. GUI_Delay(100);
    276. }
    277. }
    278. /*************************** 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.