@@ -17,12 +17,11 @@ public class SearchablePopup : PopupWindowContent
17
17
/// <summary>
18
18
/// Creates searchable popup using given properties.
19
19
/// </summary>
20
- public static void Show ( Rect activatorRect , int current , string [ ] options , Action < int > onSelect )
20
+ public static void Show ( Rect activatorRect , int current , IReadOnlyList < string > options , Action < int > onSelect )
21
21
{
22
22
PopupWindow . Show ( activatorRect , new SearchablePopup ( activatorRect , current , options , onSelect ) ) ;
23
23
}
24
24
25
-
26
25
private readonly Action < int > onSelect ;
27
26
28
27
private readonly SearchArray searchArray ;
@@ -35,12 +34,11 @@ public static void Show(Rect activatorRect, int current, string[] options, Actio
35
34
private Rect activatorRect ;
36
35
private Rect toolbarRect ;
37
36
private Rect contentRect ;
38
-
39
37
40
38
/// <summary>
41
- /// Constructor should be called only internally by the <see cref="Show(Rect, int, string[] , Action{int})"/> method.
39
+ /// Constructor should be called only internally by the <see cref="Show(Rect, int, IReadOnlyList{String} , Action{int})"/> method.
42
40
/// </summary>
43
- private SearchablePopup ( Rect activatorRect , int startIndex , string [ ] options , Action < int > onSelect )
41
+ private SearchablePopup ( Rect activatorRect , int startIndex , IReadOnlyList < string > options , Action < int > onSelect )
44
42
{
45
43
this . activatorRect = activatorRect ;
46
44
@@ -57,7 +55,6 @@ private SearchablePopup(Rect activatorRect, int startIndex, string[] options, Ac
57
55
} ;
58
56
}
59
57
60
-
61
58
private void SelectItem ( int index )
62
59
{
63
60
onSelect ( index ) ;
@@ -228,7 +225,6 @@ public override void OnGUI(Rect rect)
228
225
GUI . enabled = false ;
229
226
}
230
227
231
-
232
228
private class SearchArray
233
229
{
234
230
public struct Item
@@ -243,19 +239,16 @@ public Item(int index, string label)
243
239
}
244
240
}
245
241
246
-
247
242
private readonly List < Item > items ;
248
- private readonly string [ ] options ;
243
+ private readonly IReadOnlyList < string > options ;
249
244
250
-
251
- public SearchArray ( string [ ] options )
245
+ public SearchArray ( IReadOnlyList < string > options )
252
246
{
253
247
this . options = options ;
254
248
items = new List < Item > ( ) ;
255
249
Search ( string . Empty ) ;
256
250
}
257
251
258
-
259
252
public bool Search ( string filter )
260
253
{
261
254
if ( Filter == filter )
@@ -265,7 +258,8 @@ public bool Search(string filter)
265
258
266
259
items . Clear ( ) ;
267
260
var simplifiedFilter = filter . ToLower ( ) ;
268
- for ( var i = 0 ; i < options . Length ; i ++ )
261
+ var optionsCount = options . Count ;
262
+ for ( var i = 0 ; i < optionsCount ; i ++ )
269
263
{
270
264
var option = options [ i ] ;
271
265
if ( string . IsNullOrEmpty ( filter ) || option . ToLower ( ) . Contains ( simplifiedFilter ) )
@@ -291,7 +285,6 @@ public Item GetItemAt(int index)
291
285
return items [ index ] ;
292
286
}
293
287
294
-
295
288
public int ItemsCount => items . Count ;
296
289
297
290
public string Filter { get ; private set ; }
0 commit comments