6
6
7
7
namespace Toolbox . Editor . Internal
8
8
{
9
- using Toolbox . Editor . Drawers ;
10
-
11
9
/// <summary>
12
10
/// Version of the <see cref="ReorderableList"/> dedicated for <see cref="ToolboxDrawer"/>s.
13
11
/// Can be used only together with the internal layouting system.
@@ -75,61 +73,65 @@ private void DrawElementRow(int index, bool isActive, bool isTarget, bool hasFoc
75
73
var elementRowRect = elementRowGroup . rect ;
76
74
var isSelected = isActive || isTarget ;
77
75
elementsRects [ index ] = elementRowRect ;
78
- //draw element background (handle selection and targeting)
79
- if ( drawElementBackgroundCallback != null )
80
- {
81
- drawElementBackgroundCallback ( elementRowRect , index , isSelected , hasFocus ) ;
82
- }
83
- else
84
- {
85
- DrawStandardElementBackground ( elementRowRect , index , isSelected , hasFocus , Draggable ) ;
86
- }
87
-
88
- //prepare handle-related properties
89
- var handleRect = GetHandleRect ( elementRowRect ) ;
90
- var drawHandle = ! IsDragging ;
91
- //draw handles only for static array or currently dragged element
92
- if ( isSelected && IsDragging )
93
- {
94
- drawHandle = true ;
95
- handleRect = GetHandleRect ( draggedY ) ;
96
- }
97
-
98
- if ( drawHandle )
99
- {
100
- if ( drawElementHandleCallback != null )
101
- {
102
- drawElementHandleCallback ( handleRect , index , isActive , hasFocus ) ;
103
- }
104
- else
105
- {
106
- DrawStandardElementHandle ( handleRect , index , isActive , hasFocus , Draggable ) ;
107
- }
108
- }
109
76
77
+ DrawElementBackground ( elementRowRect , index , isSelected , hasFocus ) ;
78
+ DrawElementDragHandle ( elementRowRect , index , isSelected , hasFocus ) ;
110
79
//draw the real property in separate vertical group
111
80
using ( var elementGroup = new EditorGUILayout . VerticalScope ( Style . contentGroupStyle ) )
112
81
{
113
82
var elementRect = elementGroup . rect ;
114
83
//adjust label width to the known dragging area
115
84
EditorGUIUtility . labelWidth -= Style . dragAreaWidth ;
116
- if ( drawElementCallback != null )
117
- {
118
- drawElementCallback ( elementRect , index , isActive , hasFocus ) ;
119
- }
120
- else
121
- {
122
- DrawStandardElement ( elementRect , index , isActive , hasFocus , Draggable ) ;
123
- }
124
-
85
+ DrawElement ( index ) ;
125
86
EditorGUIUtility . labelWidth += Style . dragAreaWidth ;
126
87
}
127
88
128
- //create additional space between element and right margin
89
+ //create additional space between item and right margin
129
90
DrawEmptySpace ( Style . spacing ) ;
130
91
}
131
92
}
132
93
94
+ private void DrawElementBackground ( Rect rect , int index , bool isSelected , bool hasFocus )
95
+ {
96
+ if ( drawElementBackgroundCallback != null )
97
+ {
98
+ drawElementBackgroundCallback ( rect , index , isSelected , hasFocus ) ;
99
+ }
100
+ else
101
+ {
102
+ DrawStandardElementBackground ( rect , index , isSelected , hasFocus , Draggable ) ;
103
+ }
104
+ }
105
+
106
+ private void DrawElementDragHandle ( Rect rect , int index , bool isSelected , bool hasFocus )
107
+ {
108
+ DrawHandleArea ( ) ;
109
+ //draw handles only for static array or currently dragged element
110
+ if ( IsDragging && ! isSelected )
111
+ {
112
+ return ;
113
+ }
114
+
115
+ var handleRect = IsDragging
116
+ ? GetHandleRect ( draggedY )
117
+ : GetHandleRect ( rect ) ;
118
+ if ( drawElementHandleCallback != null )
119
+ {
120
+ drawElementHandleCallback ( handleRect , index , isSelected , hasFocus ) ;
121
+ }
122
+ else
123
+ {
124
+ DrawStandardElementHandle ( handleRect , index , isSelected , hasFocus , Draggable ) ;
125
+ }
126
+ }
127
+
128
+ private void DrawElement ( int index )
129
+ {
130
+ var element = List . GetArrayElementAtIndex ( index ) ;
131
+ var content = GetElementContent ( element , index ) ;
132
+ ToolboxEditorGui . DrawToolboxProperty ( element , content ) ;
133
+ }
134
+
133
135
/// <summary>
134
136
/// Creates empty space in a layout-based structure.
135
137
/// </summary>
@@ -138,14 +140,18 @@ private void DrawEmptySpace(float space)
138
140
GuiLayoutUtility . CreateSpace ( space ) ;
139
141
}
140
142
143
+ private void DrawHandleArea ( )
144
+ {
145
+ DrawEmptySpace ( Style . dragAreaWidth ) ;
146
+ }
147
+
141
148
/// <summary>
142
149
/// Creates empty space for the dragging area and returns adjusted <see cref="Rect"/>.
143
150
/// </summary>
144
151
private Rect GetHandleRect ( Rect rowRect )
145
152
{
146
153
var handleRect = new Rect ( rowRect ) ;
147
154
handleRect . xMax = handleRect . xMin + Style . dragAreaWidth ;
148
- DrawEmptySpace ( Style . dragAreaWidth ) ;
149
155
return handleRect ;
150
156
}
151
157
@@ -171,26 +177,15 @@ private Rect GetHandleRect(float draggedY)
171
177
/// <summary>
172
178
/// Creates small, colored rect to visualize the dragging target (gap between elements).
173
179
/// </summary>
174
- private Rect DrawTargetGap ( int targetIndex , int draggingIndex , Color color , float width , float margin )
180
+ private void DrawTargetGap ( int targetIndex , int draggingIndex )
175
181
{
176
- //TODO: refactor + custom texture/method for the gap
177
- var targetsRect = elementsRects [ targetIndex ] ;
178
- var rect = new Rect ( targetsRect ) ;
179
- //handle differently situation above and under target
180
- if ( targetIndex < draggingIndex )
181
- {
182
- rect . yMax = rect . yMin ;
183
- rect . yMin = rect . yMax - width ;
184
- }
185
- else
186
- {
187
- rect . yMin = rect . yMax ;
188
- rect . yMax = rect . yMin + width ;
189
- }
190
-
191
- rect . xMin += margin ;
192
- EditorGUI . DrawRect ( rect , color ) ;
193
- return rect ;
182
+ var rect = elementsRects [ targetIndex ] ;
183
+ rect . yMax = targetIndex < draggingIndex
184
+ ? rect . yMin
185
+ : rect . yMax + Style . spacing ;
186
+ rect . yMin = rect . yMax - Style . spacing ;
187
+ rect . xMin += Style . dragAreaWidth ;
188
+ EditorGUI . DrawRect ( rect , Style . selectionColor ) ;
194
189
}
195
190
196
191
@@ -229,7 +224,9 @@ protected override void DoListMiddle(Rect middleRect)
229
224
return ;
230
225
}
231
226
232
- DrawEmptySpace ( Style . padding ) ;
227
+ var upperPadding = Style . padding - ElementSpacing ;
228
+ var lowerPadding = Style . padding ;
229
+ DrawEmptySpace ( upperPadding ) ;
233
230
//if there are elements, we need to draw them - we will do
234
231
//this differently depending on if we are dragging or not
235
232
for ( var i = 0 ; i < arraySize ; i ++ )
@@ -240,25 +237,15 @@ protected override void DoListMiddle(Rect middleRect)
240
237
var isTarget = ( i == lastCoveredIndex && ! isActive ) ;
241
238
var isEnding = ( i == arraySize - 1 ) ;
242
239
243
- //draw current array element
240
+ DrawEmptySpace ( ElementSpacing ) ;
244
241
DrawElementRow ( i , isActive , isTarget , hasFocus ) ;
245
-
246
- //draw dragging element gap
247
242
if ( isTarget )
248
243
{
249
- DrawTargetGap ( i , Index , GapColor , GapWidth , Style . dragAreaWidth ) ;
250
- }
251
-
252
- if ( isEnding )
253
- {
254
- continue ;
244
+ DrawTargetGap ( i , Index ) ;
255
245
}
256
-
257
- //create spacing for elements
258
- DrawEmptySpace ( ElementSpacing ) ;
259
246
}
260
247
261
- DrawEmptySpace ( Style . padding ) ;
248
+ DrawEmptySpace ( lowerPadding ) ;
262
249
}
263
250
264
251
protected override bool DoListHeader ( )
@@ -339,18 +326,6 @@ protected override int GetCoveredElementIndex(Vector2 mousePosition)
339
326
}
340
327
341
328
342
- #region Methods: Default interaction/draw calls
343
-
344
- /// <inheritdoc/>
345
- public override void DrawStandardElement ( Rect rect , int index , bool selected , bool focused , bool draggable )
346
- {
347
- var element = List . GetArrayElementAtIndex ( index ) ;
348
- var content = GetElementContent ( element , index ) ;
349
- ToolboxEditorGui . DrawToolboxProperty ( element , content ) ;
350
- }
351
-
352
- #endregion
353
-
354
329
/// <inheritdoc/>
355
330
public override void DoList ( )
356
331
{
@@ -380,9 +355,5 @@ public Rect LastFooterRect
380
355
{
381
356
get => footerRect ;
382
357
}
383
-
384
- public Color GapColor { get ; set ; } = new Color ( 0.3f , 0.47f , 0.75f ) ;
385
-
386
- public float GapWidth { get ; set ; } = 2.0f ;
387
358
}
388
359
}
0 commit comments