@@ -371,6 +371,12 @@ public class TreeNode : ITreeNode
371
371
[ NonSerialized ] public Texture Icon ;
372
372
[ NonSerialized ] public Texture IconBadge ;
373
373
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
+
374
380
public string Path
375
381
{
376
382
get { return path ; }
@@ -438,14 +444,55 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
438
444
return renderResult ;
439
445
440
446
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
+ }
442
460
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 )
444
465
{
445
- nodeStartX += 2 * Level ;
466
+ nodeStartX += 2 ;
446
467
}
447
468
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
+ // }
449
496
450
497
if ( Event . current . type == EventType . repaint )
451
498
{
@@ -455,9 +502,6 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
455
502
var styleOn = false ;
456
503
if ( IsFolder )
457
504
{
458
- var toggleRect = new Rect ( nodeStartX , nodeRect . y , indentation , nodeRect . height ) ;
459
- nodeStartX += toggleRect . width ;
460
-
461
505
styleOn = ! IsCollapsed ;
462
506
463
507
if ( Event . current . type == EventType . repaint )
@@ -477,10 +521,6 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
477
521
478
522
if ( TreeIsCheckable )
479
523
{
480
- var selectRect = new Rect ( nodeStartX , nodeRect . y , indentation , nodeRect . height ) ;
481
-
482
- nodeStartX += selectRect . width + 2 ;
483
-
484
524
var selectionStyle = GUI . skin . toggle ;
485
525
var selectionValue = false ;
486
526
@@ -495,7 +535,7 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
495
535
496
536
EditorGUI . BeginChangeCheck ( ) ;
497
537
{
498
- GUI . Toggle ( selectRect , selectionValue , GUIContent . none , selectionStyle ) ;
538
+ GUI . Toggle ( checkRect , selectionValue , GUIContent . none , selectionStyle ) ;
499
539
}
500
540
if ( EditorGUI . EndChangeCheck ( ) )
501
541
{
@@ -505,20 +545,13 @@ public TreeNodeRenderResult Render(Rect rect, float indentation, bool isSelected
505
545
506
546
var contentStyle = IsActive ? activeNodeStyle : nodeStyle ;
507
547
508
- var contentRect = new Rect ( nodeStartX , rect . y , rect . width , rect . height ) ;
509
548
if ( Event . current . type == EventType . repaint )
510
549
{
511
- contentStyle . Draw ( contentRect , content , false , false , styleOn , isSelected ) ;
550
+ contentStyle . Draw ( iconRect , content , false , false , styleOn , isSelected ) ;
512
551
}
513
552
514
553
if ( IconBadge != null )
515
554
{
516
- var statusRect = new Rect (
517
- contentRect . x + 6 ,
518
- contentRect . yMax - 7 ,
519
- 9 ,
520
- 9 ) ;
521
-
522
555
GUI . DrawTexture ( statusRect , IconBadge ) ;
523
556
}
524
557
0 commit comments