Dropdown widget issues

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

    • Dropdown widget issues

      Dropdown widget issues

      Hello,

      I'm using a super simple test program with the DROPDOWN Widget. I actually used the example code from Segger's WIDGET_Dropdown.c

      I'm using the simulator on a WIN10 machine.
      1. When I only have the Dropdown widget in my program everything works perfectly.
      2. Now I added Buttons to the above program and the buttons works but the Dropdown widget expands only at the first touch on the screen. After the first click on the down arrow it never closes again. All the rest of the widgets (Buttons) present in the window still work.
      3. I isolated the issue to the following:
      A) The Segger Dropdown.c example does not use a Callback function and the Dropdown works perfectly
      B) When I add the Buttons and a Callback() function to handle my Buttons the behavior highlighted above takes place: "Dropdown widget expands only at the first touch on the screen and never closes."
      C) I figured out that the Dropdown widget actually closes but the Background is not redrawn so it "looks" as if the Dropdown widget is still expanded.
      D) To prove this I added a Callback function to redraw the background :

      WM_SetCallback(WM_HBKWIN, cbBackgroundWin);

      /*******************************************************************
      * *
      Callback routine for background window
      * ********************************************************************
      */
      static void cbBackgroundWin(WM_MESSAGE * pMsg) {
      switch (pMsg->MsgId) {
      case WM_PAINT:
      GUI_Clear();
      break;
      default:
      WM_DefaultProc(pMsg);
      }
      }

      This now works and the Dropdown opens/closes as expected but all the primitives (circles, rectangles, etc...), and text I have that were drawn on the screen are erased when this cbBackgroundWin() is called, which means I would have to draw all my primitives and text in the cbBackgroundWin() Callback. That is really not elegant coding. Is there another way?

      Thanks for your help in advance
      Electrons4me
    • Hello,

      Electrons4me wrote:

      ...I would have to draw all my primitives and text in the cbBackgroundWin() Callback...

      yes, that's right. If you are using widgets in your projects then you are using Window Manager and in this case you need to handle WM_PAINT message of the background window (desktop window in your case) and also draw all the additional graphics there. This is the way WM works and that is not only in emWin. WMs in Windows and other OS work the same way.

      Alex.
    • @EmWin support,

      I did not get any replies from you so I'm assuming that LexabGb is correct and I have to put all my own drawings and text in the callback. Would you have an example where I could see how you do this so I can replicate?

      @LexabGb, thanks for sharing, much appreciated.

      Thanks
      Electrons4me
    • Hello,

      quite simple.

      C Source Code

      1. #include "DIALOG.h"
      2. DROPDOWN_Handle hDropdown;
      3. static void _cbBk(WM_MESSAGE * pMsg) {
      4. switch (pMsg->MsgId) {
      5. case WM_PAINT:
      6. GUI_Clear();
      7. GUI_DrawCircle(90, 110, 30);
      8. GUI_DispStringHCenterAt("Circle", 90, 105);
      9. break;
      10. default:
      11. WM_DefaultProc(pMsg);
      12. break;
      13. }
      14. }
      15. void MainTask(void) {
      16. GUI_Init();
      17. WM_MULTIBUF_Enable(1);
      18. WM_SetCallback(WM_HBKWIN, _cbBk);
      19. hDropdown = DROPDOWN_CreateEx(50, 50, 80, 20, WM_HBKWIN, WM_CF_SHOW, 0, GUI_ID_DROPDOWN0);
      20. DROPDOWN_AddString(hDropdown, "Item 1");
      21. DROPDOWN_AddString(hDropdown, "Item 2");
      22. DROPDOWN_AddString(hDropdown, "Item 3");
      23. DROPDOWN_SetListHeight(hDropdown, 41);
      24. while (1) {
      25. GUI_Delay(50);
      26. }
      27. }
      Display All
      Alex.