Slastraf Posted January 24, 2021 Share Posted January 24, 2021 Hello, It is rather hard to remove an item from a TreeView if its not on the lowest subnode. auto it = std::find(itemFolder->begin(), itemFolder->end(), itemClass); if (it != itemFolder->end()) itemFolder->erase(it); subnode->ClearNodes(); // rebuild nodes for each (itemClass k in *itemFolder) { subnode->AddNode(k.info); } This for example works okay if you rebuild the tree in the following but you won't be able to remove if it is in a top treenode. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted January 24, 2021 Author Share Posted January 24, 2021 It would be better to access the tree by array or pointer . Quote Link to comment Share on other sites More sharing options...
Josh Posted January 26, 2021 Share Posted January 26, 2021 Maybe the Widget class should have a FindChild method? I don’t think you need to rebuild the whole tree. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted January 26, 2021 Author Share Posted January 26, 2021 7 minutes ago, Optimus Josh said: Maybe the Widget class should have a FindChild method? A findchild method could also be useful for many situations, but in this scenario you would know which exact widget you need to remove. Is there a way to hide a widget by widget text ? 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted January 26, 2021 Share Posted January 26, 2021 41 minutes ago, Slastraf said: A findchild method could also be useful for many situations, but in this scenario you would know which exact widget you need to remove. Is there a way to hide a widget by widget text ? Didn't we just say the exact same thing two different ways? Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted January 26, 2021 Author Share Posted January 26, 2021 1 minute ago, Optimus Josh said: Didn't we just say the exact same thing two different ways? FindChild implies you would need to know there is a parent. But if you dont know the parent you would need to call it from the root, then it collapses on itself and it becomes a Find() function. Now if you had a find function there needs to be a unique identifier for each widget which the user could set and dont need to worry about all of this. 1 Quote Link to comment Share on other sites More sharing options...
Josh Posted January 27, 2021 Share Posted January 27, 2021 In the next build you will be able to remove a treeviewnode by calling node->SetParent(NULL). Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted January 27, 2021 Share Posted January 27, 2021 The fix is up on Steam now. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted February 5, 2021 Author Share Posted February 5, 2021 How to use it ? Yesterday it seemed to work by setting subnode->SetParent(nullptr); then it would hide the whole tree but today I get an error. I made code to reproduce it, can replace lines 74-76 in the default project main. auto tree2 = CreateTreeView(border, border, 280, subpanel3->ClientSize().y - border * 2, subpanel3, TREEVIEW_DRAGANDDROP | TREEVIEW_DRAGINSERT); tree2->SetLayout(1, 0, 1, 1); auto subnode2 = tree2->root->AddNode("Node 1"); for (int n = 1; n < 10; ++n) { subnode2->AddNode("Subnode " + String(n)); } //error here subnode2->SetParent(nullptr); BTW, also happens with SetParent(NULL); Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 5, 2021 Author Share Posted February 5, 2021 any fix ? Quote Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2021 Share Posted February 6, 2021 Step one is to produce the bug. Now I have done that and we have something we can both run: #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = ListDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0]); //Create User Interface auto ui = CreateInterface(window); //Create widget auto sz = ui->root->ClientSize(); auto treeview = CreateTreeView(10, 10, sz.x - 20, sz.y - 20, ui->root); auto node = treeview->root->AddNode("Node 1"); node->AddNode("Subnode 1"); node->AddNode("Subnode 2"); node->AddNode("Subnode 3"); node = treeview->root->AddNode("Node 2"); node->AddNode("Subnode 1"); node->AddNode("Subnode 2"); node->AddNode("Subnode 3"); node = treeview->root->AddNode("Node 3"); node->AddNode("Subnode 1"); node->AddNode("Subnode 2"); node->AddNode("Subnode 3"); while (true) { const auto& event = WaitEvent(); switch (event.id) { case EVENT_WINDOWCLOSE: return 0; break; case EVENT_WIDGETACTION: { node = event.extra->As<TreeViewNode>(); node->SetParent(NULL); } break; } } return 0; } Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted February 6, 2021 Author Share Posted February 6, 2021 11 minutes ago, Optimus Josh said: Step one is to produce the bug. Now I have done that and we have something we can both run: #include "pch.h" using namespace UltraEngine; int main(int argc, const char* argv[]) { //Get the displays auto displays = ListDisplays(); //Create a window auto window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[0]); //Create User Interface auto ui = CreateInterface(window); //Create widget auto sz = ui->root->ClientSize(); auto treeview = CreateTreeView(10, 10, sz.x - 20, sz.y - 20, ui->root); auto node = treeview->root->AddNode("Node 1"); node->AddNode("Subnode 1"); node->AddNode("Subnode 2"); node->AddNode("Subnode 3"); node = treeview->root->AddNode("Node 2"); node->AddNode("Subnode 1"); node->AddNode("Subnode 2"); node->AddNode("Subnode 3"); node = treeview->root->AddNode("Node 3"); node->AddNode("Subnode 1"); node->AddNode("Subnode 2"); node->AddNode("Subnode 3"); while (true) { const auto& event = WaitEvent(); switch (event.id) { case EVENT_WINDOWCLOSE: return 0; break; case EVENT_WIDGETACTION: { node = event.extra->As<TreeViewNode>(); node->SetParent(NULL); } break; } } return 0; } That is good and I have implemented a similar thing, but what if you want to remove all nodes from the tree ? You could select an item and delete it, but in an other case I want to reset the whole tree. For example you have 10 different users and for each user there is a list of items and you want the tree to display all items of the selected user. This requires for the entire tree to refresh and rebuild. This functionality does not work anymore because a few days ago you could take the node which you iterated the tree with (like my example above) and set its parent to null and the tree would hide. This does not work anymore. Can you provide an example for reseting the tree ? Quote Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2021 Share Posted February 6, 2021 3 minutes ago, Slastraf said: That is good and I have implemented a similar thing, but what if you want to remove all nodes from the tree ? You could select an item and delete it, but in an other case I want to reset the whole tree. For example you have 10 different users and for each user there is a list of items and you want the tree to display all items of the selected user. This requires for the entire tree to refresh and rebuild. This functionality does not work anymore because a few days ago you could take the node which you iterated the tree with (like my example above) and set its parent to null and the tree would hide. This does not work anymore. Can you provide an example for reseting the tree ? I created an example that shows the error you described, and I am working on fixing it, and now you are describing another situation you want me to guess and try to create before I have fixed the thing you were reporting? You are dancing around too much. I need a piece of code I can copy and paste. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Slastraf Posted February 6, 2021 Author Share Posted February 6, 2021 3 minutes ago, Optimus Josh said: I created an example that shows the error you described, and I am working on fixing it, and now you are describing another situation you want me to guess and try to create before I have fixed the thing you were reporting? You are dancing around too much. I need a piece of code I can copy and paste. Sorry to bother so much, yes the original post was about selection Nodes, but my post from 19 hours ago was to reset the whole tree (and it worked prior but not anymore). Regardless, both things need to work. There shou.ld be ->SetParent(NULL) to remove 1 item and also tree->root->SetParent(NULL) or an equivalent tree->root->ClearNodes() (exists but throws error currently) which resets the whole tree. Quote Link to comment Share on other sites More sharing options...
Slastraf Posted February 6, 2021 Author Share Posted February 6, 2021 And this whole thing makes me stuck at my project right now because there really is no alternative Quote Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2021 Share Posted February 6, 2021 I have the problem fixed and I am making a new build now. To clear a tree, you would just remove all children from the root. You can use Lock and Unlock to prevent drawing as they are being removed: treeview->Lock(); while (!treeview->kids.empty()) { treeview->kids[0]->SetParent(NULL); } treeview->Unlock(); 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Josh Posted February 6, 2021 Share Posted February 6, 2021 Build is up now. You need to restart Steam to get it. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.