I am trying out the different widgets available in emWin and as part of my testing I am attempting to make a submenu of a submenu using the following code:
<span class="Apple-tab-span" style="white-space: pre;"> </span>hSubMenu = MENU_CreateEx(0,0,85,105,0,WM_CF_SHOW, MENU_CF_VERTICAL, ID_MENU_0_SUB_ALARM);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hItem, "Alarms", ID_MENU_0_SUB_ALARM, 0, hSubMenu);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu, "View Active", ID_MENU_ALARM_VIEW, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu, "Clear All", ID_MENU_ALARM_CLEAR, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>hSubMenu2 = MENU_CreateEx(70,15,80,55,0,WM_CF_SHOW, MENU_CF_VERTICAL, ID_MENU_ALARM_TEMP_SENSOR);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu, "Temp Sensors >", ID_MENU_ALARM_TEMP_SENSOR, 0, hSubMenu2);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu2, "Temp Sensor 1", ID_ALARM_TS1, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu2, "Temp Sensor 2", ID_ALARM_TS2, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu2, "Temp Sensor 3", ID_ALARM_TS3, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu, "Current", ID_MENU_ALARM_CURRENT, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu, "Voltage", ID_MENU_ALARM_VOLTAGE, 0, 0);
<span class="Apple-tab-span" style="white-space: pre;"> </span>AddMenuItem(hSubMenu, "Resistance", ID_MENU_ALARM_RESIST, 0, 0);
Unfortunately the 2nd level of submenu isnt offset correctly from the parent menu as shown in this image.
I have tried adding an offset when creating the submenu as in the code above, but this didnt seem to have any effect. Am I doing something wrong or is this just not possible with emWin?
I think I have uncovered a bug in the menu widget.
If you take the example Menu application that you posted and add the File menu last then the submenu for "Files..." shows incorrectly
Source snippet:
// Add menu items to main menu
_AddMenuItem(hMenu, hMenuEdit, "Edit", 0, 0);
_AddMenuItem(hMenu, hMenuHelp, "Help", 0, 0);
_AddMenuItem(hMenu, hMenuFile, "File", 0, 0);
// Attach menu to parent window
FRAMEWIN_AddMenu(hParent, hMenu);
Result:
<span class="inline inline-left"><img class="image image-preview " src="http://lpcware.com/system/files/images/menu%20misalign.png" border="0" alt="" title="" width="120" height="156" /></span>
The left hand edge of the "Files..." submenu lines up perfectly with the righthand edge of the first submenu (now "Edit") instead of its parent submenu.
Going back to my application confirms this. The Temp Sensor submenu is aligned with the righthand edge of my File submenu when it should be aligned to the Alarms menu.
EDIT:
Futher testing shows the "Files..." submenu is offset from the start of the main menu by the width of the "File" submenu. emWin is not taking the position of the parent submenu into account, only its width.
i.e. the x coordinate for the submenu is the width of its parent and not the x coordinate of its parent plus the width of the parent
Hi,
This indeed does not look right. You may want to have a look at Segger's example "Menu widget demo", the "File->Files..." menu uses submenus.
Executable: http://www.segger.com/admin/uploads/userfiles/file/emWin/tutorials/WIDGET_Menu.exe
Source: http://www.segger.com/admin/uploads/userfiles/file/emWin/tutorials/src/WIDGET_Menu.c
From: http://www.segger.com/emwin-samples.html
Regards,
Wouter