BsGUISceneTreeView.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. #include "BsGUISceneTreeView.h"
  2. #include "BsGUIArea.h"
  3. #include "BsGUILayout.h"
  4. #include "BsGUITexture.h"
  5. #include "BsGUIButton.h"
  6. #include "BsGUILabel.h"
  7. #include "BsGUISpace.h"
  8. #include "BsGUIWidget.h"
  9. #include "BsGUIToggle.h"
  10. #include "BsGUITreeViewEditBox.h"
  11. #include "BsGUIMouseEvent.h"
  12. #include "BsGUISkin.h"
  13. #include "BsGUICommandEvent.h"
  14. #include "CmSceneObject.h"
  15. #include "CmSceneManager.h"
  16. #include "BsCmdEditPlainFieldGO.h"
  17. using namespace CamelotFramework;
  18. using namespace BansheeEngine;
  19. namespace BansheeEditor
  20. {
  21. const UINT32 GUISceneTreeView::ELEMENT_EXTRA_SPACING = 3;
  22. const UINT32 GUISceneTreeView::INDENT_SIZE = 10;
  23. const UINT32 GUISceneTreeView::INITIAL_INDENT_OFFSET = 16;
  24. GUISceneTreeView::TreeElement::TreeElement()
  25. :mParent(nullptr), mFoldoutBtn(nullptr), mElement(nullptr),
  26. mId(0), mIsExpanded(false), mSortedIdx(0), mIsDirty(false), mIsVisible(true)
  27. { }
  28. GUISceneTreeView::TreeElement::~TreeElement()
  29. {
  30. for(auto& child : mChildren)
  31. cm_delete(child);
  32. if(mFoldoutBtn != nullptr)
  33. GUIElement::destroy(mFoldoutBtn);
  34. if(mElement != nullptr)
  35. GUIElement::destroy(mElement);
  36. mChildren.clear();
  37. }
  38. GUISceneTreeView::GUISceneTreeView(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
  39. GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle,
  40. const GUILayoutOptions& layoutOptions)
  41. :GUIElementContainer(parent, layoutOptions), mBackgroundStyle(backgroundStyle),
  42. mElementBtnStyle(elementBtnStyle), mFoldoutBtnStyle(foldoutBtnStyle), mEditBoxStyle(editBoxStyle), mEditElement(nullptr),
  43. mSelectedElement(nullptr), mSelectionBackground(nullptr), mNameEditBox(nullptr), mSelectionBackgroundStyle(selectionBackgroundStyle)
  44. {
  45. if(mBackgroundStyle == nullptr)
  46. mBackgroundStyle = parent.getSkin().getStyle("TreeViewBackground");
  47. if(mElementBtnStyle == nullptr)
  48. mElementBtnStyle = parent.getSkin().getStyle("TreeViewElementBtn");
  49. if(mFoldoutBtnStyle == nullptr)
  50. mFoldoutBtnStyle = parent.getSkin().getStyle("TreeViewFoldoutBtn");
  51. if(mSelectionBackgroundStyle == nullptr)
  52. mSelectionBackgroundStyle = parent.getSkin().getStyle("TreeViewSelectionBackground");
  53. if(mEditBoxStyle == nullptr)
  54. mEditBoxStyle = parent.getSkin().getStyle("TreeViewEditBox");
  55. mBackgroundImage = GUITexture::create(parent, mBackgroundStyle);
  56. mSelectionBackground = GUITexture::create(parent, mSelectionBackgroundStyle);
  57. mSelectionBackground->disableRecursively();
  58. mNameEditBox = GUITreeViewEditBox::create(parent, mEditBoxStyle);
  59. mNameEditBox->disableRecursively();
  60. mNameEditBox->onInputConfirmed.connect(boost::bind(&GUISceneTreeView::onEditAccepted, this));
  61. mNameEditBox->onInputCanceled.connect(boost::bind(&GUISceneTreeView::onEditCanceled, this));
  62. _registerChildElement(mBackgroundImage);
  63. _registerChildElement(mSelectionBackground);
  64. _registerChildElement(mNameEditBox);
  65. }
  66. GUISceneTreeView::~GUISceneTreeView()
  67. {
  68. }
  69. GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, GUIElementStyle* backgroundStyle, GUIElementStyle* elementBtnStyle,
  70. GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle)
  71. {
  72. return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle, foldoutBtnStyle,
  73. selectionBackgroundStyle, editBoxStyle, GUILayoutOptions::create(&GUISkin::DefaultStyle));
  74. }
  75. GUISceneTreeView* GUISceneTreeView::create(GUIWidget& parent, const GUIOptions& options, GUIElementStyle* backgroundStyle,
  76. GUIElementStyle* elementBtnStyle, GUIElementStyle* foldoutBtnStyle, GUIElementStyle* selectionBackgroundStyle, GUIElementStyle* editBoxStyle)
  77. {
  78. return new (cm_alloc<GUISceneTreeView, PoolAlloc>()) GUISceneTreeView(parent, backgroundStyle, elementBtnStyle,
  79. foldoutBtnStyle, selectionBackgroundStyle, editBoxStyle, GUILayoutOptions::create(options, &GUISkin::DefaultStyle));
  80. }
  81. void GUISceneTreeView::update()
  82. {
  83. // NOTE - Instead of iterating through every visible element and comparing it with internal values,
  84. // I might just want to add callbacks to SceneManager that notify me of any changes and then only perform
  85. // update if anything is actually dirty
  86. struct UpdateTreeElement
  87. {
  88. UpdateTreeElement(TreeElement* element, UINT32 seqIdx, bool visible)
  89. :element(element), seqIdx(seqIdx), visible(visible)
  90. { }
  91. TreeElement* element;
  92. UINT32 seqIdx;
  93. bool visible;
  94. };
  95. HSceneObject root = CM::gSceneManager().getRootNode();
  96. mRootElement.mSceneObject = root;
  97. mRootElement.mId = root->getId();
  98. mRootElement.mSortedIdx = 0;
  99. mRootElement.mIsExpanded = true;
  100. Stack<UpdateTreeElement>::type todo;
  101. todo.push(UpdateTreeElement(&mRootElement, 0, true));
  102. while(!todo.empty())
  103. {
  104. UpdateTreeElement updateElement = todo.top();
  105. TreeElement* current = updateElement.element;
  106. HSceneObject currentSO = current->mSceneObject;
  107. todo.pop();
  108. // Check if SceneObject has changed in any way and update the tree element
  109. if(updateElement.visible)
  110. {
  111. bool completeMatch = (UINT32)current->mChildren.size() == currentSO->getNumChildren();
  112. // Early exit case - Most commonly there will be no changes between active and cached data so
  113. // we first do a quick check in order to avoid expensive comparison later
  114. if(completeMatch)
  115. {
  116. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  117. {
  118. UINT32 curId = currentSO->getChild(i)->getId();
  119. if(curId != current->mChildren[i]->mId)
  120. {
  121. completeMatch = false;
  122. break;
  123. }
  124. }
  125. }
  126. // Not a complete match, compare everything and insert/delete elements as needed
  127. if(!completeMatch)
  128. {
  129. Vector<TreeElement*>::type newChildren;
  130. mTempToDelete.resize(current->mChildren.size(), true);
  131. for(UINT32 i = 0; i < currentSO->getNumChildren(); i++)
  132. {
  133. HSceneObject currentSOChild = currentSO->getChild(i);
  134. UINT32 curId = currentSOChild->getId();
  135. bool found = false;
  136. for(UINT32 j = 0; j < current->mChildren.size(); j++)
  137. {
  138. TreeElement* currentChild = current->mChildren[j];
  139. if(curId == currentChild->mId)
  140. {
  141. mTempToDelete[j] = false;
  142. currentChild->mIsDirty = true;
  143. currentChild->mSortedIdx = (UINT32)newChildren.size();
  144. newChildren.push_back(currentChild);
  145. found = true;
  146. break;
  147. }
  148. }
  149. if(!found)
  150. {
  151. TreeElement* newChild = cm_new<TreeElement>();
  152. newChild->mParent = current;
  153. newChild->mSceneObject = currentSOChild;
  154. newChild->mId = currentSOChild->getId();
  155. newChild->mName = currentSOChild->getName();
  156. newChild->mSortedIdx = (UINT32)newChildren.size();
  157. newChild->mIsDirty = true;
  158. newChildren.push_back(newChild);
  159. }
  160. }
  161. for(UINT32 i = 0; i < current->mChildren.size(); i++)
  162. {
  163. if(!mTempToDelete[i])
  164. continue;
  165. cm_delete(current->mChildren[i]);
  166. }
  167. current->mChildren = newChildren;
  168. current->mIsDirty = true;
  169. }
  170. // Check if name needs updating
  171. const String& name = current->mSceneObject->getName();
  172. if(current->mName != name)
  173. {
  174. current->mName = name;
  175. current->mIsDirty = true;
  176. }
  177. // Calculate the sorted index of the element based on its name
  178. TreeElement* parent = current->mParent;
  179. if(current->mIsDirty && parent != nullptr)
  180. {
  181. for(UINT32 i = 0; i < (UINT32)parent->mChildren.size(); i++)
  182. {
  183. INT32 stringCompare = current->mName.compare(parent->mChildren[i]->mName);
  184. if(stringCompare > 0)
  185. {
  186. if(current->mSortedIdx < parent->mChildren[i]->mSortedIdx)
  187. std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
  188. }
  189. else if(stringCompare < 0)
  190. {
  191. if(current->mSortedIdx > parent->mChildren[i]->mSortedIdx)
  192. std::swap(current->mSortedIdx, parent->mChildren[i]->mSortedIdx);
  193. }
  194. }
  195. }
  196. }
  197. bool visibilityChanged = false;
  198. if(current->mIsVisible != updateElement.visible)
  199. {
  200. visibilityChanged = true;
  201. current->mIsVisible = updateElement.visible;
  202. current->mIsDirty = true;
  203. }
  204. if(current->mIsDirty && current != &mRootElement)
  205. {
  206. if(updateElement.visible)
  207. {
  208. HString name(toWString(current->mName));
  209. if(current->mElement == nullptr)
  210. {
  211. current->mElement = GUILabel::create(_getParentWidget(), name, mElementBtnStyle);
  212. _registerChildElement(current->mElement);
  213. }
  214. if(current->mChildren.size() > 0)
  215. {
  216. if(current->mFoldoutBtn == nullptr)
  217. {
  218. current->mFoldoutBtn = GUIToggle::create(_getParentWidget(), GUIContent(HString(L"")), mFoldoutBtnStyle);
  219. _registerChildElement(current->mFoldoutBtn);
  220. current->mFoldoutBtn->onToggled.connect(boost::bind(&GUISceneTreeView::elementToggled, this, current, _1));
  221. }
  222. }
  223. else
  224. {
  225. if(current->mFoldoutBtn != nullptr)
  226. {
  227. GUIElement::destroy(current->mFoldoutBtn);
  228. current->mFoldoutBtn = nullptr;
  229. }
  230. }
  231. current->mElement->setContent(GUIContent(name));
  232. }
  233. else
  234. {
  235. if(current->mElement != nullptr)
  236. {
  237. GUIElement::destroy(current->mElement);
  238. current->mElement = nullptr;
  239. }
  240. if(current->mFoldoutBtn != nullptr)
  241. {
  242. GUIElement::destroy(current->mFoldoutBtn);
  243. current->mFoldoutBtn = nullptr;
  244. }
  245. }
  246. markContentAsDirty();
  247. current->mIsDirty = false;
  248. }
  249. // Queue children for next iteration
  250. if(visibilityChanged || current->mIsVisible)
  251. {
  252. for(UINT32 i = 0; i < (UINT32)current->mChildren.size(); i++)
  253. {
  254. todo.push(UpdateTreeElement(current->mChildren[i], i, current->mIsVisible && current->mIsExpanded));
  255. }
  256. }
  257. }
  258. if(mSelectedElement != nullptr)
  259. {
  260. if(mSelectionBackground->_isDisabled())
  261. mSelectionBackground->enableRecursively();
  262. }
  263. else
  264. {
  265. if(!mSelectionBackground->_isDisabled())
  266. mSelectionBackground->disableRecursively();
  267. }
  268. }
  269. bool GUISceneTreeView::mouseEvent(const GUIMouseEvent& event)
  270. {
  271. if(event.getType() == GUIMouseEventType::MouseUp)
  272. {
  273. const GUISceneTreeView::InteractableElement* element = findElementUnderCoord(event.getPosition());
  274. if(element != nullptr && element->isTreeElement())
  275. mSelectedElement = interactableToRealElement(*element);
  276. markContentAsDirty();
  277. return true;
  278. }
  279. return false;
  280. }
  281. bool GUISceneTreeView::commandEvent(const GUICommandEvent& ev)
  282. {
  283. if(ev.getType() == GUICommandEventType::Rename)
  284. {
  285. if(mSelectedElement != nullptr && mEditElement == nullptr)
  286. enableEdit(mSelectedElement);
  287. return true;
  288. }
  289. return false;
  290. }
  291. void GUISceneTreeView::elementToggled(TreeElement* element, bool toggled)
  292. {
  293. element->mIsExpanded = toggled;
  294. }
  295. void GUISceneTreeView::onEditAccepted()
  296. {
  297. disableEdit(true);
  298. }
  299. void GUISceneTreeView::onEditCanceled()
  300. {
  301. if(mEditElement != nullptr)
  302. disableEdit(false);
  303. }
  304. void GUISceneTreeView::enableEdit(TreeElement* element)
  305. {
  306. assert(mEditElement == nullptr);
  307. mEditElement = element;
  308. mNameEditBox->enableRecursively();
  309. mNameEditBox->setFocus(true);
  310. if(element->mElement != nullptr)
  311. element->mElement->disableRecursively();
  312. }
  313. void GUISceneTreeView::disableEdit(bool applyChanges)
  314. {
  315. assert(mEditElement != nullptr);
  316. if(mEditElement->mElement != nullptr)
  317. mEditElement->mElement->enableRecursively();
  318. if(applyChanges)
  319. {
  320. String newName = toString(mNameEditBox->getText());
  321. CmdEditPlainFieldGO<String>::execute(mEditElement->mSceneObject, "mName", newName);
  322. }
  323. mNameEditBox->disableRecursively();
  324. mEditElement = nullptr;
  325. }
  326. Vector2I GUISceneTreeView::_getOptimalSize() const
  327. {
  328. struct UpdateTreeElement
  329. {
  330. UpdateTreeElement(const TreeElement* element, UINT32 indent)
  331. :element(element), indent(indent)
  332. { }
  333. const TreeElement* element;
  334. UINT32 indent;
  335. };
  336. Vector2I optimalSize;
  337. if(_getLayoutOptions().fixedWidth && _getLayoutOptions().fixedHeight)
  338. {
  339. optimalSize.x = _getLayoutOptions().width;
  340. optimalSize.y = _getLayoutOptions().height;
  341. }
  342. else
  343. {
  344. Stack<UpdateTreeElement>::type todo;
  345. todo.push(UpdateTreeElement(&mRootElement, 0));
  346. optimalSize.y += ELEMENT_EXTRA_SPACING;
  347. while(!todo.empty())
  348. {
  349. UpdateTreeElement currentUpdateElement = todo.top();
  350. const TreeElement* current = currentUpdateElement.element;
  351. todo.pop();
  352. INT32 yOffset = 0;
  353. if(current->mElement != nullptr)
  354. {
  355. Vector2I curOptimalSize = current->mElement->_getOptimalSize();
  356. optimalSize.x = std::max(optimalSize.x,
  357. (INT32)(INITIAL_INDENT_OFFSET + curOptimalSize.x + currentUpdateElement.indent * INDENT_SIZE));
  358. yOffset = curOptimalSize.y + ELEMENT_EXTRA_SPACING;
  359. }
  360. optimalSize.y += yOffset;
  361. for(auto& child : current->mChildren)
  362. {
  363. if(!child->mIsVisible)
  364. continue;
  365. todo.push(UpdateTreeElement(child, currentUpdateElement.indent + 1));
  366. }
  367. }
  368. if(_getLayoutOptions().fixedWidth)
  369. optimalSize.x = _getLayoutOptions().width;
  370. else
  371. {
  372. if(_getLayoutOptions().minWidth > 0)
  373. optimalSize.x = std::max((INT32)_getLayoutOptions().minWidth, optimalSize.x);
  374. if(_getLayoutOptions().maxWidth > 0)
  375. optimalSize.x = std::min((INT32)_getLayoutOptions().maxWidth, optimalSize.x);
  376. }
  377. if(_getLayoutOptions().fixedHeight)
  378. optimalSize.y = _getLayoutOptions().height;
  379. else
  380. {
  381. if(_getLayoutOptions().minHeight > 0)
  382. optimalSize.y = std::max((INT32)_getLayoutOptions().minHeight, optimalSize.y);
  383. if(_getLayoutOptions().maxHeight > 0)
  384. optimalSize.y = std::min((INT32)_getLayoutOptions().maxHeight, optimalSize.y);
  385. }
  386. }
  387. return optimalSize;
  388. }
  389. void GUISceneTreeView::updateClippedBounds()
  390. {
  391. Vector2I offset = _getOffset();
  392. mClippedBounds = RectI(offset.x, offset.y, _getWidth(), _getHeight());
  393. }
  394. void GUISceneTreeView::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,
  395. RectI clipRect, UINT8 widgetDepth, UINT16 areaDepth)
  396. {
  397. struct UpdateTreeElement
  398. {
  399. UpdateTreeElement(TreeElement* element, UINT32 indent)
  400. :element(element), indent(indent)
  401. { }
  402. TreeElement* element;
  403. UINT32 indent;
  404. };
  405. mVisibleElements.clear();
  406. Stack<UpdateTreeElement>::type todo;
  407. todo.push(UpdateTreeElement(&mRootElement, 0));
  408. // NOTE - Instead of iterating through all elements, try to find those within the clip rect
  409. // and only iterate through those. Others should somehow be marked in-active (similar to GUIElement::isDisabled()?)
  410. Vector<TreeElement*>::type tempOrderedElements;
  411. Vector2I offset(x, y);
  412. while(!todo.empty())
  413. {
  414. UpdateTreeElement currentUpdateElement = todo.top();
  415. TreeElement* current = currentUpdateElement.element;
  416. UINT32 indent = currentUpdateElement.indent;
  417. todo.pop();
  418. if(current->mParent != nullptr && current->mSortedIdx == 0)
  419. {
  420. mVisibleElements.push_back(InteractableElement(current->mParent, 0, RectI(x, offset.y, width, ELEMENT_EXTRA_SPACING)));
  421. }
  422. INT32 btnHeight = 0;
  423. INT32 yOffset = 0;
  424. if(current->mElement != nullptr)
  425. {
  426. Vector2I elementSize = current->mElement->_getOptimalSize();
  427. btnHeight = elementSize.y;
  428. offset.x = INITIAL_INDENT_OFFSET + indent * INDENT_SIZE;
  429. current->mElement->_setOffset(offset);
  430. current->mElement->_setWidth(elementSize.x);
  431. current->mElement->_setHeight(elementSize.y);
  432. current->mElement->_setAreaDepth(areaDepth);
  433. current->mElement->_setWidgetDepth(widgetDepth);
  434. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  435. current->mElement->_setClipRect(elemClipRect);
  436. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 1, RectI(x, offset.y, width, btnHeight)));
  437. mVisibleElements.push_back(InteractableElement(current->mParent, current->mSortedIdx * 2 + 2, RectI(x, offset.y + btnHeight, width, ELEMENT_EXTRA_SPACING)));
  438. yOffset = btnHeight + ELEMENT_EXTRA_SPACING;
  439. }
  440. if(current->mFoldoutBtn != nullptr)
  441. {
  442. Vector2I elementSize = current->mFoldoutBtn->_getOptimalSize();
  443. offset.x -= std::min((INT32)INITIAL_INDENT_OFFSET, elementSize.y);
  444. Vector2I myOffset = offset;
  445. if(elementSize.y > btnHeight)
  446. {
  447. UINT32 diff = elementSize.y - btnHeight;
  448. float half = diff * 0.5f;
  449. myOffset.y -= Math::floorToInt(half);
  450. }
  451. current->mFoldoutBtn->_setOffset(myOffset);
  452. current->mFoldoutBtn->_setWidth(elementSize.x);
  453. current->mFoldoutBtn->_setHeight(elementSize.y);
  454. current->mFoldoutBtn->_setAreaDepth(areaDepth);
  455. current->mFoldoutBtn->_setWidgetDepth(widgetDepth);
  456. RectI elemClipRect(clipRect.x - myOffset.x, clipRect.y - myOffset.y, clipRect.width, clipRect.height);
  457. current->mFoldoutBtn->_setClipRect(elemClipRect);
  458. }
  459. offset.y += yOffset;
  460. tempOrderedElements.resize(current->mChildren.size(), nullptr);
  461. for(auto& child : current->mChildren)
  462. {
  463. tempOrderedElements[child->mSortedIdx] = child;
  464. }
  465. for(auto iter = tempOrderedElements.rbegin(); iter != tempOrderedElements.rend(); ++iter)
  466. {
  467. TreeElement* child = *iter;
  468. if(!child->mIsVisible)
  469. continue;
  470. todo.push(UpdateTreeElement(child, indent + 1));
  471. }
  472. }
  473. if(mSelectedElement != nullptr)
  474. {
  475. GUILabel* targetElement = mSelectedElement->mElement;
  476. Vector2I offset = targetElement->_getOffset();
  477. offset.x = x;
  478. mSelectionBackground->_setOffset(offset);
  479. mSelectionBackground->_setWidth(width);
  480. mSelectionBackground->_setHeight(targetElement->_getHeight());
  481. mSelectionBackground->_setAreaDepth(areaDepth + 1);
  482. mSelectionBackground->_setWidgetDepth(widgetDepth);
  483. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  484. mSelectionBackground->_setClipRect(elemClipRect);
  485. }
  486. if(mEditElement != nullptr)
  487. {
  488. GUILabel* targetElement = mEditElement->mElement;
  489. Vector2I offset = targetElement->_getOffset();
  490. UINT32 remainingWidth = (UINT32)std::max(0, (((INT32)width) - (offset.x - x)));
  491. mNameEditBox->_setOffset(offset);
  492. mNameEditBox->_setWidth(remainingWidth);
  493. mNameEditBox->_setHeight(targetElement->_getHeight());
  494. mNameEditBox->_setAreaDepth(areaDepth);
  495. mNameEditBox->_setWidgetDepth(widgetDepth);
  496. RectI elemClipRect(clipRect.x - offset.x, clipRect.y - offset.y, clipRect.width, clipRect.height);
  497. mNameEditBox->_setClipRect(elemClipRect);
  498. }
  499. }
  500. const GUISceneTreeView::InteractableElement* GUISceneTreeView::findElementUnderCoord(const CM::Vector2I& coord) const
  501. {
  502. for(auto& element : mVisibleElements)
  503. {
  504. if(element.bounds.contains(coord))
  505. {
  506. return &element;
  507. }
  508. }
  509. return nullptr;
  510. }
  511. GUISceneTreeView::TreeElement* GUISceneTreeView::interactableToRealElement(const GUISceneTreeView::InteractableElement& element)
  512. {
  513. if(!element.isTreeElement())
  514. return nullptr;
  515. UINT32 sortedIdx = (element.index - 1) / 2;
  516. auto findIter = std::find_if(element.parent->mChildren.begin(), element.parent->mChildren.end(),
  517. [&](const TreeElement* x) { return x->mSortedIdx == sortedIdx; });
  518. if(findIter != element.parent->mChildren.end())
  519. return *findIter;
  520. return nullptr;
  521. }
  522. const String& GUISceneTreeView::getGUITypeName()
  523. {
  524. static String typeName = "SceneTreeView";
  525. return typeName;
  526. }
  527. }