Răsfoiți Sursa

TreeView expand now works

Marko Pintera 12 ani în urmă
părinte
comite
b5d74cbb33

+ 12 - 0
CamelotClient/Include/CmTestTextSprite.h

@@ -22,6 +22,18 @@ namespace BansheeEditor
 		GUISceneTreeView* mSceneTreeView;
 		CM::HString labelString;
 
+		CM::HSceneObject mDbgMainA;
+		CM::HSceneObject mDbgMainB;
+
+		CM::HSceneObject mDbgChildA;
+		CM::HSceneObject mDbgChildB;
+		CM::HSceneObject mDbgChildC;
+
 		void dbgBtn();
+
+		void dbgAdd();
+		void dbgRename();
+		void dbgRemoveChildren();
+		void dbgRemoveParents();
 	};
 }

+ 4 - 0
CamelotClient/Source/BsEditorGUI.cpp

@@ -643,6 +643,10 @@ namespace BansheeEditor
 		treeViewExpandButtonStyle.normalOn.texture = getTexture(TreeViewExpandButtonOnNormal);
 		treeViewExpandButtonStyle.hoverOn.texture = getTexture(TreeViewExpandButtonOnHover);
 		treeViewExpandButtonStyle.activeOn.texture = treeViewExpandButtonStyle.hoverOn.texture;
+		treeViewExpandButtonStyle.margins.left = 4;
+		treeViewExpandButtonStyle.margins.right = 4;
+		treeViewExpandButtonStyle.margins.top = 5;
+		treeViewExpandButtonStyle.margins.bottom = 4;
 		treeViewExpandButtonStyle.fixedHeight = true;
 		treeViewExpandButtonStyle.fixedWidth = true;
 		treeViewExpandButtonStyle.height = 16;

+ 56 - 36
CamelotClient/Source/BsGUISceneTreeView.cpp

@@ -224,9 +224,9 @@ namespace BansheeEditor
 			{
 				if(updateElement.visible)
 				{
+					HString name(toWString(current->mName));
 					if(current->mElement == nullptr)
 					{
-						HString name(toWString(current->mName));
 						current->mElement = GUILabel::create(_getParentWidget(), name, mElementBtnStyle);
 					}
 
@@ -246,6 +246,8 @@ namespace BansheeEditor
 							current->mFoldoutBtn = nullptr;
 						}
 					}
+
+					current->mElement->setContent(GUIContent(name));
 				}
 				else
 				{
@@ -319,16 +321,22 @@ namespace BansheeEditor
 				const TreeElement* current = currentUpdateElement.element;
 				todo.pop();
 
+				INT32 yOffset = 0;
 				if(current->mElement != nullptr)
 				{
 					Vector2I curOptimalSize = current->mElement->_getOptimalSize();
 					optimalSize.x = std::max(optimalSize.x, 
 						(INT32)(INITIAL_INDENT_OFFSET + curOptimalSize.x + currentUpdateElement.indent * INDENT_SIZE));
-					optimalSize.y += curOptimalSize.y + ELEMENT_EXTRA_SPACING;
+					yOffset = curOptimalSize.y + ELEMENT_EXTRA_SPACING;
 				}
 
+				optimalSize.y += yOffset;
+
 				for(auto& child : current->mChildren)
 				{
+					if(!child->mIsVisible)
+						continue;
+
 					todo.push(UpdateTreeElement(child, currentUpdateElement.indent + 1));
 				}
 			}
@@ -394,53 +402,65 @@ namespace BansheeEditor
 			UINT32 indent = currentUpdateElement.indent;
 			todo.pop();
 
-			tempOrderedElements.resize(current->mChildren.size(), nullptr);
-			for(auto& child : current->mChildren)
+			INT32 btnHeight = 0;
+			INT32 yOffset = 0;
+			if(current->mElement != nullptr)
 			{
-				tempOrderedElements[child->mSortedIdx] = child;
-			}
+				Vector2I elementSize = current->mElement->_getOptimalSize();
+				btnHeight = elementSize.y;
 
-			for(auto& child : tempOrderedElements)
-			{
-				if(!child->mIsVisible)
-					continue;
+				offset.x = INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
 
-				INT32 yOffset = 0;
-				if(child->mElement != nullptr)
-				{
-					Vector2I elementSize = child->mElement->_getOptimalSize();
+				current->mElement->_setOffset(offset);
+				current->mElement->_setWidth(elementSize.x);
+				current->mElement->_setHeight(elementSize.y);
+				current->mElement->_setAreaDepth(areaDepth);
+				current->mElement->_setWidgetDepth(widgetDepth);
 
-					offset.x = INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
+				RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
+				current->mElement->_setClipRect(elemClipRect);
 
-					child->mElement->_setOffset(offset);
-					child->mElement->_setWidth(elementSize.x);
-					child->mElement->_setHeight(elementSize.y);
-					child->mElement->_setAreaDepth(areaDepth);
-					child->mElement->_setWidgetDepth(widgetDepth);
+				yOffset = btnHeight + ELEMENT_EXTRA_SPACING;
+			}
 
-					RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-					child->mElement->_setClipRect(elemClipRect);
+			if(current->mFoldoutBtn != nullptr)
+			{
+				Vector2I elementSize = current->mFoldoutBtn->_getOptimalSize();
 
-					yOffset = elementSize.y + ELEMENT_EXTRA_SPACING;
-				}
+				offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.y);
 
