MENU: Menu widget - visual changes in version 5.48

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

    • MENU: Menu widget - visual changes in version 5.48

      Hello.

      In all versions of emWin until 5.46 (including) the functionality of MENU widget was realized in following way:

      If to the root menu are added some hierarchical levels of submenus (for example, the depth of hierarchy is 5 of even more), then all nested submenus, beginning from third level, are placing on the screen overlapped previous submenu level. This gives a good and useful possibility to make many-level hierarchical tree of menu, where all its submenus are placed on the screen with full access to each item of each submenu (see picture 1).

      But since version 5.48 this "overlapping" behaviour was changed to "side-by-side" placement behaviour. It makes impossible to create menus with depth of hierarchy more than 3 or 4. All next levels are placed out of screen on its right side (see picture 2).

      Could you please return previous behaviour of menu widget, or to give possibility to choose one of two ways - as new one as well as old one.


      But even better way is to realize possibility to place manually (through x0, y0 parameters in MENU_CreateEx) of every submenu area according its parent submenu, where this parent submenu could be also given to this function as its already existing parameter "hParent".
      Images
      • menu_5.38.png

        43.41 kB, 710×630, viewed 394 times
      • menu_5.48.png

        41.5 kB, 710×630, viewed 443 times
      Best regards,
      Volodymyr.

      The post was edited 6 times, last by volodymyr ().

    • Hi,

      You can set a callback for each menu and react on WM_MENU and MENU_ON_OPEN. Now you can move the window (the menu) to any position.

      You can use this one as a reference:

      C Source Code

      1. static void _cbMenu(WM_MESSAGE * pMsg) {
      2. MENU_MSG_DATA * pData;
      3. int xPos;
      4. int yPos;
      5. const WIDGET_EFFECT * pEffect;
      6. switch (pMsg->MsgId) {
      7. case WM_MENU:
      8. MENU_Callback(pMsg);
      9. pData = (MENU_MSG_DATA *)pMsg->Data.p;
      10. switch (pData->MsgType) {
      11. case MENU_ON_OPEN:
      12. //
      13. // Get effect to get the size of it
      14. //
      15. pEffect = MENU_GetDefaultEffect();
      16. //
      17. // Calculate the new position
      18. //
      19. xPos = WM_GetWindowOrgX(pMsg->hWinSrc) + WM_GetWindowSizeX(pMsg->hWinSrc) - pEffect->EffectSize;
      20. yPos = WM_GetWindowOrgY(pMsg->hWinSrc) - WM_GetWindowSizeY(pMsg->hWin) / 2;
      21. //
      22. // Use the calculated position or use any other position
      23. //
      24. WM_MoveTo(pMsg->hWin, xPos, yPos);
      25. break;
      26. }
      27. break;
      28. default:
      29. MENU_Callback(pMsg);
      30. break;
      31. }
      32. }
      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.
    • Hello.

      Thank you for the answer.

      I tried to run your code, but it gives on line 11 the following runtime error:
      Unhandled exception thrown: read access violation.
      pData was 0x1.

      However followindg code runs OK:

      Source Code

      1. static void cbMenu(WM_MESSAGE * pMsg) {
      2. MENU_MSG_DATA * pData;
      3. int xPosSrc, yPosSrc;
      4. switch (pMsg->MsgId) {
      5. case WM_MENU:
      6. pData = (MENU_MSG_DATA*)pMsg->Data.p;
      7. MENU_Callback(pMsg);
      8. switch (pData->MsgType) {
      9. case MENU_ON_OPEN:
      10. MENU_Callback(pMsg);
      11. xPosSrc = WM_GetWindowOrgX(pMsg->hWinSrc);
      12. yPosSrc = WM_GetWindowOrgY(pMsg->hWinSrc);
      13. WM_MoveTo(pMsg->hWin, xPosSrc + 40, yPosSrc + 20);
      14. break;
      15. }
      16. break;
      17. default:
      18. MENU_Callback(pMsg);
      19. break;
      20. }
      21. }
      Display All

      Thus I have one question - how to get xPos, yPos of current selected item of menu?
      Images
      • menu_positioning.png

        38.67 kB, 710×630, viewed 309 times
      Best regards,
      Volodymyr.

      The post was edited 4 times, last by volodymyr ().