Skip to content
This repository was archived by the owner on Dec 5, 2024. It is now read-only.

Commit a2f84dd

Browse files
Placing elements in the tree view
1 parent 4ed230a commit a2f84dd

File tree

1 file changed

+53
-20
lines changed

1 file changed

+53
-20
lines changed

src/UnityExtension/Assets/Editor/GitHub.Unity/UI/TreeControl.cs

Lines changed: 53 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ public class TreeNode : ITreeNode
371371
[NonSerialized] public Texture Icon;
372372
[NonSerialized] public Texture IconBadge;
373373

374+
// [NonSerialized] private GUIStyle blackStyle;
375+
// [NonSerialized] private GUIStyle greenStyle;
376+
// [NonSerialized] private GUIStyle blueStyle;
377+
// [NonSerialized] private GUIStyle yellowStyle;
378+
// [NonSerialized] private GUIStyle magentaStyle;
379+
374380
public string Path
375381
{
376382
get { return path; }
@@ -438,14 +444,55 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
438444
return renderResult;
439445

440446
var fillRect = rect;
441-
var nodeStartX = Level * indentation * (TreeIsCheckable ? 2 : 1);
447+
var nodeStartX = Level * indentation;
448+
nodeStartX += 2 * level;
449+
450+
var nodeRect = new Rect(nodeStartX, rect.y, fillRect.width - nodeStartX, rect.height);
451+
452+
var reserveToggleSpace = TreeIsCheckable || isFolder;
453+
var toggleRect = new Rect(nodeStartX, nodeRect.y, reserveToggleSpace ? indentation : 0, nodeRect.height);
454+
455+
nodeStartX += toggleRect.width;
456+
if (reserveToggleSpace)
457+
{
458+
nodeStartX += 2;
459+
}
442460

443-
if (TreeIsCheckable && Level > 0)
461+
var checkRect = new Rect(nodeStartX, nodeRect.y, TreeIsCheckable ? indentation : 0, nodeRect.height);
462+
463+
nodeStartX += checkRect.width;
464+
if (TreeIsCheckable)
444465
{
445-
nodeStartX += 2 * Level;
466+
nodeStartX += 2;
446467
}
447468

448-
var nodeRect = new Rect(nodeStartX, rect.y, rect.width, rect.height);
469+
var iconRect = new Rect(nodeStartX, nodeRect.y, fillRect.width - nodeStartX, nodeRect.height);
470+
var statusRect = new Rect(iconRect.x + 6, iconRect.yMax - 9, 9, 9);
471+
472+
// if (Event.current.type == EventType.repaint)
473+
// {
474+
// if (blackStyle == null)
475+
// blackStyle = new GUIStyle { normal = { background = Utility.GetTextureFromColor(Color.black) } };
476+
//
477+
// if (greenStyle == null)
478+
// greenStyle = new GUIStyle { normal = { background = Utility.GetTextureFromColor(Color.green) } };
479+
//
480+
// if (blueStyle == null)
481+
// blueStyle = new GUIStyle { normal = { background = Utility.GetTextureFromColor(Color.blue) } };
482+
//
483+
// if (yellowStyle == null)
484+
// yellowStyle = new GUIStyle { normal = { background = Utility.GetTextureFromColor(Color.yellow) } };
485+
//
486+
// if (magentaStyle == null)
487+
// magentaStyle = new GUIStyle { normal = { background = Utility.GetTextureFromColor(Color.magenta) } };
488+
//
489+
// GUI.Box(nodeRect, GUIContent.none, blackStyle);
490+
//
491+
// GUI.Box(toggleRect, GUIContent.none, isFolder ? greenStyle : blueStyle);
492+
//
493+
// GUI.Box(checkRect, GUIContent.none, yellowStyle);
494+
// GUI.Box(iconRect, GUIContent.none, magentaStyle);
495+
// }
449496

450497
if (Event.current.type == EventType.repaint)
451498
{
@@ -455,9 +502,6 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
455502
var styleOn = false;
456503
if (IsFolder)
457504
{
458-
var toggleRect = new Rect(nodeStartX, nodeRect.y, indentation, nodeRect.height);
459-
nodeStartX += toggleRect.width;
460-
461505
styleOn = !IsCollapsed;
462506

463507
if (Event.current.type == EventType.repaint)
@@ -477,10 +521,6 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
477521

478522
if (TreeIsCheckable)
479523
{
480-
var selectRect = new Rect(nodeStartX, nodeRect.y, indentation, nodeRect.height);
481-
482-
nodeStartX += selectRect.width + 2;
483-
484524
var selectionStyle = GUI.skin.toggle;
485525
var selectionValue = false;
486526

@@ -495,7 +535,7 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
495535

496536
EditorGUI.BeginChangeCheck();
497537
{
498-
GUI.Toggle(selectRect, selectionValue, GUIContent.none, selectionStyle);
538+
GUI.Toggle(checkRect, selectionValue, GUIContent.none, selectionStyle);
499539
}
500540
if (EditorGUI.EndChangeCheck())
501541
{
@@ -505,20 +545,13 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
505545

506546
var contentStyle = IsActive ? activeNodeStyle : nodeStyle;
507547

508-
var contentRect = new Rect(nodeStartX, rect.y, rect.width, rect.height);
509548
if (Event.current.type == EventType.repaint)
510549
{
511-
contentStyle.Draw(contentRect, content, false, false, styleOn, isSelected);
550+
contentStyle.Draw(iconRect, content, false, false, styleOn, isSelected);
512551
}
513552

514553
if (IconBadge != null)
515554
{
516-
var statusRect = new Rect(
517-
contentRect.x + 6,
518-
contentRect.yMax - 7,
519-
9,
520-
9);
521-
522555
GUI.DrawTexture(statusRect, IconBadge);
523556
}
524557

0 commit comments

Comments
 (0)