create a simple custom widget (LED)

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

  • create a simple custom widget (LED)

    Hi, I need to create a simple LED widget (just display one of two images according to ON/OFF state, I wonder how such a basic widget is missing...).

    I read the costume widget creation doc, but missing the create_indirect() function template.

    I assume that Create_indirect call <myWidget>_create, but how?

    Is it available anywhere?

    thanks

    Johanan
  • Hello Johanan,

    The IMAGE widget can be used to display images.

    Currently the application note for creating a custom widget type does not include a guide for a <MyWidget>_CreateIndirect() function. I would recommend you to create your custom widget from within the WM_INIT_DIALOG event.

    Best regards,
    Adrian
  • My application builds the screens dynamically, ans populates a dialogue table at run time, so I need the create indirect. It seems quite easy to do, but the way to set the WINDOW_ID is unclear.
    I now do with a workaround, using MY_GetDialogItem(), and I wonder if you can give a hint on doing it in a more elegant way.
    -------------------

    C Source Code

    1. typedef struct {
    2. U8 State;
    3. GUI_BITMAP * pOffBMP;
    4. GUI_BITMAP * pOnBMP;
    5. int wmid;
    6. } LED_Obj;
    7. LED_Handle LED_Create(int x0, int y0, int xSize, int ySize,
    8. WM_HWIN hWinParent,U32 Style, WM_CALLBACK * pfCallback, int wmid)
    9. {
    10. LED_Handle hWin;
    11. LED_Obj LEDwidget;
    12. WM_CALLBACK * pfUsed;
    13. if (pfCallback) {
    14. pfUsed = pfCallback;
    15. } else {
    16. pfUsed = LED_Callback;
    17. }
    18. LEDwidget = LED_Default;
    19. LEDwidget.wmid = wmid; // save the WM ID
    20. hWin = WM_CreateWindowAsChild(x0, y0, xSize, ySize, hWinParent, Style, pfUsed, sizeof(LED_Obj));
    21. WM_SetUserData(hWin, &LEDwidget, sizeof(LED_Obj));
    22. return hWin;
    23. }
    24. LED_Handle LED_CreateIndirect(const GUI_WIDGET_CREATE_INFO* pCreateInfo, WM_HWIN hWinParent, int x0, int y0, WM_CALLBACK* cb) {
    25. LED_Handle hRes;
    26. hRes = LED_Create( pCreateInfo->x0, pCreateInfo->y0 ,pCreateInfo->xSize, pCreateInfo->ySize,
    27. hWinParent, 0, cb, pCreateInfo->Id);
    28. WM_SetId(hRes, pCreateInfo->Id); // this has no effect. Why?
    29. return hRes;
    30. }
    31. WM_HWIN MY_GetDialogItem(WM_HWIN hwin, int id)
    32. {
    33. WM_HWIN res;
    34. LED_Obj ledobj;
    35. res = WM_GetDialogItem(hwin, id);
    36. if (res != 0 )
    37. return res;
    38. // check my custom widget, LED
    39. res = WM_GetFirstChild(hwin);
    40. while ( res != 0)
    41. {
    42. if(WM_GetCallback(res) == LED_Callback) // is it my led?
    43. {
    44. WM_GetUserData(res,&ledobj,sizeof(LED_Obj));
    45. if(ledobj.wmid == id)
    46. return res;
    47. }
    48. res = WM_GetNextSibling(res);
    49. }
    50. }
    51. // now in the callback...
    52. ...
    53. case WM_NOTIFICATION_RELEASED : // led changes when button is relesed
    54. hItem = MY_GetDialogItem(hWin, ID_LED);
    55. LED_SetState(hItem, LED_GetState(hItem) ^ 1);
    56. break;
    Display All


    Thanks
    Johanan
  • Using the WM_SetId function is a custom widget

    Hello Adrian and Johanan,

    I am facing the same issue when using a custom widget.

    In the create function I use the function WM_SetId to setup a unique id for the widget, but when I call the WM_GetId in the parent window to identify which widget was clicked it always returns 0.

    Is there a work around for this?

    Thank you,

    Pedro
  • Using the WM_SetId function is a custom widget

    Hello Adrian and Johanan,

    Looking back over the documentation I figured out why the WM_GetId and WM_SetId is not working. We need to implement this in our widget's message callback function using the WM_GET_ID and WM_SET_ID.

    E.g.


    void WinHandler(WM_MESSAGE * pMsg)
    {
    DIGI_SLIDER_Obj sliderObj;

    WM_GetUserData(hWin, &sliderObj, sizeof(DIGI_SLIDER_Obj));

    switch (pMsg->MsgId)
    {
    case WM_GET_ID:
    pMsg->Data.v = sliderObj.Id;
    break;

    case WM_SET_ID:
    sliderObj.Id = pMsg->Data.v;
    WM_SetUserData(hWin, &sliderObj, sizeof(DIGI_SLIDER_Obj));
    break;
    default:
    WM_DefaultProc(pMsg);
    }
    }

    Thank you,

    Pedro