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
- /*********************************************************************
- * SEGGER MICROCONTROLLER SYSTEME GmbH *
- * Solutions for real time microcontroller applications *
- **********************************************************************
- * *
- * 2016 SEGGER Microcontroller Systeme GmbH *
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- ----------------------------------------------------------------------
- File : GUIDRV_Lin.h
- Purpose : Interface definition for GUIDRV_Lin driver
- ---------------------------END-OF-HEADER------------------------------
- */
- #include <stdio.h>
- #include "DIALOG.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
- { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
- };
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _SwipeOwnerDraw
- */
- static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
- //
- // Distinguish between different commands
- //
- switch (pDrawItemInfo->Cmd) {
- case WIDGET_ITEM_DRAW_SEP:
- GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
- GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
- break;
- case WIDGET_ITEM_DRAW_TEXT:
- //
- // Just set a text mode but let the default owner draw routine handle the rest
- //
- GUI_SetTextMode(GUI_TM_TRANS);
- SWIPELIST_OwnerDraw(pDrawItemInfo);
- break;
- case WIDGET_ITEM_DRAW_BITMAP:
- break;
- case WIDGET_ITEM_DRAW_BACKGROUND:
- //
- // Handle drawing of the background of the items
- //
- switch (pDrawItemInfo->ItemIndex) {
- case 0: // 1st separator
- case 5: // 2nd separator
- case 10: // 3rd separator
- case 15: // 4th separator
- GUI_SetColor(GUI_BLACK);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
- return 0;
- default: // Any other item
- //
- // Determin if the item to drawn is the currently selected
- //
- if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
- //
- // Draw the selected one different
- //
- GUI_SetColor(GUI_DARKRED);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
- } else {
- //
- // Draw any other items this way
- //
- GUI_SetColor(GUI_DARKGRAY);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- }
- }
- break;
- default:
- //
- // Anything we do not catch in this routine gets handled by the default owner draw
- //
- return SWIPELIST_OwnerDraw(pDrawItemInfo);
- }
- return 0;
- }
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- GUI_RECT Rect;
- int NCode;
- int Id;
- char aText[30];
- int i;
- int j;
- int Item;
- static int ItemIndex = 0;
- static GUI_RECT TRect;
- WM_HWIN hAttachItem;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- //
- // Init SWIPELIST
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- //
- // Four separator
- //
- Item = 1;
- for (j = 0; j < 4; j++) {
- sprintf(aText, "Separator %i", j);
- SWIPELIST_AddSepItem(hItem, aText, 30);
- //
- // Four subitems for each separator
- //
- for (i = 0; i < 4; i++) {
- sprintf(aText, "Item %i", j + Item++);
- SWIPELIST_AddItem(hItem, aText, 60);
- }
- }
- hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, 0, 3, 15);
- SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
- hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, 0);
- SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
- //
- // Set an owner draw function
- //
- SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
- //
- // Set Text rect
- //
- TRect.x0 = LCD_GetXSize() / 2;
- TRect.y0 = 0;
- TRect.x1 = LCD_GetXSize();
- TRect.y1 = LCD_GetYSize();
- break;
- case WM_PAINT:
- //
- // Draw the background of the dialog window
- //
- WM_GetClientRect(&Rect);
- GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- //
- // Draw a frame around the SWIPELIST
- //
- WM_GetWindowRectEx(hItem, &Rect);
- Rect.x0 -= 1;
- Rect.y0 -= 1;
- Rect.x1 += 1;
- Rect.y1 += 1;
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRectEx(&Rect);
- if (ItemIndex) {
- sprintf(aText, "Item %i selected", ItemIndex); // build a string
- } else {
- sprintf(aText, "no item selected"); // build a string
- }
- GUI_SetTextMode(GUI_TM_TRANS);
- GUI_SetFont(GUI_FONT_24B_1);
- GUI_SetColor(GUI_WHITE);
- GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
- break;
- case WM_NOTIFY_PARENT:
- //
- // Get Id of the child got something
- //
- Id = WM_GetId(pMsg->hWinSrc);
- //
- // Get an idea of what it got
- //
- NCode = pMsg->Data.v;
- switch(Id) {
- //
- // Which child
- //
- case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
- switch(NCode) {
- //
- // got what
- //
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- ItemIndex = SWIPELIST_GetReleasedItem(hItem);
- WM_InvalidateRect(pMsg->hWin, &TRect);
- break;
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- WM_SetCreateFlags(WM_CF_MEMDEV);
- GUI_Init();
- GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- while (1) {
- GUI_Delay(100);
- }
- }
- /*************************** End of file ****************************/
I hope this helps.
Regards,
SvenPlease 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
This should work:
C Source Code
- /*********************************************************************
- * SEGGER MICROCONTROLLER SYSTEME GmbH *
- * Solutions for real time microcontroller applications *
- **********************************************************************
- * *
- * 2016 SEGGER Microcontroller Systeme GmbH *
- * *
- * Internet: www.segger.com Support: support@segger.com *
- * *
- **********************************************************************
- ----------------------------------------------------------------------
- File : GUIDRV_Lin.h
- Purpose : Interface definition for GUIDRV_Lin driver
- ---------------------------END-OF-HEADER------------------------------
- */
- #include <stdio.h>
- #include "DIALOG.h"
- #include "SWIPELIST.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
- { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
- };
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _SwipeOwnerDraw
- */
- static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
- //
- // Distinguish between different commands
- //
- switch (pDrawItemInfo->Cmd) {
- case WIDGET_ITEM_DRAW_SEP:
- GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
- GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
- break;
- case WIDGET_ITEM_DRAW_TEXT:
- //
- // Just set a text mode but let the default owner draw routine handle the rest
- //
- GUI_SetTextMode(GUI_TM_TRANS);
- SWIPELIST_OwnerDraw(pDrawItemInfo);
- break;
- case WIDGET_ITEM_DRAW_BITMAP:
- break;
- case WIDGET_ITEM_DRAW_BACKGROUND:
- //
- // Handle drawing of the background of the items
- //
- switch (pDrawItemInfo->ItemIndex) {
- case 0: // 1st separator
- case 5: // 2nd separator
- case 10: // 3rd separator
- case 15: // 4th separator
- GUI_SetColor(GUI_BLACK);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
- return 0;
- default: // Any other item
- //
- // Determin if the item to drawn is the currently selected
- //
- if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
- //
- // Draw the selected one different
- //
- GUI_SetColor(GUI_DARKRED);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
- } else {
- //
- // Draw any other items this way
- //
- GUI_SetColor(GUI_DARKGRAY);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- }
- }
- break;
- default:
- //
- // Anything we do not catch in this routine gets handled by the default owner draw
- //
- return SWIPELIST_OwnerDraw(pDrawItemInfo);
- }
- return 0;
- }
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- GUI_RECT Rect;
- int NCode;
- int Id;
- char aText[30];
- int i;
- int j;
- int Item;
- static int ItemIndex = 0;
- static GUI_RECT TRect;
- WM_HWIN hAttachItem;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- //
- // Init SWIPELIST
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
- //
- // Four separator
- //
- Item = 1;
- for (j = 0; j < 4; j++) {
- sprintf(aText, "Separator %i", j);
- SWIPELIST_AddSepItem(hItem, aText, 30);
- //
- // Four subitems for each separator
- //
- for (i = 0; i < 4; i++) {
- sprintf(aText, "Item %i", j + Item++);
- SWIPELIST_AddItem(hItem, aText, 60);
- }
- }
- hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, 0, 3, 15);
- SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
- hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, 0);
- SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
- //
- // Set an owner draw function
- //
- SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
- //
- // Set Text rect
- //
- TRect.x0 = LCD_GetXSize() / 2;
- TRect.y0 = 0;
- TRect.x1 = LCD_GetXSize();
- TRect.y1 = LCD_GetYSize();
- break;
- case WM_PAINT:
- //
- // Draw the background of the dialog window
- //
- WM_GetClientRect(&Rect);
- GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- //
- // Draw a frame around the SWIPELIST
- //
- WM_GetWindowRectEx(hItem, &Rect);
- Rect.x0 -= 1;
- Rect.y0 -= 1;
- Rect.x1 += 1;
- Rect.y1 += 1;
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRectEx(&Rect);
- if (ItemIndex) {
- sprintf(aText, "Item %i selected", ItemIndex); // build a string
- } else {
- sprintf(aText, "no item selected"); // build a string
- }
- GUI_SetTextMode(GUI_TM_TRANS);
- GUI_SetFont(GUI_FONT_24B_1);
- GUI_SetColor(GUI_WHITE);
- GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
- break;
- case WM_NOTIFY_PARENT:
- //
- // Get Id of the child got something
- //
- Id = WM_GetId(pMsg->hWinSrc);
- //
- // Get an idea of what it got
- //
- NCode = pMsg->Data.v;
- switch(Id) {
- //
- // Which child
- //
- case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
- switch(NCode) {
- //
- // got what
- //
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- ItemIndex = SWIPELIST_GetReleasedItem(hItem);
- WM_InvalidateRect(pMsg->hWin, &TRect);
- break;
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- WM_SetCreateFlags(WM_CF_MEMDEV);
- GUI_Init();
- WM_MOTION_Enable(1);
- GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- while (1) {
- GUI_Delay(100);
- }
- }
- /*************************** End of file ****************************/
Regards,
SvenPlease 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,
Wow! Its working.. Thanks :) -
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,
SvenPlease 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
- #include <stdio.h>
- #include "RADIO.h"
- #include "DIALOG.h"
- #include "SWIPELIST.h"
- /*
- Defines
- */
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
- #define ID_RADIO_0 (GUI_ID_USER + 0x02)
- static WM_HWIN _hWindow1;
- static GUI_COLOR _FrameColor1 = GUI_BLUE;
- /*
- Static data
- */
- /*
- _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 800, 480, 0, 0x0, 0 },
- { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 400, 440, 0, 0x0, 0 },
- };
- /*
- Static code
- */
- /*
- _cbWindow1
- */
- static void _cbWindow1(WM_MESSAGE * pMsg) {
- GUI_RECT Rect;
- int x;
- int y;
- switch (pMsg->MsgId) {
- case WM_PAINT:
- WM_GetInsideRect(&Rect);
- GUI_SetBkColor(GUI_RED);
- GUI_SetColor(_FrameColor1);
- GUI_ClearRectEx(&Rect);
- GUI_DrawRectEx(&Rect);
- GUI_SetColor(GUI_WHITE);
- GUI_SetFont(&GUI_Font24_ASCII);
- x = WM_GetWindowSizeX(pMsg->hWin);
- y = WM_GetWindowSizeY(pMsg->hWin);
- GUI_DispStringHCenterAt("Window 1", x / 2, (y / 2) - 12);
- break;
- default:
- WM_DefaultProc(pMsg);
- }
- }
- /*
- _SwipeOwnerDraw
- */
- static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
- //
- // Distinguish between different commands
- //
- switch (pDrawItemInfo->Cmd) {
- case WIDGET_ITEM_DRAW_SEP:
- GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
- GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
- break;
- case WIDGET_ITEM_DRAW_TEXT:
- //
- // Just set a text mode but let the default owner draw routine handle the rest
- //
- GUI_SetTextMode(GUI_TM_TRANS);
- SWIPELIST_OwnerDraw(pDrawItemInfo);
- break;
- case WIDGET_ITEM_DRAW_BITMAP:
- break;
- case WIDGET_ITEM_DRAW_BACKGROUND:
- //
- // Handle drawing of the background of the items
- //
- switch (pDrawItemInfo->ItemIndex) {
- case 0: // 1st separator
- case 5: // 2nd separator
- case 10: // 3rd separator
- case 15: // 4th separator
- GUI_SetColor(GUI_BLACK);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
- return 0;
- default: // Any other item
- //
- // Determin if the item to drawn is the currently selected
- //
- if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
- //
- // Draw the selected one different
- //
- GUI_SetColor(GUI_DARKRED);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
- } else {
- //
- // Draw any other items this way
- //
- GUI_SetColor(GUI_DARKGRAY);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- }
- }
- break;
- default:
- //
- // Anything we do not catch in this routine gets handled by the default owner draw
- //
- return SWIPELIST_OwnerDraw(pDrawItemInfo);
- }
- return 0;
- }
- /*
- _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- GUI_RECT Rect;
- int NCode;
- int Id;
- char aText[30];
- int i;
- int j;
- int Item;
- static int ItemIndex = 0;
- static int RadioValue = 0;
- static GUI_RECT TRect;
- WM_HWIN hAttachItem;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- //
- // Init SWIPELIST
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
- //
- // Four separator
- //
- Item = 1;
- for (j = 0; j < 4; j++) {
- sprintf(aText, "Separator %i", j);
- SWIPELIST_AddSepItem(hItem, aText, 30);
- //
- // Four subitems for each separator
- //
- for (i = 0; i < 4; i++) {
- sprintf(aText, "Item %i", j + Item++);
- SWIPELIST_AddItem(hItem, aText, 60);
- }
- }
- hAttachItem = RADIO_CreateEx(0, 0, 60, 50, pMsg->hWin, WM_CF_SHOW, 0, ID_RADIO_0, 3, 15);
- RADIO_SetTextColor(hAttachItem,GUI_WHITE);
- RADIO_SetText(hAttachItem, "Red",0);
- RADIO_SetText(hAttachItem, "Blue",1);
- RADIO_SetText(hAttachItem, "Green",2);
- SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 40, 50);
- //
- // Set an owner draw function
- //
- SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
- //
- // Set Text rect
- //
- TRect.x0 = LCD_GetXSize() / 2;
- TRect.y0 = 0;
- TRect.x1 = LCD_GetXSize();
- TRect.y1 = LCD_GetYSize();
- break;
- case WM_PAINT:
- //
- // Draw the background of the dialog window
- //
- WM_GetClientRect(&Rect);
- GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- //
- // Draw a frame around the SWIPELIST
- //
- WM_GetWindowRectEx(hItem, &Rect);
- Rect.x0 -= 1;
- Rect.y0 -= 1;
- Rect.x1 += 1;
- Rect.y1 += 1;
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRectEx(&Rect);
- if (ItemIndex) {
- sprintf(aText, "Item %i selected", ItemIndex); // build a string
- } else {
- sprintf(aText, "no item selected"); // build a string
- }
- GUI_SetTextMode(GUI_TM_TRANS);
- GUI_SetFont(GUI_FONT_24B_1);
- GUI_SetColor(GUI_WHITE);
- GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
- break;
- case WM_TOUCH_CHILD:
- break;
- case WM_NOTIFY_PARENT:
- //
- // Get Id of the child got something
- //
- Id = WM_GetId(pMsg->hWinSrc);
- //
- // Get an idea of what it got
- //
- NCode = pMsg->Data.v;
- switch(Id) {
- //
- // Which child
- //
- case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
- switch(NCode) {
- //
- // got what
- //
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- ItemIndex = SWIPELIST_GetReleasedItem(hItem);
- switch(ItemIndex){
- case 1:
- break;
- case 2 :
- WM_DeleteWindow(_hWindow1);
- break;
- }
- WM_InvalidateRect(pMsg->hWin, &TRect);
- break;
- }
- break;
- case ID_RADIO_0: // Notifications sent by 'Radio'
- switch(NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- // USER START (Optionally insert code for reacting on notification message)
- hItem= WM_GetDialogItem(pMsg->hWin,ID_RADIO_0);
- RadioValue=RADIO_GetValue(hItem);
- switch(RadioValue){
- case 0:
- _hWindow1 = WM_CreateWindow( 500, 5, 400, 460, WM_CF_SHOW | WM_CF_MEMDEV, _cbWindow1, 0);
- break;
- }
- // USER END
- break;
- // USER START (Optionally insert additional code for further notification handling)
- // USER END
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- void MainTask(void) {
- WM_SetCreateFlags(WM_CF_MEMDEV);
- WM_EnableMemdev(WM_HBKWIN);
- GUI_Init();
- WM_MOTION_Enable(1);
- GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- while (1) {
- GUI_Delay(100);
- }
- }
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
- /*********************************************************************
- *
- * _cbSwipe
- */
- static void _cbSwipe(WM_MESSAGE * pMsg) {
- int NCode;
- int Id;
- WM_HWIN hItem;
- int Value;
- switch (pMsg->MsgId) {
- case WM_NOTIFY_PARENT:
- //
- // Get Id of the child got something
- //
- Id = WM_GetId(pMsg->hWinSrc);
- //
- // Get an idea of what it got
- //
- NCode = pMsg->Data.v;
- switch(Id) {
- case ID_RADIO_0: // Notifications sent by the RADIO widget
- switch(NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_RADIO_0);
- Value = RADIO_GetValue(hItem);
- break;
- }
- break;
- case ID_CHECK_0: // Notifications sent by CHECKBOX widget
- switch(NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECK_0);
- Value = CHECKBOX_GetState(hItem);
- break;
- }
- break;
- }
- break;
- default:
- SWIPELIST_Callback(pMsg);
- break;
- }
- }
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:
Thats all. In _cbSwipe() we react on the different widgets and get their values.
The final application would look like this:
C Source Code
- #include <stdio.h>
- #include "DIALOG.h"
- #include "SWIPELIST.h"
- /*********************************************************************
- *
- * Defines
- *
- **********************************************************************
- */
- #define ID_WINDOW_0 (GUI_ID_USER + 0x00)
- #define ID_SWIPELIST_0 (GUI_ID_USER + 0x01)
- #define ID_RADIO_0 (GUI_ID_USER + 0x02)
- #define ID_CHECK_0 (GUI_ID_USER + 0x03)
- /*********************************************************************
- *
- * Static data
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _aDialogCreate
- */
- static const GUI_WIDGET_CREATE_INFO _aDialogCreate[] = {
- { WINDOW_CreateIndirect, "Window", ID_WINDOW_0, 0, 0, 480, 272, 0, 0x0, 0 },
- { SWIPELIST_CreateIndirect, "Swipelist", ID_SWIPELIST_0, 20, 20, 220, 232, 0, 0x0, 0 },
- };
- /*********************************************************************
- *
- * Static code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * _SwipeOwnerDraw
- */
- static int _SwipeOwnerDraw(const WIDGET_ITEM_DRAW_INFO * pDrawItemInfo) {
- //
- // Distinguish between different commands
- //
- switch (pDrawItemInfo->Cmd) {
- case WIDGET_ITEM_DRAW_SEP:
- GUI_DrawGradientH(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y1, GUI_DARKGRAY, GUI_BLACK);
- GUI_DrawGradientH(pDrawItemInfo->x1 - (pDrawItemInfo->x1 - pDrawItemInfo->x0) / 2, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_BLACK, GUI_DARKGRAY);
- break;
- case WIDGET_ITEM_DRAW_TEXT:
- //
- // Just set a text mode but let the default owner draw routine handle the rest
- //
- GUI_SetTextMode(GUI_TM_TRANS);
- SWIPELIST_OwnerDraw(pDrawItemInfo);
- break;
- case WIDGET_ITEM_DRAW_BITMAP:
- break;
- case WIDGET_ITEM_DRAW_BACKGROUND:
- //
- // Handle drawing of the background of the items
- //
- switch (pDrawItemInfo->ItemIndex) {
- case 0: // 1st separator
- case 5: // 2nd separator
- case 10: // 3rd separator
- case 15: // 4th separator
- GUI_SetColor(GUI_BLACK);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 2, GUI_BLACK, GUI_GRAY);
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRoundedRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - 1, 5);
- return 0;
- default: // Any other item
- //
- // Determin if the item to drawn is the currently selected
- //
- if (SWIPELIST_GetSelItem(pDrawItemInfo->hWin) == pDrawItemInfo->ItemIndex) {
- //
- // Draw the selected one different
- //
- GUI_SetColor(GUI_DARKRED);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) * 2 / 3, GUI_BLACK, GUI_DARKRED);
- GUI_DrawGradientV(pDrawItemInfo->x0, pDrawItemInfo->y1 - (pDrawItemInfo->y1 - pDrawItemInfo->y0) / 3, pDrawItemInfo->x1, pDrawItemInfo->y1, GUI_DARKRED, GUI_BLACK);
- } else {
- //
- // Draw any other items this way
- //
- GUI_SetColor(GUI_DARKGRAY);
- GUI_FillRect(pDrawItemInfo->x0, pDrawItemInfo->y0, pDrawItemInfo->x1, pDrawItemInfo->y1);
- }
- }
- break;
- default:
- //
- // Anything we do not catch in this routine gets handled by the default owner draw
- //
- return SWIPELIST_OwnerDraw(pDrawItemInfo);
- }
- return 0;
- }
- /*********************************************************************
- *
- * _cbSwipe
- */
- static void _cbSwipe(WM_MESSAGE * pMsg) {
- int NCode;
- int Id;
- WM_HWIN hItem;
- int Value;
- switch (pMsg->MsgId) {
- case WM_NOTIFY_PARENT:
- //
- // Get Id of the child got something
- //
- Id = WM_GetId(pMsg->hWinSrc);
- //
- // Get an idea of what it got
- //
- NCode = pMsg->Data.v;
- switch(Id) {
- case ID_RADIO_0: // Notifications sent by the RADIO widget
- switch(NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_RADIO_0);
- Value = RADIO_GetValue(hItem);
- break;
- }
- break;
- case ID_CHECK_0: // Notifications sent by CHECKBOX widget
- switch(NCode) {
- case WM_NOTIFICATION_VALUE_CHANGED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_CHECK_0);
- Value = CHECKBOX_GetState(hItem);
- break;
- }
- break;
- }
- break;
- default:
- SWIPELIST_Callback(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * _cbDialog
- */
- static void _cbDialog(WM_MESSAGE * pMsg) {
- WM_HWIN hItem;
- GUI_RECT Rect;
- int NCode;
- int Id;
- char aText[30];
- int i;
- int j;
- int Item;
- static int ItemIndex = 0;
- static GUI_RECT TRect;
- WM_HWIN hAttachItem;
- switch (pMsg->MsgId) {
- case WM_INIT_DIALOG:
- //
- // Init SWIPELIST
- //
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- WM_SetCallback(hItem, _cbSwipe);
- WM_MOTION_SetMoveable(hItem, WM_CF_MOTION_Y, 1);
- //
- // Four separator
- //
- Item = 1;
- for (j = 0; j < 4; j++) {
- sprintf(aText, "Separator %i", j);
- SWIPELIST_AddSepItem(hItem, aText, 30);
- //
- // Four subitems for each separator
- //
- for (i = 0; i < 4; i++) {
- sprintf(aText, "Item %i", j + Item++);
- SWIPELIST_AddItem(hItem, aText, 60);
- }
- }
- hAttachItem = RADIO_CreateEx(0, 0, 20, 50, pMsg->hWin, WM_CF_SHOW, 0, ID_RADIO_0, 3, 15);
- SWIPELIST_ItemAttachWindow(hItem, 1, hAttachItem, 70, 5);
- hAttachItem = CHECKBOX_CreateEx(0, 0, 20, 20, pMsg->hWin, WM_CF_SHOW, 0, ID_CHECK_0);
- SWIPELIST_ItemAttachWindow(hItem, 2, hAttachItem, 70, 20);
- //
- // Set an owner draw function
- //
- SWIPELIST_SetOwnerDraw(hItem, _SwipeOwnerDraw);
- //
- // Set Text rect
- //
- TRect.x0 = LCD_GetXSize() / 2;
- TRect.y0 = 0;
- TRect.x1 = LCD_GetXSize();
- TRect.y1 = LCD_GetYSize();
- break;
- case WM_PAINT:
- //
- // Draw the background of the dialog window
- //
- WM_GetClientRect(&Rect);
- GUI_DrawGradientH(Rect.x0, Rect.y0, Rect.x1, Rect.y1, GUI_BLACK, GUI_GRAY);
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- //
- // Draw a frame around the SWIPELIST
- //
- WM_GetWindowRectEx(hItem, &Rect);
- Rect.x0 -= 1;
- Rect.y0 -= 1;
- Rect.x1 += 1;
- Rect.y1 += 1;
- GUI_SetColor(GUI_LIGHTGRAY);
- GUI_DrawRectEx(&Rect);
- if (ItemIndex) {
- sprintf(aText, "Item %i selected", ItemIndex); // build a string
- } else {
- sprintf(aText, "no item selected"); // build a string
- }
- GUI_SetTextMode(GUI_TM_TRANS);
- GUI_SetFont(GUI_FONT_24B_1);
- GUI_SetColor(GUI_WHITE);
- GUI_DispStringInRect(aText, &TRect, GUI_TA_HCENTER | GUI_TA_VCENTER); // and display it centered
- break;
- case WM_NOTIFY_PARENT:
- //
- // Get Id of the child got something
- //
- Id = WM_GetId(pMsg->hWinSrc);
- //
- // Get an idea of what it got
- //
- NCode = pMsg->Data.v;
- switch(Id) {
- //
- // Which child
- //
- case ID_SWIPELIST_0: // Notifications sent by 'Swipelist'
- switch(NCode) {
- //
- // got what
- //
- case WM_NOTIFICATION_CLICKED:
- break;
- case WM_NOTIFICATION_RELEASED:
- hItem = WM_GetDialogItem(pMsg->hWin, ID_SWIPELIST_0);
- ItemIndex = SWIPELIST_GetReleasedItem(hItem);
- WM_InvalidateRect(pMsg->hWin, &TRect);
- break;
- }
- break;
- }
- break;
- default:
- WM_DefaultProc(pMsg);
- break;
- }
- }
- /*********************************************************************
- *
- * Public code
- *
- **********************************************************************
- */
- /*********************************************************************
- *
- * MainTask
- */
- void MainTask(void) {
- WM_SetCreateFlags(WM_CF_MEMDEV);
- GUI_Init();
- WM_MOTION_Enable(1);
- GUI_CreateDialogBox(_aDialogCreate, GUI_COUNTOF(_aDialogCreate), _cbDialog, WM_HBKWIN, 0, 0);
- while (1) {
- GUI_Delay(100);
- }
- }
- /*************************** End of file ****************************/
Regards,
SvenPlease 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, Schoenen,
Thank you for your swift reponse, it helped me alot to grasp the callback system.
Regards,
JjO
-
Share
- Facebook 0
- Twitter 0
- Google Plus 0
- Reddit 0