fix menu navigation

This commit is contained in:
Vadim Lopatin 2014-05-12 09:32:27 +04:00
parent 374b5bb058
commit 45cafad1cb
2 changed files with 26 additions and 11 deletions

View File

@ -308,10 +308,11 @@ extern (C) int UIAppMain(string[] args) {
//========================================================================== //==========================================================================
tabs.selectTab("tab3");
contentLayout.addChild(tabs); contentLayout.addChild(tabs);
window.mainWidget = contentLayout; window.mainWidget = contentLayout;
tabs.selectTab("tab3");
} else { } else {
window.mainWidget = (new Button()).text("sample button"); window.mainWidget = (new Button()).text("sample button");
} }

View File

@ -311,12 +311,12 @@ class MenuWidgetBase : ListWidget {
if (_openedPopup) { if (_openedPopup) {
if (_openedPopup is p) { if (_openedPopup is p) {
_openedMenu.onPopupClosed(p); _openedMenu.onPopupClosed(p);
bool undoSelection = _openedPopupIndex == _selectedItemIndex; //bool undoSelection = _openedPopupIndex == _selectedItemIndex;
_openedPopup = null; _openedPopup = null;
_openedMenu = null; _openedMenu = null;
if (undoSelection) { //if (undoSelection) {
performUndoSelection(); // performUndoSelection();
} //}
if (!isMainMenu) if (!isMainMenu)
window.setFocus(this); window.setFocus(this);
} else if (thisPopup is p) { } else if (thisPopup is p) {
@ -327,7 +327,15 @@ class MenuWidgetBase : ListWidget {
protected void openSubmenu(int index, MenuItemWidget itemWidget, bool selectFirstItem) { protected void openSubmenu(int index, MenuItemWidget itemWidget, bool selectFirstItem) {
if (_openedPopup !is null) { if (_openedPopup !is null) {
_openedPopup.close(); if (_openedPopupIndex == index) {
if (selectFirstItem) {
window.setFocus(_openedMenu);
_openedMenu.selectItem(0);
}
return;
} else {
_openedPopup.close();
}
} }
PopupMenu popupMenu = new PopupMenu(itemWidget.item, this); PopupMenu popupMenu = new PopupMenu(itemWidget.item, this);
PopupWidget popup = window.showPopup(popupMenu, itemWidget, orientation == Orientation.Horizontal ? PopupAlign.Below : PopupAlign.Right); PopupWidget popup = window.showPopup(popupMenu, itemWidget, orientation == Orientation.Horizontal ? PopupAlign.Below : PopupAlign.Right);
@ -336,14 +344,17 @@ class MenuWidgetBase : ListWidget {
_openedPopup = popup; _openedPopup = popup;
_openedMenu = popupMenu; _openedMenu = popupMenu;
_openedPopupIndex = index; _openedPopupIndex = index;
window.setFocus(popupMenu); if (selectFirstItem) {
if (selectFirstItem) window.setFocus(popupMenu);
_openedMenu.selectItem(0); _openedMenu.selectItem(0);
}
} }
/// override to handle change of selection /// override to handle change of selection
override protected void selectionChanged(int index, int previouslySelectedItem = -1) { override protected void selectionChanged(int index, int previouslySelectedItem = -1) {
debug Log.d("menu.selectionChanged ", index, ", ", previouslySelectedItem, " _selectedItemIndex=", _selectedItemIndex); debug Log.d("menu.selectionChanged ", index, ", ", previouslySelectedItem, " _selectedItemIndex=", _selectedItemIndex);
if (index >= 0)
setFocus();
MenuItemWidget itemWidget = index >= 0 ? cast(MenuItemWidget)_adapter.itemWidget(index) : null; MenuItemWidget itemWidget = index >= 0 ? cast(MenuItemWidget)_adapter.itemWidget(index) : null;
MenuItemWidget prevWidget = previouslySelectedItem >= 0 ? cast(MenuItemWidget)_adapter.itemWidget(previouslySelectedItem) : null; MenuItemWidget prevWidget = previouslySelectedItem >= 0 ? cast(MenuItemWidget)_adapter.itemWidget(previouslySelectedItem) : null;
if (prevWidget !is null) { if (prevWidget !is null) {
@ -400,7 +411,7 @@ class MenuWidgetBase : ListWidget {
// second click on main menu opened item // second click on main menu opened item
_openedPopup.close(); _openedPopup.close();
_openedPopup = null; _openedPopup = null;
selectItem(-1); //selectItem(-1);
selectOnHover = false; selectOnHover = false;
} else { } else {
openSubmenu(index, itemWidget, _orientation == Orientation.Horizontal); // for main menu, select first item openSubmenu(index, itemWidget, _orientation == Orientation.Horizontal); // for main menu, select first item
@ -434,8 +445,11 @@ class MenuWidgetBase : ListWidget {
if (_parentMenu !is null) { if (_parentMenu !is null) {
if (_parentMenu.orientation == Orientation.Vertical) { if (_parentMenu.orientation == Orientation.Vertical) {
if (thisPopup !is null) { if (thisPopup !is null) {
//int selectedItem = _selectedItemIndex;
// back to parent menu on Left key // back to parent menu on Left key
thisPopup.close(); thisPopup.close();
//if (selectedItem >= 0)
// selectItem(selectedItem);
return true; return true;
} }
} else { } else {