Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question TreeView connected Lines

Discussion in 'UI Toolkit' started by equal, Jul 6, 2023.

  1. equal

    equal

    Joined:
    Dec 14, 2012
    Posts:
    77
    Hi,

    what would be my best approch to implement "lines" in the Runtime TreeView?
    I tried to search for it, but i didnt find an awnser.

    Currently i have this:
    upload_2023-7-6_12-43-41.png

    I would like to replace the teal Areas with something like this:



    2. Question: Do the Entries/Elements know about if they are "the last of current indentation" or any other Information i could use to code something up myself?
     
  2. equal

    equal

    Joined:
    Dec 14, 2012
    Posts:
    77
    Alright, nevermind. I found a way.

    upload_2023-7-6_13-49-50.png

    Solution: the individual Elements have 2 addition absolutly positioned images to the left of them. Binding i run a check if they are the last element in their Parents list. Like this:
    Code (CSharp):
    1. ...
    2. else if (treeV.GetItemDataForIndex<object>(index) is sdGalaxy g)
    3.                 {
    4.                     plListEntry.sLabel.text = g.Name;
    5.                     plListEntry.sToggle.visible = false;
    6.                     plListEntry.sImageVisualElement.style.backgroundImage = icon_galaxy;
    7.                     //plListEntry.parent.parent.style.left = -15;
    8.  
    9.                     if (g.Sectors.Count > 0)
    10.                     {
    11.                         plListEntry.sVisualElementTreeTrunk.visible = false;
    12.                         plListEntry.sVisualElementTreeTrunk_L.visible = false;
    13.                     }
    14.                     else
    15.                     {
    16.                         if (g.Parent.Galaxies.IndexOf(g) == g.Parent.Galaxies.Count - 1)
    17.                         {
    18.                             plListEntry.sVisualElementTreeTrunk.visible = false;
    19.                             plListEntry.sVisualElementTreeTrunk_L.visible = true;
    20.                         }
    21.                         else
    22.                         {
    23.                             plListEntry.sVisualElementTreeTrunk_L.visible = false;
    24.                             plListEntry.sVisualElementTreeTrunk.visible = true;
    25.                         }
    26.                     }
    27.                 }
    28. ...
    This simple implementation is ok for now. I just hope that i dont come in problems with the virtualizer, because i cant be 100% sure if what is the last element in the object list is also the "most bottom" element of the indent for the virtualized tree.