2
0

BsGUITreeView.cpp 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385
  1. #include "BsGUITreeView.h"
  2. #include "BsGUILayout.h"
  3. #include "BsGUITexture.h"
  4. #include "BsGUIButton.h"
  5. #include "BsGUILabel.h"
  6. #include "BsGUISpace.h"
  7. #include "BsCGUIWidget.h"
  8. #include "BsGUIToggle.h"
  9. #include "BsGUITreeViewEditBox.h"
  10. #include "BsGUIMouseEvent.h"
  11. #include "BsGUISkin.h"
  12. #include "BsGUICommandEvent.h"
  13. #include "BsGUIVirtualButtonEvent.h"
  14. #include "BsGUIScrollArea.h"
  15. #include "BsDragAndDropManager.h"
  16. #include "BsTime.h"
  17. using namespace std::placeholders;
  18. namespace BansheeEngine
  19. {
  20. const UINT32 GUITreeView::ELEMENT_EXTRA_SPACING = 3;
  21. const UINT32 GUITreeView::INDENT_SIZE = 10;
  22. const UINT32 GUITreeView::INITIAL_INDENT_OFFSET = 16;
  23. const UINT32 GUITreeView::DRAG_MIN_DISTANCE = 3;
  24. const float GUITreeView::AUTO_EXPAND_DELAY_SEC = 0.5f;
  25. const float GUITreeView::SCROLL_AREA_HEIGHT_PCT = 0.1f;
  26. const UINT32 GUITreeView::SCROLL_SPEED_PX_PER_SEC = 100;
  27. const Color GUITreeView::GRAYED_OUT_COLOR = Color(1.0f, 1.0f, 1.0f, 0.5f);
  28. VirtualButton GUITreeView::mRenameVB = VirtualButton("Rename");
  29. VirtualButton GUITreeView::mDeleteVB = VirtualButton("Delete");
  30. VirtualButton GUITreeView::mDuplicateVB = VirtualButton("Duplicate");
  31. VirtualButton GUITreeView::mCutVB = VirtualButton("Cut");
  32. VirtualButton GUITreeView::mCopyVB = VirtualButton("Copy");
  33. VirtualButton GUITreeView::mPasteVB = VirtualButton("Paste");
  34. GUITreeView::TreeElement::TreeElement()
  35. :mParent(nullptr), mFoldoutBtn(nullptr), mElement(nullptr), mIsSelected(false),
  36. mIsExpanded(false), mSortedIdx(0), mIsVisible(true), mIsHighlighted(false), mIsGrayedOut(false)
  37. { }
  38. GUITreeView::TreeElement::~TreeElement()
  39. {
  40. for(auto& child : mChildren)
  41. bs_delete(child);
  42. if(mFoldoutBtn != nullptr)
  43. GUIElement::destroy(mFoldoutBtn);
  44. if(mElement != nullptr)
  45. GUIElement::destroy(mElement);
  46. mChildren.clear();
  47. }
  48. bool GUITreeView::TreeElement::isParentRec(TreeElement* element) const
  49. {
  50. TreeElement* curParent = mParent;
  51. while(curParent != nullptr)
  52. {
  53. if(curParent == element)
  54. return true;
  55. curParent = curParent->mParent;
  56. }
  57. return false;
  58. }
  59. GUITreeView::TreeElement* GUITreeView::InteractableElement::getTreeElement() const
  60. {
  61. if(!isTreeElement())
  62. return nullptr;
  63. UINT32 sortedIdx = (index - 1) / 2;
  64. auto findIter = std::find_if(parent->mChildren.begin(), parent->mChildren.end(),
  65. [&](const TreeElement* x) { return x->mSortedIdx == sortedIdx; });
  66. if(findIter != parent->mChildren.end())
  67. return *findIter;
  68. return nullptr;
  69. }
  70. GUITreeView::GUITreeView(const String& backgroundStyle, const String& elementBtnStyle,
  71. const String& foldoutBtnStyle, const String& selectionBackgroundStyle, const String& highlightBackgroundStyle,
  72. const String& editBoxStyle, const String& dragHighlightStyle, const String& dragSepHighlightStyle, const GUIDimensions& dimensions)
  73. :GUIElementContainer(dimensions), mBackgroundStyle(backgroundStyle),
  74. mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr), mIsElementSelected(false),
  75. mNameEditBox(nullptr), mHighlightBackgroundStyle(highlightBackgroundStyle), mSelectionBackgroundStyle(selectionBackgroundStyle), mDragInProgress(nullptr),
  76. mDragHighlightStyle(dragHighlightStyle), mDragSepHighlightStyle(dragSepHighlightStyle), mDragHighlight(nullptr), mDragSepHighlight(nullptr), mMouseOverDragElement(nullptr),
  77. mMouseOverDragElementTime(0.0f), mScrollState(ScrollState::None), mLastScrollTime(0.0f), mIsElementHighlighted(false)
  78. {
  79. if(mBackgroundStyle == StringUtil::BLANK)
  80. mBackgroundStyle = "TreeViewBackground";
  81. if(mElementBtnStyle == StringUtil::BLANK)
  82. mElementBtnStyle = "TreeViewElementBtn";
  83. if(mFoldoutBtnStyle == StringUtil::BLANK)
  84. mFoldoutBtnStyle = "TreeViewFoldoutBtn";
  85. if(mSelectionBackgroundStyle == StringUtil::BLANK)
  86. mSelectionBackgroundStyle = "TreeViewSelectionBackground";
  87. if (mHighlightBackgroundStyle == StringUtil::BLANK)
  88. mHighlightBackgroundStyle = "TreeViewHighlightBackground";
  89. if(mEditBoxStyle == StringUtil::BLANK)
  90. mEditBoxStyle = "TreeViewEditBox";
  91. if(mDragHighlightStyle == StringUtil::BLANK)
  92. mDragHighlightStyle = "TreeViewElementHighlight";
  93. if(mDragSepHighlightStyle == StringUtil::BLANK)
  94. mDragSepHighlightStyle = "TreeViewElementSepHighlight";
  95. mBackgroundImage = GUITexture::create(mBackgroundStyle);
  96. mNameEditBox = GUITreeViewEditBox::create(mEditBoxStyle);
  97. mNameEditBox->disableRecursively();
  98. mNameEditBox->onInputConfirmed.connect(std::bind(&GUITreeView::onEditAccepted, this));
  99. mNameEditBox->onInputCanceled.connect(std::bind(&GUITreeView::onEditCanceled, this));
  100. mNameEditBox->onFocusLost.connect(std::bind(&GUITreeView::onEditFocusLost, this));
  101. mDragHighlight = GUITexture::create(mDragHighlightStyle);
  102. mDragSepHighlight = GUITexture::create(mDragSepHighlightStyle);
  103. mDragHighlight->disableRecursively();
  104. mDragSepHighlight->disableRecursively();
  105. mDragHighlight->_setElementDepth(2);
  106. mDragSepHighlight->_setElementDepth(2);
  107. _registerChildElement(mBackgroundImage);
  108. _registerChildElement(mNameEditBox);
  109. _registerChildElement(mDragHighlight);
  110. _registerChildElement(mDragSepHighlight);
  111. }
  112. GUITreeView::~GUITreeView()
  113. {
  114. }
  115. void GUITreeView::_update()
  116. {
  117. // Attempt to auto-expand elements we are dragging over
  118. if(acceptDragAndDrop())
  119. {
  120. const GUITreeView::InteractableElement* element = findElementUnderCoord(mDragPosition);
  121. temporarilyExpandElement(element);
  122. }
  123. // NOTE - Instead of iterating through every visible element and comparing it with internal values,
  124. // I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
  125. // update if anything is actually dirty
  126. updateTreeElementHierarchy();
  127. // Attempt to scroll if needed
  128. if(mScrollState != ScrollState::None)
  129. {
  130. GUIScrollArea* scrollArea = findParentScrollArea();
  131. if(scrollArea != nullptr)
  132. {
  133. float curTime = gTime().getTime();
  134. float timeDiff = curTime - mLastScrollTime;
  135. float secondsPerPixel = 1.0f / SCROLL_SPEED_PX_PER_SEC;
  136. switch(mScrollState)
  137. {
  138. case ScrollState::TransitioningUp:
  139. mScrollState = ScrollState::Up;
  140. mLastScrollTime = curTime;
  141. break;
  142. case ScrollState::TransitioningDown:
  143. mScrollState = ScrollState::Down;
  144. mLastScrollTime = curTime;
  145. break;
  146. case ScrollState::Up:
  147. {
  148. UINT32 scrollAmount = (UINT32)Math::floorToInt(timeDiff / secondsPerPixel);
  149. mLastScrollTime += scrollAmount * secondsPerPixel;
  150. scrollArea->scrollUpPx(scrollAmount);
  151. }
  152. break;
  153. case ScrollState::Down:
  154. {
  155. UINT32 scrollAmount = (UINT32)Math::floorToInt(timeDiff / secondsPerPixel);
  156. mLastScrollTime += scrollAmount * secondsPerPixel;
  157. scrollArea->scrollDownPx(scrollAmount);
  158. }
  159. break;
  160. }
  161. }
  162. }
  163. }
  164. bool GUITreeView::_mouseEvent(const GUIMouseEvent& event)
  165. {
  166. if(event.getType() == GUIMouseEventType::MouseUp)
  167. {
  168. if(DragAndDropManager::instance().isDragInProgress())
  169. return false;
  170. const GUITreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
  171. TreeElement* treeElement = nullptr;
  172. if(element != nullptr && element->isTreeElement())
  173. {
  174. treeElement = element->getTreeElement();
  175. }
  176. if (treeElement != nullptr)
  177. {
  178. bool onFoldout = false;
  179. if (treeElement->mFoldoutBtn != nullptr)
  180. onFoldout = treeElement->mFoldoutBtn->_getClippedBounds().contains(event.getPosition());
  181. bool onEditElement = false;
  182. if (mEditElement != nullptr)
  183. onEditElement = treeElement == mEditElement;
  184. if (!onFoldout && !onEditElement)
  185. {
  186. if (event.getButton() == GUIMouseButton::Left)
  187. {
  188. if (event.isCtrlDown())
  189. {
  190. selectElement(treeElement);
  191. }
  192. else if (event.isShiftDown())
  193. {
  194. if (isSelectionActive())
  195. {
  196. TreeElement* selectionRoot = mSelectedElements[0].element;
  197. unselectAll();
  198. auto iterStartFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  199. [&](const InteractableElement& x) { return x.parent == selectionRoot->mParent; });
  200. bool foundStart = false;
  201. bool foundEnd = false;
  202. for (; iterStartFind != mVisibleElements.end(); ++iterStartFind)
  203. {
  204. if (!iterStartFind->isTreeElement())
  205. continue;
  206. TreeElement* curElem = iterStartFind->getTreeElement();
  207. if (curElem == selectionRoot)
  208. {
  209. foundStart = true;
  210. break;
  211. }
  212. }
  213. auto iterEndFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  214. [&](const InteractableElement& x) { return &x == element; });
  215. if (iterEndFind != mVisibleElements.end())
  216. foundEnd = true;
  217. if (foundStart && foundEnd)
  218. {
  219. if (iterStartFind < iterEndFind)
  220. {
  221. for (; iterStartFind != (iterEndFind + 1); ++iterStartFind)
  222. {
  223. if (iterStartFind->isTreeElement())
  224. selectElement(iterStartFind->getTreeElement());
  225. }
  226. }
  227. else if (iterEndFind < iterStartFind)
  228. {
  229. for (; iterEndFind != (iterStartFind + 1); ++iterEndFind)
  230. {
  231. if (iterEndFind->isTreeElement())
  232. selectElement(iterEndFind->getTreeElement());
  233. }
  234. }
  235. else
  236. selectElement(treeElement);
  237. }
  238. if (!foundStart || !foundEnd)
  239. selectElement(treeElement);
  240. }
  241. else
  242. {
  243. selectElement(treeElement);
  244. }
  245. }
  246. else
  247. {
  248. bool doRename = false;
  249. if (isSelectionActive())
  250. {
  251. for (auto& selectedElem : mSelectedElements)
  252. {
  253. if (selectedElem.element == treeElement)
  254. {
  255. doRename = true;
  256. break;
  257. }
  258. }
  259. }
  260. unselectAll();
  261. selectElement(treeElement);
  262. if (doRename)
  263. renameSelected();
  264. }
  265. _markLayoutAsDirty();
  266. return true;
  267. }
  268. else if (event.getButton() == GUIMouseButton::Right)
  269. {
  270. unselectAll();
  271. selectElement(treeElement);
  272. _markLayoutAsDirty();
  273. return true;
  274. }
  275. }
  276. }
  277. else
  278. {
  279. unselectAll();
  280. return true;
  281. }
  282. }
  283. else if(event.getType() == GUIMouseEventType::MouseDragStart)
  284. {
  285. clearPing();
  286. mDragStartPosition = event.getPosition();
  287. }
  288. else if(event.getType() == GUIMouseEventType::MouseDrag)
  289. {
  290. UINT32 dist = mDragStartPosition.manhattanDist(event.getPosition());
  291. if(!DragAndDropManager::instance().isDragInProgress())
  292. {
  293. if(dist > DRAG_MIN_DISTANCE && mEditElement == nullptr)
  294. {
  295. const GUITreeView::InteractableElement* element = findElementUnderCoord(mDragStartPosition);
  296. TreeElement* treeElement = nullptr;
  297. if(element != nullptr && element->isTreeElement())
  298. {
  299. // If element we are trying to drag isn't selected, select it
  300. TreeElement* treeElement = element->getTreeElement();
  301. auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
  302. [&] (const SelectedElement& x) { return x.element == treeElement; });
  303. if(iterFind == mSelectedElements.end())
  304. {
  305. unselectAll();
  306. selectElement(element->getTreeElement());
  307. }
  308. }
  309. dragAndDropStart();
  310. mDragPosition = event.getPosition();
  311. mDragInProgress = true;
  312. mScrollState = ScrollState::None;
  313. _markLayoutAsDirty();
  314. }
  315. }
  316. }
  317. else if(event.getType() == GUIMouseEventType::MouseDragAndDropDragged)
  318. {
  319. if(acceptDragAndDrop())
  320. {
  321. clearPing();
  322. mDragPosition = event.getPosition();
  323. mDragInProgress = true;
  324. _markLayoutAsDirty();
  325. if(mBottomScrollBounds.contains(mDragPosition))
  326. {
  327. if(mScrollState != ScrollState::Down)
  328. mScrollState = ScrollState::TransitioningDown;
  329. }
  330. else if(mTopScrollBounds.contains(mDragPosition))
  331. {
  332. if(mScrollState != ScrollState::Up)
  333. mScrollState = ScrollState::TransitioningUp;
  334. }
  335. else
  336. mScrollState = ScrollState::None;
  337. return true;
  338. }
  339. }
  340. else if(event.getType() == GUIMouseEventType::MouseDragAndDropDropped)
  341. {
  342. if(acceptDragAndDrop())
  343. {
  344. const GUITreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
  345. TreeElement* treeElement = nullptr;
  346. if(element != nullptr)
  347. {
  348. if(element->isTreeElement())
  349. treeElement = element->getTreeElement();
  350. else
  351. treeElement = element->parent;
  352. }
  353. dragAndDropEnded(treeElement);
  354. unselectAll();
  355. return true;
  356. }
  357. }
  358. else if(event.getType() == GUIMouseEventType::MouseOut)
  359. {
  360. mDragInProgress = false;
  361. _markLayoutAsDirty();
  362. }
  363. return false;
  364. }
  365. bool GUITreeView::_commandEvent(const GUICommandEvent& ev)
  366. {
  367. if(ev.getType() == GUICommandEventType::MoveUp || ev.getType() == GUICommandEventType::SelectUp)
  368. {
  369. TreeElement* topMostElement = getTopMostSelectedElement();
  370. auto topMostIter = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  371. [&] (const InteractableElement& x) { return x.getTreeElement() == topMostElement; });
  372. if(topMostIter != mVisibleElements.end() && topMostIter != mVisibleElements.begin())
  373. {
  374. do
  375. {
  376. topMostIter--;
  377. } while (!topMostIter->isTreeElement() && topMostIter != mVisibleElements.begin());
  378. if(topMostIter->isTreeElement())
  379. {
  380. if(ev.getType() == GUICommandEventType::MoveUp)
  381. unselectAll();
  382. TreeElement* treeElement = topMostIter->getTreeElement();
  383. selectElement(treeElement);
  384. scrollToElement(treeElement, false);
  385. }
  386. }
  387. }
  388. else if(ev.getType() == GUICommandEventType::MoveDown || ev.getType() == GUICommandEventType::SelectDown)
  389. {
  390. TreeElement* bottoMostElement = getBottomMostSelectedElement();
  391. auto bottomMostIter = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  392. [&] (const InteractableElement& x) { return x.getTreeElement() == bottoMostElement; });
  393. if(bottomMostIter != mVisibleElements.end())
  394. {
  395. do
  396. {
  397. bottomMostIter++;
  398. } while (bottomMostIter != mVisibleElements.end() && !bottomMostIter->isTreeElement());
  399. if(bottomMostIter != mVisibleElements.end() && bottomMostIter->isTreeElement())
  400. {
  401. if(ev.getType() == GUICommandEventType::MoveDown)
  402. unselectAll();
  403. TreeElement* treeElement = bottomMostIter->getTreeElement();
  404. selectElement(treeElement);
  405. scrollToElement(treeElement, false);
  406. }
  407. }
  408. }
  409. return GUIElementContainer::_commandEvent(ev);
  410. }
  411. bool GUITreeView::_virtualButtonEvent(const GUIVirtualButtonEvent& ev)
  412. {
  413. if(ev.getButton() == mRenameVB)
  414. {
  415. renameSelected();
  416. return true;
  417. }
  418. else if(ev.getButton() == mDeleteVB)
  419. {
  420. deleteSelection();
  421. }
  422. else if (ev.getButton() == mDuplicateVB)
  423. {
  424. duplicateSelection();
  425. return true;
  426. }
  427. else if (ev.getButton() == mCutVB)
  428. {
  429. cutSelection();
  430. return true;
  431. }
  432. else if (ev.getButton() == mCopyVB)
  433. {
  434. copySelection();
  435. return true;
  436. }
  437. else if (ev.getButton() == mPasteVB)
  438. {
  439. paste();
  440. return true;
  441. }
  442. return false;
  443. }
  444. bool GUITreeView::isSelectionActive() const
  445. {
  446. return mIsElementSelected && mSelectedElements.size() > 0;
  447. }
  448. void GUITreeView::selectElement(TreeElement* element)
  449. {
  450. clearPing();
  451. auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
  452. [&] (const SelectedElement& x) { return x.element == element; });
  453. if(iterFind == mSelectedElements.end())
  454. {
  455. GUITexture* background = GUITexture::create(mSelectionBackgroundStyle);
  456. background->_setElementDepth(3);
  457. _registerChildElement(background);
  458. element->mIsSelected = true;
  459. mSelectedElements.push_back(SelectedElement(element, background));
  460. mIsElementSelected = true;
  461. selectionChanged();
  462. }
  463. }
  464. void GUITreeView::unselectElement(TreeElement* element)
  465. {
  466. clearPing();
  467. auto iterFind = std::find_if(mSelectedElements.begin(), mSelectedElements.end(),
  468. [&] (const SelectedElement& x) { return x.element == element; });
  469. if(iterFind != mSelectedElements.end())
  470. {
  471. iterFind->element->mIsSelected = false;
  472. GUIElement::destroy(iterFind->background);
  473. mSelectedElements.erase(iterFind);
  474. _markLayoutAsDirty();
  475. selectionChanged();
  476. }
  477. mIsElementSelected = mSelectedElements.size() > 0;
  478. }
  479. void GUITreeView::unselectAll()
  480. {
  481. clearPing();
  482. for(auto& selectedElem : mSelectedElements)
  483. {
  484. selectedElem.element->mIsSelected = false;
  485. GUIElement::destroy(selectedElem.background);
  486. }
  487. mSelectedElements.clear();
  488. mIsElementSelected = false;
  489. _markLayoutAsDirty();
  490. selectionChanged();
  491. }
  492. void GUITreeView::renameSelected()
  493. {
  494. if (isSelectionActive() && mEditElement == nullptr)
  495. {
  496. clearPing();
  497. enableEdit(mSelectedElements[0].element);
  498. unselectAll();
  499. }
  500. }
  501. void GUITreeView::deleteSelection()
  502. {
  503. if (isSelectionActive())
  504. {
  505. auto isChildOf = [&](const TreeElement* parent, const TreeElement* child)
  506. {
  507. const TreeElement* elem = child;
  508. while (elem != nullptr && elem != parent)
  509. elem = child->mParent;
  510. return elem == parent;
  511. };
  512. // Ensure we don't unnecessarily try to delete children if their
  513. // parent is getting deleted anyway
  514. Vector<TreeElement*> elementsToDelete;
  515. for (UINT32 i = 0; i < (UINT32)mSelectedElements.size(); i++)
  516. {
  517. bool hasDeletedParent = false;
  518. for (UINT32 j = 0; j < (UINT32)mSelectedElements.size(); j++)
  519. {
  520. if (i == j)
  521. continue;
  522. if (isChildOf(mSelectedElements[j].element, mSelectedElements[i].element))
  523. {
  524. hasDeletedParent = true;
  525. break;
  526. }
  527. }
  528. if (!hasDeletedParent)
  529. elementsToDelete.push_back(mSelectedElements[i].element);
  530. }
  531. clearPing();
  532. unselectAll();
  533. for (auto& elem : elementsToDelete)
  534. deleteTreeElement(elem);
  535. }
  536. }
  537. void GUITreeView::ping(TreeElement* element)
  538. {
  539. clearPing();
  540. expandToElement(element);
  541. scrollToElement(element, true);
  542. GUITexture* background = GUITexture::create(mHighlightBackgroundStyle);
  543. background->_setElementDepth(2);
  544. _registerChildElement(background);
  545. element->mIsHighlighted = true;
  546. mHighlightedElement.element = element;
  547. mHighlightedElement.background = background;
  548. mIsElementHighlighted = true;
  549. _markLayoutAsDirty();
  550. }
  551. void GUITreeView::clearPing()
  552. {
  553. if (!mIsElementHighlighted)
  554. return;
  555. mHighlightedElement.element->mIsHighlighted = false;
  556. GUIElement::destroy(mHighlightedElement.background);
  557. mHighlightedElement.element = nullptr;
  558. mHighlightedElement.background = nullptr;
  559. mIsElementHighlighted = false;
  560. _markLayoutAsDirty();
  561. }
  562. void GUITreeView::expandToElement(TreeElement* element)
  563. {
  564. if (element->mIsVisible || element->mParent == nullptr)
  565. return;
  566. Stack<TreeElement*> todo;
  567. TreeElement* parent = element->mParent;
  568. while (parent != nullptr)
  569. {
  570. if (!parent->mIsExpanded)
  571. todo.push(parent);
  572. if (parent->mIsVisible)
  573. break;
  574. parent = parent->mParent;
  575. }
  576. while (!todo.empty())
  577. {
  578. TreeElement* curElement = todo.top();
  579. todo.pop();
  580. expandElement(curElement);
  581. }
  582. }
  583. void GUITreeView::expandElement(TreeElement* element)
  584. {
  585. if(element->mIsExpanded)
  586. return;
  587. element->mIsExpanded = true;
  588. if(element->mParent == nullptr || (element->mParent->mIsVisible && element->mParent->mIsExpanded))
  589. {
  590. Stack<TreeElement*> todo;
  591. todo.push(element);
  592. while(!todo.empty())
  593. {
  594. TreeElement* curElem = todo.top();
  595. todo.pop();
  596. curElem->mIsVisible = true;
  597. updateElementGUI(curElem);
  598. if(curElem->mIsExpanded)
  599. {
  600. for(auto& child : curElem->mChildren)
  601. todo.push(child);
  602. }
  603. }
  604. }
  605. }
  606. void GUITreeView::collapseElement(TreeElement* element)
  607. {
  608. if(!element->mIsExpanded)
  609. return;
  610. element->mIsExpanded = false;
  611. updateElementGUI(element);
  612. if(element->mParent == nullptr || (element->mParent->mIsVisible && element->mParent->mIsExpanded))
  613. {
  614. Stack<TreeElement*> todo;
  615. for(auto& child : element->mChildren)
  616. todo.push(child);
  617. while(!todo.empty())
  618. {
  619. TreeElement* curElem = todo.top();
  620. todo.pop();
  621. curElem->mIsVisible = false;
  622. if(curElem->mIsSelected)
  623. unselectElement(curElem);
  624. updateElementGUI(curElem);
  625. if(curElem->mIsExpanded)
  626. {
  627. for(auto& child : curElem->mChildren)
  628. todo.push(child);
  629. }
  630. }
  631. }
  632. }
  633. void GUITreeView::updateElementGUI(TreeElement* element)
  634. {
  635. if(element == &getRootElement())
  636. return;
  637. if(element->mIsVisible)
  638. {
  639. HString name(toWString(element->mName));
  640. if(element->mElement == nullptr)
  641. {
  642. element->mElement = GUILabel::create(name, mElementBtnStyle);
  643. _registerChildElement(element->mElement);
  644. }
  645. if (element->mIsGrayedOut)
  646. {
  647. Color grayedOutTint = element->mTint;
  648. grayedOutTint.a = GRAYED_OUT_COLOR.a;
  649. element->mElement->setTint(grayedOutTint);
  650. }
  651. else
  652. element->mElement->setTint(element->mTint);
  653. if(element->mChildren.size() > 0)
  654. {
  655. if(element->mFoldoutBtn == nullptr)
  656. {
  657. element->mFoldoutBtn = GUIToggle::create(GUIContent(HString(L"")), mFoldoutBtnStyle);
  658. _registerChildElement(element->mFoldoutBtn);
  659. element->mFoldoutBtn->onToggled.connect(std::bind(&GUITreeView::elementToggled, this, element, _1));
  660. if(element->mIsExpanded)
  661. element->mFoldoutBtn->toggleOn();
  662. }
  663. }
  664. else
  665. {
  666. if(element->mFoldoutBtn != nullptr)
  667. {
  668. GUIElement::destroy(element->mFoldoutBtn);
  669. element->mFoldoutBtn = nullptr;
  670. }
  671. }
  672. element->mElement->setContent(GUIContent(name));
  673. }
  674. else
  675. {
  676. if(element->mElement != nullptr)
  677. {
  678. GUIElement::destroy(element->mElement);
  679. element->mElement = nullptr;
  680. }
  681. if(element->mFoldoutBtn != nullptr)
  682. {
  683. GUIElement::destroy(element->mFoldoutBtn);
  684. element->mFoldoutBtn = nullptr;
  685. }
  686. if(element->mIsSelected && element->mIsExpanded)
  687. unselectElement(element);
  688. }
  689. _markLayoutAsDirty();
  690. }
  691. void GUITreeView::elementToggled(TreeElement* element, bool toggled)
  692. {
  693. clearPing();
  694. if(toggled)
  695. expandElement(element);
  696. else
  697. collapseElement(element);
  698. }
  699. void GUITreeView::onEditAccepted()
  700. {
  701. TreeElement* elem = mEditElement;
  702. disableEdit(true);
  703. selectElement(elem);
  704. }
  705. void GUITreeView::onEditCanceled()
  706. {
  707. if (mEditElement != nullptr)
  708. {
  709. TreeElement* elem = mEditElement;
  710. disableEdit(false);
  711. selectElement(elem);
  712. }
  713. }
  714. void GUITreeView::onEditFocusLost()
  715. {
  716. if (mEditElement != nullptr)
  717. disableEdit(false);
  718. }
  719. void GUITreeView::enableEdit(TreeElement* element)
  720. {
  721. assert(mEditElement == nullptr);
  722. mEditElement = element;
  723. mNameEditBox->enableRecursively();
  724. mNameEditBox->setText(toWString(element->mName));
  725. mNameEditBox->setFocus(true);
  726. if(element->mElement != nullptr)
  727. element->mElement->disableRecursively();
  728. }
  729. void GUITreeView::disableEdit(bool applyChanges)
  730. {
  731. assert(mEditElement != nullptr);
  732. if(mEditElement->mElement != nullptr)
  733. mEditElement->mElement->enableRecursively();
  734. if(applyChanges)
  735. {
  736. WString newName = mNameEditBox->getText();
  737. renameTreeElement(mEditElement, newName);
  738. }
  739. mNameEditBox->setFocus(false);
  740. mNameEditBox->disableRecursively();
  741. mEditElement = nullptr;
  742. }
  743. Vector2I GUITreeView::_getOptimalSize() const
  744. {
  745. struct UpdateTreeElement
  746. {
  747. UpdateTreeElement(const TreeElement* element, UINT32 indent)
  748. :element(element), indent(indent)
  749. { }
  750. const TreeElement* element;
  751. UINT32 indent;
  752. };
  753. Vector2I optimalSize;
  754. if (_getDimensions().fixedWidth() && _getDimensions().fixedHeight())
  755. {
  756. optimalSize.x = _getDimensions().minWidth;
  757. optimalSize.y = _getDimensions().minHeight;
  758. }
  759. else
  760. {
  761. Stack<UpdateTreeElement> todo;
  762. todo.push(UpdateTreeElement(&getRootElementConst(), 0));
  763. while(!todo.empty())
  764. {
  765. UpdateTreeElement currentUpdateElement = todo.top();
  766. const TreeElement* current = currentUpdateElement.element;
  767. todo.pop();
  768. INT32 yOffset = 0;
  769. if(current->mElement != nullptr)
  770. {
  771. Vector2I curOptimalSize = current->mElement->_getOptimalSize();
  772. optimalSize.x = std::max(optimalSize.x,
  773. (INT32)(INITIAL_INDENT_OFFSET + curOptimalSize.x + currentUpdateElement.indent * INDENT_SIZE));
  774. yOffset = curOptimalSize.y + ELEMENT_EXTRA_SPACING;
  775. }
  776. optimalSize.y += yOffset;
  777. for(auto& child : current->mChildren)
  778. {
  779. if(!child->mIsVisible)
  780. continue;
  781. todo.push(UpdateTreeElement(child, currentUpdateElement.indent + 1));
  782. }
  783. }
  784. if(_getDimensions().fixedWidth())
  785. optimalSize.x = _getDimensions().minWidth;
  786. else
  787. {
  788. if(_getDimensions().minWidth > 0)
  789. optimalSize.x = std::max((INT32)_getDimensions().minWidth, optimalSize.x);
  790. if(_getDimensions().maxWidth > 0)
  791. optimalSize.x = std::min((INT32)_getDimensions().maxWidth, optimalSize.x);
  792. }
  793. if (_getDimensions().fixedHeight())
  794. optimalSize.y = _getDimensions().minHeight;
  795. else
  796. {
  797. if(_getDimensions().minHeight > 0)
  798. optimalSize.y = std::max((INT32)_getDimensions().minHeight, optimalSize.y);
  799. if(_getDimensions().maxHeight > 0)
  800. optimalSize.y = std::min((INT32)_getDimensions().maxHeight, optimalSize.y);
  801. }
  802. }
  803. return optimalSize;
  804. }
  805. void GUITreeView::updateClippedBounds()
  806. {
  807. mClippedBounds = mLayoutData.area;
  808. mClippedBounds.clip(mLayoutData.clipRect);
  809. }
  810. void GUITreeView::_updateLayoutInternal(const GUILayoutData& data)
  811. {
  812. struct UpdateTreeElement
  813. {
  814. UpdateTreeElement(TreeElement* element, UINT32 indent)
  815. :element(element), indent(indent)
  816. { }
  817. TreeElement* element;
  818. UINT32 indent;
  819. };
  820. mVisibleElements.clear();
  821. Stack<UpdateTreeElement> todo;
  822. todo.push(UpdateTreeElement(&getRootElement(), 0));
  823. // NOTE - Instead of iterating through all elements, try to find those within the clip rect
  824. // and only iterate through those. Others should somehow be marked in-active (similar to GUIElement::isDisabled()?)
  825. Vector<TreeElement*> tempOrderedElements;
  826. Vector2I offset(data.area.x, data.area.y);
  827. while(!todo.empty())
  828. {
  829. UpdateTreeElement currentUpdateElement = todo.top();
  830. TreeElement* current = currentUpdateElement.element;
  831. UINT32 indent = currentUpdateElement.indent;
  832. todo.pop();
  833. INT32 btnHeight = 0;
  834. INT32 yOffset = 0;
  835. if(current->mElement != nullptr)
  836. {
  837. Vector2I elementSize = current->mElement->_getOptimalSize();
  838. btnHeight = elementSize.y;
  839. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 0, Rect2I(data.area.x, offset.y, data.area.width, ELEMENT_EXTRA_SPACING)));
  840. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 1, Rect2I(data.area.x, offset.y + ELEMENT_EXTRA_SPACING, data.area.width, btnHeight)));
  841. offset.x = data.area.x + INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
  842. offset.y += ELEMENT_EXTRA_SPACING;
  843. GUILayoutData childData = data;
  844. childData.area.x = offset.x;
  845. childData.area.y = offset.y;
  846. childData.area.width = elementSize.x;
  847. childData.area.height = elementSize.y;
  848. current->mElement->_setLayoutData(childData);
  849. yOffset = btnHeight;
  850. }
  851. if(current->mFoldoutBtn != nullptr)
  852. {
  853. Vector2I elementSize = current->mFoldoutBtn->_getOptimalSize();
  854. offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.x + 2);
  855. Vector2I myOffset = offset;
  856. myOffset.y += 1;
  857. if(elementSize.y > btnHeight)
  858. {
  859. UINT32 diff = elementSize.y - btnHeight;
  860. float half = diff * 0.5f;
  861. myOffset.y -= Math::floorToInt(half);
  862. }
  863. GUILayoutData childData = data;
  864. childData.area.x = myOffset.x;
  865. childData.area.y = myOffset.y;
  866. childData.area.width = elementSize.x;
  867. childData.area.height = elementSize.y;
  868. current->mFoldoutBtn->_setLayoutData(childData);
  869. }
  870. offset.y += yOffset;
  871. tempOrderedElements.resize(current->mChildren.size(), nullptr);
  872. for(auto& child : current->mChildren)
  873. {
  874. tempOrderedElements[child->mSortedIdx] = child;
  875. }
  876. for(auto iter = tempOrderedElements.rbegin(); iter != tempOrderedElements.rend(); ++iter)
  877. {
  878. TreeElement* child = *iter;
  879. if(!child->mIsVisible)
  880. continue;
  881. todo.push(UpdateTreeElement(child, indent + 1));
  882. }
  883. }
  884. UINT32 remainingHeight = (UINT32)std::max(0, (INT32)data.area.height - (offset.y - data.area.y));
  885. if(remainingHeight > 0)
  886. mVisibleElements.push_back(InteractableElement(&getRootElement(), (UINT32)getRootElement().mChildren.size() * 2, Rect2I(data.area.x, offset.y, data.area.width, remainingHeight)));
  887. for(auto selectedElem : mSelectedElements)
  888. {
  889. GUILabel* targetElement = selectedElem.element->mElement;
  890. GUILayoutData childData = data;
  891. childData.area.y = targetElement->_getLayoutData().area.y;
  892. childData.area.height = targetElement->_getLayoutData().area.height;
  893. selectedElem.background->_setLayoutData(childData);
  894. }
  895. if (mIsElementHighlighted)
  896. {
  897. GUILabel* targetElement = mHighlightedElement.element->mElement;
  898. GUILayoutData childData = data;
  899. childData.area.y = targetElement->_getLayoutData().area.y;
  900. childData.area.height = targetElement->_getLayoutData().area.height;
  901. mHighlightedElement.background->_setLayoutData(childData);
  902. }
  903. if(mEditElement != nullptr)
  904. {
  905. GUILabel* targetElement = mEditElement->mElement;
  906. UINT32 remainingWidth = (UINT32)std::max(0, (((INT32)data.area.width) - (offset.x - data.area.x)));
  907. GUILayoutData childData = data;
  908. childData.area = targetElement->_getLayoutData().area;
  909. childData.area.width = remainingWidth;
  910. mNameEditBox->_setLayoutData(childData);
  911. }
  912. if(mDragInProgress)
  913. {
  914. const InteractableElement* interactableElement = findElementUnderCoord(mDragPosition);
  915. if(interactableElement == nullptr)
  916. {
  917. if(!mDragHighlight->_isDisabled())
  918. mDragHighlight->disableRecursively();
  919. if(!mDragSepHighlight->_isDisabled())
  920. mDragSepHighlight->disableRecursively();
  921. }
  922. else
  923. {
  924. if(interactableElement->isTreeElement())
  925. {
  926. if(!mDragSepHighlight->_isDisabled())
  927. mDragSepHighlight->disableRecursively();
  928. if(mDragHighlight->_isDisabled())
  929. mDragHighlight->enableRecursively();
  930. GUILayoutData childData = data;
  931. childData.area = interactableElement->bounds;
  932. mDragHighlight->_setLayoutData(childData);
  933. }
  934. else
  935. {
  936. if(!mDragHighlight->_isDisabled())
  937. mDragHighlight->disableRecursively();
  938. if(mDragSepHighlight->_isDisabled())
  939. mDragSepHighlight->enableRecursively();
  940. GUILayoutData childData = data;
  941. childData.area = interactableElement->bounds;
  942. mDragSepHighlight->_setLayoutData(childData);
  943. }
  944. }
  945. }
  946. else
  947. {
  948. if(!mDragHighlight->_isDisabled())
  949. mDragHighlight->disableRecursively();
  950. if(!mDragSepHighlight->_isDisabled())
  951. mDragSepHighlight->disableRecursively();
  952. }
  953. // Update scroll bounds
  954. UINT32 scrollHeight = (UINT32)Math::roundToInt(data.clipRect.height * SCROLL_AREA_HEIGHT_PCT);
  955. mTopScrollBounds.x = data.clipRect.x;
  956. mTopScrollBounds.y = data.clipRect.y;
  957. mTopScrollBounds.width = data.clipRect.width;
  958. mTopScrollBounds.height = scrollHeight;
  959. mBottomScrollBounds.x = data.clipRect.x;
  960. mBottomScrollBounds.y = data.clipRect.y + data.clipRect.height - scrollHeight;
  961. mBottomScrollBounds.width = data.clipRect.width;
  962. mBottomScrollBounds.height = scrollHeight;
  963. }
  964. const GUITreeView::InteractableElement* GUITreeView::findElementUnderCoord(const Vector2I& coord) const
  965. {
  966. for(auto& element : mVisibleElements)
  967. {
  968. if(element.bounds.contains(coord))
  969. {
  970. return &element;
  971. }
  972. }
  973. return nullptr;
  974. }
  975. GUITreeView::TreeElement* GUITreeView::getTopMostSelectedElement() const
  976. {
  977. auto topMostElement = mVisibleElements.end();
  978. for(auto& selectedElement : mSelectedElements)
  979. {
  980. auto iterFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  981. [&] (const InteractableElement& x) { return x.getTreeElement() == selectedElement.element; });
  982. if(iterFind != mVisibleElements.end())
  983. {
  984. if(topMostElement == mVisibleElements.end())
  985. topMostElement = iterFind;
  986. else
  987. {
  988. if(iterFind->bounds.y < topMostElement->bounds.y)
  989. topMostElement = iterFind;
  990. }
  991. }
  992. }
  993. if(topMostElement != mVisibleElements.end())
  994. return topMostElement->getTreeElement();
  995. else
  996. return nullptr;
  997. }
  998. GUITreeView::TreeElement* GUITreeView::getBottomMostSelectedElement() const
  999. {
  1000. auto& botMostElement = mVisibleElements.end();
  1001. for(auto& selectedElement : mSelectedElements)
  1002. {
  1003. auto iterFind = std::find_if(mVisibleElements.begin(), mVisibleElements.end(),
  1004. [&] (const InteractableElement& x) { return x.getTreeElement() == selectedElement.element; });
  1005. if(iterFind != mVisibleElements.end())
  1006. {
  1007. if(botMostElement == mVisibleElements.end())
  1008. botMostElement = iterFind;
  1009. else
  1010. {
  1011. if((iterFind->bounds.y + iterFind->bounds.height) > (botMostElement->bounds.y + botMostElement->bounds.height))
  1012. botMostElement = iterFind;
  1013. }
  1014. }
  1015. }
  1016. if(botMostElement != mVisibleElements.end())
  1017. return botMostElement->getTreeElement();
  1018. else
  1019. return nullptr;
  1020. }
  1021. void GUITreeView::closeTemporarilyExpandedElements()
  1022. {
  1023. temporarilyExpandElement(nullptr);
  1024. }
  1025. void GUITreeView::temporarilyExpandElement(const GUITreeView::InteractableElement* mouseOverElement)
  1026. {
  1027. TreeElement* treeElement = nullptr;
  1028. if(mouseOverElement != nullptr && mouseOverElement->isTreeElement())
  1029. treeElement = mouseOverElement->getTreeElement();
  1030. if(treeElement == nullptr || treeElement != mMouseOverDragElement)
  1031. {
  1032. while(!mAutoExpandedElements.empty())
  1033. {
  1034. TreeElement* autoExpandedElement = mAutoExpandedElements.top();
  1035. bool unexpandElement = false;
  1036. if(mouseOverElement != nullptr && mouseOverElement->parent != nullptr)
  1037. {
  1038. if(mouseOverElement->parent != autoExpandedElement && !mouseOverElement->parent->isParentRec(autoExpandedElement))
  1039. unexpandElement = true;
  1040. else
  1041. break;
  1042. }
  1043. else
  1044. unexpandElement = true;
  1045. if(unexpandElement)
  1046. {
  1047. collapseElement(autoExpandedElement);
  1048. if(autoExpandedElement->mFoldoutBtn != nullptr)
  1049. autoExpandedElement->mFoldoutBtn->toggleOff();
  1050. mAutoExpandedElements.pop();
  1051. }
  1052. }
  1053. mMouseOverDragElement = treeElement;
  1054. mMouseOverDragElementTime = gTime().getTime();
  1055. }
  1056. else
  1057. {
  1058. if(mMouseOverDragElement != nullptr && !mMouseOverDragElement->mIsExpanded)
  1059. {
  1060. float timeDiff = gTime().getTime() - mMouseOverDragElementTime;
  1061. if(timeDiff >= AUTO_EXPAND_DELAY_SEC)
  1062. {
  1063. mAutoExpandedElements.push(mMouseOverDragElement);
  1064. expandElement(mMouseOverDragElement);
  1065. if(mMouseOverDragElement->mFoldoutBtn != nullptr)
  1066. mMouseOverDragElement->mFoldoutBtn->toggleOn();
  1067. }
  1068. }
  1069. }
  1070. }
  1071. void GUITreeView::scrollToElement(TreeElement* element, bool center)
  1072. {
  1073. if(element->mElement == nullptr)
  1074. return;
  1075. GUIScrollArea* scrollArea = findParentScrollArea();
  1076. if(scrollArea == nullptr)
  1077. return;
  1078. if(center)
  1079. {
  1080. Rect2I myBounds = _getClippedBounds();
  1081. INT32 clipVertCenter = myBounds.y + (INT32)Math::roundToInt(myBounds.height * 0.5f);
  1082. INT32 elemVertCenter = element->mElement->_getLayoutData().area.y + (INT32)Math::roundToInt(element->mElement->_getLayoutData().area.height * 0.5f);
  1083. if(elemVertCenter > clipVertCenter)
  1084. scrollArea->scrollDownPx(elemVertCenter - clipVertCenter);
  1085. else
  1086. scrollArea->scrollUpPx(clipVertCenter - elemVertCenter);
  1087. }
  1088. else
  1089. {
  1090. Rect2I myBounds = _getClippedBounds();
  1091. INT32 elemVertTop = element->mElement->_getLayoutData().area.y;
  1092. INT32 elemVertBottom = element->mElement->_getLayoutData().area.y + element->mElement->_getLayoutData().area.height;
  1093. INT32 top = myBounds.y;
  1094. INT32 bottom = myBounds.y + myBounds.height;
  1095. INT32 offset = 0;
  1096. if(elemVertTop < top)
  1097. scrollArea->scrollUpPx(top - elemVertTop);
  1098. else if(elemVertBottom > bottom)
  1099. scrollArea->scrollDownPx(elemVertBottom - bottom);
  1100. }
  1101. }
  1102. GUIScrollArea* GUITreeView::findParentScrollArea() const
  1103. {
  1104. GUIElementBase* parent = _getParent();
  1105. while(parent != nullptr)
  1106. {
  1107. if(parent->_getType() == GUIElementBase::Type::Element)
  1108. {
  1109. GUIElement* parentElement = static_cast<GUIElement*>(parent);
  1110. if(parentElement->_getElementType() == GUIElement::ElementType::ScrollArea)
  1111. {
  1112. GUIScrollArea* scrollArea = static_cast<GUIScrollArea*>(parentElement);
  1113. return scrollArea;
  1114. }
  1115. }
  1116. parent = parent->_getParent();
  1117. }
  1118. return nullptr;
  1119. }
  1120. const String& GUITreeView::getGUITypeName()
  1121. {
  1122. static String typeName = "SceneTreeView";
  1123. return typeName;
  1124. }
  1125. }