Просмотр исходного кода

Setup UITrees and UITreeContainers to differentiate between node selection by keyboard and by mouse. Removed ability to optionally select a node in UITreeContainer::scrollToNode() method. Removed ability to travel to first child node via right arrow key (use down).

Ethan M 12 лет назад
Родитель
Сommit
caaa0c85ad

+ 5 - 1
Modules/Contents/UI/Include/PolyUITree.h

@@ -54,7 +54,7 @@ namespace Polycode {
 			void setUserData(void *data);
 			UITree *getSelectedNode();
 			void setIcon(String iconFile);
-			void setSelected();
+			void setSelected(bool byKey=false);
 			
 			void setLabelText(const String &text);
 			
@@ -74,6 +74,8 @@ namespace Polycode {
 			UITree *getPrevSibling();
 			UITree *getNextSibling();
 			Number getCellHeight() { return cellHeight; }
+
+			bool isSelectedByKey() { return selectedByKey; }
 		
 		private:
 
@@ -104,5 +106,7 @@ namespace Polycode {
 			int size;
 			Number cellHeight;
 			Number cellPadding;
+
+			bool selectedByKey;
 	};
 }

+ 1 - 2
Modules/Contents/UI/Include/PolyUITreeContainer.h

@@ -47,9 +47,8 @@ namespace Polycode {
 		 * Scrolls the container to show a specified node.
 		 * @param node The tree node to scroll to or show.
 		 * @param showAtTop If true, show the node at the top of the container. If false, show it at the bottom.
-		 * @param select If true (default), select the node. If false, don't.
 		 */
-		void scrollToNode(UITree *node, bool showAtTop, bool select=true);
+		void scrollToNode(UITree *node, bool showAtTop);
 		
 	protected:
 		bool keyNavigable;

+ 2 - 1
Modules/Contents/UI/Source/PolyUITree.cpp

@@ -145,7 +145,8 @@ void UITree::removeTreeChild(UITree *child) {
 	}
 }
 
-void UITree::setSelected() {
+void UITree::setSelected(bool byKey) {
+	selectedByKey = byKey;
 	selected = true;
 	refreshTree();
 	if(parent == NULL) {

+ 8 - 15
Modules/Contents/UI/Source/PolyUITreeContainer.cpp

@@ -167,9 +167,9 @@ void UITreeContainer::onKeyDown(PolyKEY key, wchar_t charCode) {
 					for (int i=0; i < parent->getNumTreeChildren(); i++) {
 						if (parent->getTreeChild(i) == currentSelection) {
 							if (i == 0)
-								parent->setSelected();
+								parent->setSelected(true);
 							else
-								findLastOpenNode((parent->getTreeChild(i-1)))->setSelected();
+								findLastOpenNode((parent->getTreeChild(i-1)))->setSelected(true);
 							scrollDir = UP;
 							break;
 						}
@@ -185,7 +185,7 @@ void UITreeContainer::onKeyDown(PolyKEY key, wchar_t charCode) {
 					parent = getRootNode();
 
 				if (currentSelection->hasTreeChildren() && !currentSelection->isCollapsed()) {
-					currentSelection->getTreeChild(0)->setSelected();
+					currentSelection->getTreeChild(0)->setSelected(true);
 					scrollDir = DOWN;
 				}
 				else {
@@ -194,9 +194,9 @@ void UITreeContainer::onKeyDown(PolyKEY key, wchar_t charCode) {
 							if (i == parent->getNumTreeChildren()-1) {
 								UITree *psib = findNextParentSibling(parent);
 								if (psib)
-									psib->setSelected();
+									psib->setSelected(true);
 							} else {
-								parent->getTreeChild(i+1)->setSelected();
+								parent->getTreeChild(i+1)->setSelected(true);
 							}
 							scrollDir = DOWN;
 							break;
@@ -209,7 +209,7 @@ void UITreeContainer::onKeyDown(PolyKEY key, wchar_t charCode) {
 				if (currentSelection->hasTreeChildren() && !currentSelection->isCollapsed())
 					currentSelection->toggleCollapsed();
 				else if (parent) {
-					parent->setSelected();
+					parent->setSelected(true);
 					scrollDir = UP;
 				}
 			}
@@ -218,15 +218,11 @@ void UITreeContainer::onKeyDown(PolyKEY key, wchar_t charCode) {
 				if (currentSelection->hasTreeChildren()) {
 					if (currentSelection->isCollapsed())
 						currentSelection->toggleCollapsed();
-					else {
-						currentSelection->getTreeChild(0)->setSelected();
-						scrollDir = DOWN;
-					}
 				}
 			}
 			
 			if (scrollDir != NONE)
-				scrollToNode(getRootNode()->getSelectedNode(), (scrollDir == UP) ? true : false, false);
+				scrollToNode(getRootNode()->getSelectedNode(), (scrollDir == UP) ? true : false);
 		}
 		//
 		// END KEYBOARD NAV STUFF
@@ -234,7 +230,7 @@ void UITreeContainer::onKeyDown(PolyKEY key, wchar_t charCode) {
 	}
 }
 
-void UITreeContainer::scrollToNode(UITree *node, bool showAtTop, bool select) {
+void UITreeContainer::scrollToNode(UITree *node, bool showAtTop) {
 	
 	Number nodeY = node->getScreenPosition().y - getRootNode()->getScreenPosition().y;
 	Number contentHeight = mainContainer->getContentSize().y;
@@ -242,9 +238,6 @@ void UITreeContainer::scrollToNode(UITree *node, bool showAtTop, bool select) {
 	Number viewTop = (contentHeight - mainContainer->getHeight()) * mainContainer->getVScrollBar()->getScrollValue();
 	Number viewBottom = viewTop + mainContainer->getHeight();
 	
-	if (select)
-		node->setSelected();
-	
 	if (nodeY < viewTop || nodeY+node->getCellHeight() > viewBottom) {
 		if (showAtTop)
 			mainContainer->scrollVertical((nodeY-viewTop) / scrollHeight);