iwalidza Posted April 14, 2020 Share Posted April 14, 2020 What the best way to make Parents and children system for my dx lib? Link to comment
Moderators Patrick Posted April 14, 2020 Moderators Share Posted April 14, 2020 (edited) Enough to store parent of elements. And when you destroy an element, you need to check every other element. (if checked element's parent is equals to destroyed element, you need to delete it too) For example, if you destroy window. local dxelements = {} function destroy(id) -- destroy -> id -- loop trough all other dxelements for id2, data in pairs(dxelements) do if data.parent == id then -- checked element's parent equals to destroyed element -- destroy this dxelement too destroy(id2) end end end Steps: - Delete window - Start to check other elements which parent is window. -> Delete tab. - Start to check other elements which parent is tab. -> Delete button. - Start to check other elements which parent is button. -> Not found. -> Done. Or you can store childrens of element, and then you don't need to check every other element, because you already know the childrens. Edited April 14, 2020 by Patrick Link to comment
iwalidza Posted April 14, 2020 Author Share Posted April 14, 2020 then i need insert all childrens in table for parent and for table to all elements and when i remove the parent need to check for all childrens of the parent table Link to comment
Moderators Patrick Posted April 14, 2020 Moderators Share Posted April 14, 2020 4 minutes ago, iwalidza said: then i need insert all childrens in table for parent and for table to all elements and when i remove the parent need to check for all childrens of the parent table Exactly. (and when you remove a children, you need to remove it from parent's table too) 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now