BsGUITreeView.cpp 37 KB

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