-				if(child->mFoldoutBtn != nullptr)
+				Vector2I myOffset = offset;
+				if(elementSize.y > btnHeight)
 				{
-					Vector2I elementSize = child->mFoldoutBtn->_getOptimalSize();
+					UINT32 diff = elementSize.y - btnHeight;
+					float half = diff * 0.5f;
+					myOffset.y -= Math::floorToInt(half);
+				}
 
-					offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.y);
+				current->mFoldoutBtn->_setOffset(myOffset);
+				current->mFoldoutBtn->_setWidth(elementSize.x);
+				current->mFoldoutBtn->_setHeight(elementSize.y);
+				current->mFoldoutBtn->_setAreaDepth(areaDepth);
+				current->mFoldoutBtn->_setWidgetDepth(widgetDepth);
 
-					child->mFoldoutBtn->_setOffset(offset);
-					child->mFoldoutBtn->_setWidth(elementSize.x);
-					child->mFoldoutBtn->_setHeight(elementSize.y);
-					child->mFoldoutBtn->_setAreaDepth(areaDepth);
-					child->mFoldoutBtn->_setWidgetDepth(widgetDepth);
+				RectI elemClipRect(clipRect.x - myOffset.x, clipRect.y - myOffset.y, clipRect.width, clipRect.height);
+				current->mFoldoutBtn->_setClipRect(elemClipRect);
+			}
 
-					RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
-					child->mFoldoutBtn->_setClipRect(elemClipRect);
-				}
+			offset.y += yOffset;
+
+			tempOrderedElements.resize(current->mChildren.size(), nullptr);
+			for(auto& child : current->mChildren)
+			{
+				tempOrderedElements[child->mSortedIdx] = child;
+			}
 
-				offset.y += yOffset;
+			for(auto iter = tempOrderedElements.rbegin(); iter != tempOrderedElements.rend(); ++iter)
+			{
+				TreeElement* child = *iter;
+
+				if(!child->mIsVisible)
+					continue;
 
 				todo.push(UpdateTreeElement(child, indent + 1));
 			}

+ 49 - 1
CamelotClient/Source/CmTestTextSprite.cpp

@@ -54,7 +54,7 @@ namespace BansheeEditor
 		sceneTreeViewLayout.addElement(mSceneTreeView);
 		sceneTreeViewLayout.addFlexibleSpace();
 
-		//area->getLayout().addElement(GUIRenderTexture::create(*this, sceneView, GUIOptions(GUIOption::fixedWidth(800), GUIOption::fixedHeight(600))));
+		area->getLayout().addElement(GUIRenderTexture::create(*this, sceneView, GUIOptions(GUIOption::fixedWidth(800), GUIOption::fixedHeight(600))));
 		//mLabel = GUILabel::create(*this, HString(L""));
 		//area->getLayout().addElement(mLabel);
 
@@ -69,6 +69,22 @@ namespace BansheeEditor
 		button->onClick.connect(boost::bind(&TestTextSprite::dbgBtn, this));
 		area->getLayout().addElement(button);
 
+		button = GUIButton::create(*this, HString(L"Add GameObjects"));
+		button->onClick.connect(boost::bind(&TestTextSprite::dbgAdd, this));
+		area->getLayout().addElement(button);
+
+		button = GUIButton::create(*this, HString(L"Rename GameObject"));
+		button->onClick.connect(boost::bind(&TestTextSprite::dbgRename, this));
+		area->getLayout().addElement(button);
+
+		button = GUIButton::create(*this, HString(L"Remove child GameObjects"));
+		button->onClick.connect(boost::bind(&TestTextSprite::dbgRemoveChildren, this));
+		area->getLayout().addElement(button);
+
+		button = GUIButton::create(*this, HString(L"Remove parent GameObjects"));
+		button->onClick.connect(boost::bind(&TestTextSprite::dbgRemoveParents, this));
+		area->getLayout().addElement(button);
+
 		area->getLayout().addFlexibleSpace();
 
 		labelString = HString(L"\\{0}, {1}");
@@ -105,4 +121,36 @@ namespace BansheeEditor
 
 		dbg++;
 	}
+
+	void TestTextSprite::dbgAdd()
+	{
+		mDbgMainA = SceneObject::create("DEBUG_A");
+		mDbgChildA = SceneObject::create("DEBUG_CHILD_0");
+		mDbgChildA->setParent(mDbgMainA);
+
+		mDbgChildB = SceneObject::create("DEBUG_CHILD_1");
+		mDbgChildB->setParent(mDbgMainA);
+
+		mDbgChildC = SceneObject::create("DEBUG_CHILD_2");
+		mDbgChildC->setParent(mDbgMainA);
+
+		mDbgMainB = SceneObject::create("DEBUG_B");
+	}
+
+	void TestTextSprite::dbgRename()
+	{
+		mDbgMainA->setName("Z_DEBUG_RENAMED_A");
+	}
+
+	void TestTextSprite::dbgRemoveChildren()
+	{
+		mDbgChildA->destroy();
+		mDbgChildB->destroy();
+	}
+
+	void TestTextSprite::dbgRemoveParents()
+	{
+		mDbgMainA->destroy();
+		mDbgMainB->destroy();
+	}
 }

+ 2 - 0
CamelotCore/Include/CmSceneObject.h

@@ -22,6 +22,8 @@ namespace CamelotFramework
 		UINT32 getId() const { return mId; }
 		const String& getName() const { return mName; }
 
+		void setName(const String& name) { mName = name; }
+
 	private:
 		HSceneObject mThisHandle;