swing-ui 0.1.25 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (116) hide show
  1. package/LICENSE +5 -4
  2. package/README.md +144 -7
  3. package/SwingUI.js +2611 -0
  4. package/classes/Arc.js +185 -0
  5. package/classes/Button.js +55 -0
  6. package/classes/CheckBox.js +33 -0
  7. package/classes/CheckBoxMenuItem.js +24 -0
  8. package/classes/ComboBox.js +329 -0
  9. package/classes/ComponentContainer.js +828 -0
  10. package/classes/ContextMenu.js +141 -0
  11. package/classes/DocumentEditor.js +168 -0
  12. package/classes/Ellipse.js +76 -0
  13. package/classes/InternalWindow.js +397 -0
  14. package/classes/InternalWindowContainer.js +93 -0
  15. package/classes/Label.js +52 -0
  16. package/classes/Line.js +105 -0
  17. package/classes/List.js +452 -0
  18. package/classes/MediaPlayer.js +504 -0
  19. package/classes/Menu.js +74 -0
  20. package/classes/MenuBar.js +56 -0
  21. package/classes/MenuItem.js +92 -0
  22. package/classes/Panel.js +50 -0
  23. package/classes/PasswordField.js +47 -0
  24. package/classes/Polygon.js +236 -0
  25. package/classes/Polyline.js +240 -0
  26. package/classes/ProgressBar.js +62 -0
  27. package/classes/RadioButton.js +110 -0
  28. package/classes/RadioButtonMenuItem.js +106 -0
  29. package/classes/Rectangle.js +199 -0
  30. package/classes/ScrollPane.js +53 -0
  31. package/classes/ScrollableComponent.js +141 -0
  32. package/classes/Separator.js +24 -0
  33. package/classes/Shape.js +584 -0
  34. package/classes/ShapeContainer.js +231 -0
  35. package/classes/Slider.js +172 -0
  36. package/classes/Spinner.js +172 -0
  37. package/classes/SplitView.js +82 -0
  38. package/classes/Stroke.js +115 -0
  39. package/classes/Table.js +982 -0
  40. package/classes/Tabs.js +228 -0
  41. package/classes/TextArea.js +125 -0
  42. package/classes/TextComponent.js +207 -0
  43. package/classes/TextField.js +128 -0
  44. package/classes/TextShape.js +123 -0
  45. package/classes/ToggleButton.js +147 -0
  46. package/classes/ToolBar.js +120 -0
  47. package/classes/TrayIcon.js +54 -0
  48. package/classes/Tree.js +569 -0
  49. package/classes/UIComponent.js +2154 -0
  50. package/classes/Window.js +609 -0
  51. package/enums.js +298 -0
  52. package/fonts.conf +32 -0
  53. package/functions.js +254 -0
  54. package/icon.png +0 -0
  55. package/index.js +109 -4
  56. package/jar/gui-11.jar +0 -0
  57. package/jar/lib/flatlaf.jar +0 -0
  58. package/jar/lib/jna.jar +0 -0
  59. package/package.json +58 -33
  60. package/typedefs.js +973 -0
  61. package/types/SwingUI.d.ts +727 -0
  62. package/types/classes/Arc.d.ts +111 -0
  63. package/types/classes/Button.d.ts +38 -0
  64. package/types/classes/CheckBox.d.ts +22 -0
  65. package/types/classes/CheckBoxMenuItem.d.ts +18 -0
  66. package/types/classes/ComboBox.d.ts +172 -0
  67. package/types/classes/ComponentContainer.d.ts +131 -0
  68. package/types/classes/ContextMenu.d.ts +74 -0
  69. package/types/classes/DocumentEditor.d.ts +95 -0
  70. package/types/classes/Ellipse.d.ts +34 -0
  71. package/types/classes/InternalWindow.d.ts +163 -0
  72. package/types/classes/InternalWindowContainer.d.ts +36 -0
  73. package/types/classes/Label.d.ts +33 -0
  74. package/types/classes/Line.d.ts +48 -0
  75. package/types/classes/List.d.ts +223 -0
  76. package/types/classes/MediaPlayer.d.ts +381 -0
  77. package/types/classes/Menu.d.ts +43 -0
  78. package/types/classes/MenuBar.d.ts +26 -0
  79. package/types/classes/MenuItem.d.ts +57 -0
  80. package/types/classes/Panel.d.ts +28 -0
  81. package/types/classes/PasswordField.d.ts +22 -0
  82. package/types/classes/Polygon.d.ts +93 -0
  83. package/types/classes/Polyline.d.ts +96 -0
  84. package/types/classes/ProgressBar.d.ts +36 -0
  85. package/types/classes/RadioButton.d.ts +70 -0
  86. package/types/classes/RadioButtonMenuItem.d.ts +71 -0
  87. package/types/classes/Rectangle.d.ts +82 -0
  88. package/types/classes/ScrollPane.d.ts +23 -0
  89. package/types/classes/ScrollableComponent.d.ts +81 -0
  90. package/types/classes/Separator.d.ts +14 -0
  91. package/types/classes/Shape.d.ts +223 -0
  92. package/types/classes/ShapeContainer.d.ts +92 -0
  93. package/types/classes/Slider.d.ts +107 -0
  94. package/types/classes/Spinner.d.ts +129 -0
  95. package/types/classes/SplitView.d.ts +47 -0
  96. package/types/classes/Stroke.d.ts +99 -0
  97. package/types/classes/Table.d.ts +652 -0
  98. package/types/classes/Tabs.d.ts +118 -0
  99. package/types/classes/TextArea.d.ts +45 -0
  100. package/types/classes/TextComponent.d.ts +136 -0
  101. package/types/classes/TextField.d.ts +94 -0
  102. package/types/classes/TextShape.d.ts +73 -0
  103. package/types/classes/ToggleButton.d.ts +84 -0
  104. package/types/classes/ToolBar.d.ts +82 -0
  105. package/types/classes/TrayIcon.d.ts +43 -0
  106. package/types/classes/Tree.d.ts +354 -0
  107. package/types/classes/UIComponent.d.ts +966 -0
  108. package/types/classes/Window.d.ts +334 -0
  109. package/types/enums.d.ts +437 -0
  110. package/types/functions.d.ts +109 -0
  111. package/types/index.d.ts +188 -0
  112. package/types/typedefs.d.ts +1626 -0
  113. package/ui-process-manager.js +317 -0
  114. package/video-devices-linux.sh +72 -0
  115. package/video-devices-mac.sh +33 -0
  116. package/CHANGES.md +0 -3
@@ -0,0 +1,452 @@
1
+
2
+ import {ScrollableComponent} from "./ScrollableComponent.js";
3
+
4
+ /**
5
+ * List UI component, extends ScrollableComponent class, which extends UIComponent class.
6
+ * List can be a list of text items, icons, or icons and text. List direction can be vertical, horizontal with wrapping, and vertical with wrapping.
7
+ * Check example below to become familiar with how the item Object is formatted.
8
+ *
9
+ * For more methods for this component check UIComponent class.
10
+ * @class
11
+ * @global
12
+ * @see ScrollableComponent
13
+ * @see ListItem
14
+ * @example
15
+ *
16
+ * // Item Object format (All fields other than "text" are optional):
17
+ * {
18
+ * text: string, // Item text (Required)
19
+ * [id]: string|number, // Value that can be used by software logic to identify this item
20
+ * [value]: string|number, // Additional value to be stored in the item for later use.
21
+ * [icon]: string, // Absolute or relative path to icon image, base64 encoded image string, or `null` to remove icon.
22
+ * [color]: string, // Item text color as a 6 character hex encoded color string (e.g. #665500)
23
+ * [background]: string, // Item background color as a 6 character hex encoded color string (e.g. #665500)
24
+ * [tooltip]: string, // Tooltip text to show when pointer hover the item. (in List and Tree components only)
25
+ * [font]: font object // Object{name: string, size: number, bold: boolean, ...}. See complete list of font properties in example of font() method.
26
+ * }
27
+ */
28
+ export class List extends ScrollableComponent
29
+ {
30
+ /**
31
+ * Layouts that can be used to display list items.
32
+ * @readonly
33
+ * @enum {number}
34
+ * @property {number} Vertical - Items are arranged in a single vertical column.
35
+ * @property {number} VerticalWrap - Items flow vertically and wrap into additional columns if needed.
36
+ * @property {number} HorizontalWrap - Items flow horizontally and wrap into additional rows if needed.
37
+ * @example
38
+ * list.layout(List.Layout.VerticalWrap);
39
+ */
40
+ static Layout = Object.freeze({Vertical: 0, VerticalWrap: 1, HorizontalWrap: 2});
41
+
42
+ /**
43
+ * List constructor.
44
+ * Accepts an optional Array parameter: strings ["Item 1","Item 2", ...], numbers [1, 2, 3, ...], and ListItem formatted objects [{text:"Item 1"}, {text:"Item 2"}, ...], or a mix of them.
45
+ *
46
+ * @param {Array<string|number|ListItem>} [items] - Items as an Array of ListItem formatted objects, strings or numbers. Can be a mix of these types.
47
+ * @example
48
+ * // Creating combo box, then adding each item separately.
49
+ * const combo1 = new ComboBox().add("Item 1").add(45).add({text: "Item 2", font:{bolt:true}});
50
+ *
51
+ * // Creating combo box, then adding items as an array.
52
+ * const combo2 = new ComboBox().items([
53
+ * "Item 1",
54
+ * 45,
55
+ * {text: "Item 2", font:{bolt:true}}
56
+ * ]);
57
+ *
58
+ * // Creating combo box with items as a string and object. Items can be a mix of strings and objects.
59
+ * const combo3 = new ComboBox([
60
+ * "Item 1",
61
+ * 45,
62
+ * {text: "Item 2", font:{bolt:true}}
63
+ * ]);
64
+ */
65
+ constructor(...args)
66
+ {
67
+ if(args.length > 0)
68
+ {
69
+ super("List", (new.target === List), args[0]);
70
+ }
71
+ else
72
+ {
73
+ super("List", (new.target === List));
74
+ }
75
+
76
+ this.finalize(List);
77
+ }
78
+
79
+ /**
80
+ * Adds a list item at the end of the list, or inserts the item at specified index.
81
+ *
82
+ * @param {string|number|ListItem} item - List item as a string, number, or ListItem formatted object.
83
+ * @param {number} index - Integer position at which to add the item.
84
+ * @returns {number} Returns an index at which the item was inserted, or -1 if item was not inserted for some reason.
85
+ * @see ListItem
86
+ * @example
87
+ * const i = combo1.add({text: "New Item", ...more optional properties}); // Adding item as object
88
+ * const i = combo1.add("New Item"); // Adding item as string
89
+ * const i = combo1.add(45); // Adding item as number
90
+ */
91
+ add(item, index = -1)
92
+ {
93
+ if(item == null) throw new Error(`item is ${typeof item} in List.add(item)`);
94
+ if(index > -1) item.index = index;
95
+ return ui.sendToGUI({control: this.id, get: "add", data: item}, r => r.value);
96
+ }
97
+
98
+ /**
99
+ * If index argument is specified, N amount of items starting form specified index will be removed.
100
+ * If called without parameters, this component will be removed from it's parent. See examples below.
101
+ *
102
+ * @param {number} [index=undefined] - Index of the item to remove. If not provided, the component will be removed from its parent.
103
+ * @param {number} [deleteCount=1] - Amount of items to remove
104
+ * @returns {List} Returns `this` ComboBox instance.
105
+ * @example
106
+ * list.remove(); // removes the component from it's parent container
107
+ * list.remove(4); // removes list item at index 4
108
+ * list.remove(4, 3); // removes 3 items starting at index 4
109
+ */
110
+ remove()
111
+ {
112
+ let value = null;
113
+
114
+ if(arguments.length > 0 && typeof arguments[0] !== "boolean")
115
+ {
116
+ value = parseInt(arguments[0]);
117
+ if(isNaN(value) || value < 0) return this; // if not valid index, return now
118
+ let qty = arguments.length > 1 && !isNaN(arguments[1]) ? parseInt(arguments[1]) : 1;
119
+
120
+ ui.sendToGUI({control: this.id, set: "remove", value: value, qty: qty});
121
+ return this;
122
+ }
123
+ else
124
+ {
125
+ return super.remove();
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Gets the amount of items in the list.
131
+ * @readonly
132
+ * @type {number}
133
+ */
134
+ get length()
135
+ {
136
+ return ui.sendToGUI({control: this.id, get: "length"});
137
+ }
138
+
139
+ /**
140
+ * Gets, sets or updates an item at a specified index. Check usage examples below.
141
+ *
142
+ * @param {number} index - Index of the list item
143
+ * @param {ListItem} [item] - Item object. See object format in the example of ComboBox.add() documentation.
144
+ * @param {boolean} [update=false] - `true` to update specified item properties with provided item properties, `false` to replace the item with new one. Default is `false`.
145
+ * @returns {List|ListItem} If item argument is passed, then `this` List instance is returned, otherwise item at specified index is returned. If index is out of range, `undefined` is returned.
146
+ * @see ListItem
147
+ * @example
148
+ * const item = list.item(3); // gets the item at index 3
149
+ * list.item(3, {text: "New text", value:"new value"}); // replaces item at index 3
150
+ * list.item(3, {background: "#FF7777"}, true); // changes item's background color at index 3
151
+ */
152
+ item(i)
153
+ {
154
+ if(typeof i !== "number") i = parseInt(i);
155
+ if(!Number.isSafeInteger(i) || i < 0) throw new Error(`Invalid "index" argument passed to List.item(i). A positive number is expected, but received a ${typeof arguments[0]}: ${arguments[0]}.`);
156
+
157
+ if(arguments.length > 1)
158
+ {
159
+ if(typeof arguments[1] !== "object") arguments[1] = {text: String(arguments[1]), id: arguments[1]}; // create object
160
+ arguments[1].index = i;
161
+ arguments[1].update = (arguments.length > 2 && arguments[2] === true);
162
+ ui.sendToGUI({control: this.id, set: "item", value: arguments[1]});
163
+ return this;
164
+ }
165
+ else
166
+ {
167
+ return ui.sendToGUI({control: this.id, get: "item", data: parseInt(i)});
168
+ }
169
+ }
170
+
171
+ /**
172
+ * Sets selected indexes of elements in the list or returns an array of selected indexes.
173
+ *
174
+ * @param {number[]|number|null} [indices] - Array of indexes to be selected, one index number, `null` or -1 to deselect all items
175
+ * @returns {List|Array} When setting, `this` component instance is returned, otherwise an array indexes of selected items is returned.
176
+ */
177
+ selection()
178
+ {
179
+ if(arguments.length > 0)
180
+ {
181
+ var arg1 = arguments[0];
182
+
183
+ ui.sendToGUI({control: this.id, set: "selection", value: Array.isArray(arg1) ? arg1 : ((arg1 === -1 || arg1 == null || arg1 === false) ? [] : [parseInt(arg1)])});
184
+ return this;
185
+ }
186
+ else
187
+ {
188
+ let _i = ui.sendToGUI({control: this.id, get: "selection"});
189
+ return (_i !== null && _i.length !== undefined) ? _i : [];
190
+ }
191
+ }
192
+
193
+ /**
194
+ * Gets an Array of selected items. Returns selected items as an Array of objects, or empty Array if no item is selected.
195
+ *
196
+ * @readonly
197
+ * @type {ListItem[]}
198
+ */
199
+ get selectedItems()
200
+ {
201
+ return this.property("selectedItems", arguments) ?? []; // if return value is NULL, then return empty array
202
+ }
203
+
204
+ /**
205
+ * Sets or gets an index of a selected item. Can be used to make one item at certain index to be selected.
206
+ * To select more than one item make sure to enable multi-selection by selectionMode(SelectionMode.Multiple), and then use selection() method instead.
207
+ *
208
+ * @param {number} [index] - Index of an item to select.
209
+ * @returns {List|number} If index is specified, then `this` component instance is returned, otherwise currently selected index is returned.
210
+ */
211
+ selectedIndex()
212
+ {
213
+ if(arguments.length > 0)
214
+ {
215
+ return this.selection(parseInt(arguments[0]));
216
+ }
217
+ else
218
+ {
219
+ let _i = this.selection();
220
+ return _i.length > 0 ? _i[0] : -1;
221
+ }
222
+ }
223
+
224
+ /**
225
+ * Sets or returns a selection mode, which defines how list items can be selected (only one item, multiple items together as a range, or any combination of items).
226
+ *
227
+ * @param {SelectionMode} mode - One of: SelectionMode.Single, SelectionMode.Multiple, SelectionMode.Range. See {@link SelectionMode}.
228
+ * @returns {SelectionMode|List}
229
+ * @see SelectionMode
230
+ */
231
+ selectionMode()
232
+ {
233
+ if(arguments.length > 0) arguments[0] = String(arguments[0]);
234
+ return this.property("selectionMode", arguments);
235
+ }
236
+
237
+ /**
238
+ * Selects/Deselects all items in the List
239
+ *
240
+ * @param {boolean} [selected=true] - `true` to select all items, `false` to deselect.
241
+ * @return {List} Returns an instance of `this` List for method chaining.
242
+ */
243
+ selectAll(selected = true)
244
+ {
245
+ this.property("selectAll", [selected === true]);
246
+ return this;
247
+ }
248
+
249
+ /**
250
+ * Sets or gets items of the list.
251
+ * @arg {Array.<(object|string|number)>} [items] - Array of items as objects or strings
252
+ * @returns {List|object[]} If items are passed, returns an instance of `this` List, otherwise returns an Object Array of items.
253
+ * @example
254
+ * list.items([{value:1, text:"Label 1", ...}, [{value:2, text:"Label 2", ...}); // Sets items by an array of objects
255
+ * list.items(["Label 1", "Label 2", ...]); // Sets items by an array of strings
256
+ * list.items(["Label 1", {value:1, text:"Label 1", ...}, 45); // Sets items as an array of strings, objects and numbers
257
+ */
258
+ items()
259
+ {
260
+ if(arguments.length > 0)
261
+ {
262
+ ui.sendToGUI({control: this.id, set: "items", value: arguments[0]});
263
+ return this;
264
+ }
265
+ else
266
+ {
267
+ return ui.sendToGUI({control: this.id, get: "items"}) ?? [];
268
+ }
269
+ }
270
+
271
+ /**
272
+ * Removes all items from the list.
273
+ * @returns {List} Returns an instance of ths List.
274
+ */
275
+ clear()
276
+ {
277
+ ui.sendToGUI({control: this.id, set: "clear"});
278
+ return this;
279
+ }
280
+
281
+ /**
282
+ * Sets or get layout of the list (Vertical, Horizontal Wrap, or Vertical Wrap).
283
+ * Default is Vertical.
284
+ *
285
+ * @param {List.Layout} [layout] - List.Layout.[Vertical|HorizontalWrap|VerticalWrap]
286
+ * @return {List.Layout|List} Returns `this` component instance if argument is provided, otherwise returns the current layout.
287
+ */
288
+ layout(...args)
289
+ {
290
+ if(args.length > 0) args[0] = parseInt(args[0]);
291
+ return this.property("layout", args);
292
+ }
293
+
294
+ /**
295
+ * Sets the size of each item in the list.
296
+ *
297
+ * @param {number|object} [width_or_both] - Width of items as a number, same width and height as a number, or size Object to set both width and height (see examples below).
298
+ * @param {number} [height] - Height of items.
299
+ * @return {object|List} Returns `this` component instance if at least one argument is provided, otherwise returns the current item size.
300
+ * @example
301
+ * itemSize(null) - Resets item size to default (auto size).
302
+ * itemSize(100) - Both width and height are set to 100px.
303
+ * itemSize(100, 150) - width 100, height 150
304
+ * itemSize({width:100, height:150})
305
+ * itemSize() - retrieves size and returns {width:number, height:number} or NULL if it was not previously set.
306
+ */
307
+ itemSize()
308
+ {
309
+ let _a = arguments;
310
+
311
+ if(_a.length === 0)
312
+ {
313
+ return this.property("itemSize", []);
314
+ }
315
+ else if(_a.length === 1)
316
+ {
317
+ if(_a[0] === null)
318
+ {
319
+ _a[0] = [-1, -1];
320
+ }
321
+ else if(typeof _a[0] === "object")
322
+ {
323
+ if(_a[0].width !== undefined && _a[0].height !== undefined)
324
+ {
325
+ _a[0] = [parseInt(_a[0].width), parseInt(_a[0].height)];
326
+ }
327
+ else
328
+ {
329
+ _a[0] = null;
330
+ }
331
+ }
332
+ else
333
+ {
334
+ _a[0] = [parseInt(_a[0]), parseInt(_a[0])];
335
+ }
336
+ }
337
+ else if(_a.length > 1)
338
+ {
339
+ _a[0] = [parseInt(_a[0]), parseInt(_a[1])];
340
+ }
341
+
342
+ return this.property("itemSize", [_a[0]]);
343
+ }
344
+
345
+ /**
346
+ * Sets or gets an alignment of item's label and icon within a list item.
347
+ *
348
+ * @param {string} [alignment] - One or combination of alignment describing strings: top, bottom, left, right, and center. Maximum one horizontal and maximum one vertical alignment is allowed.
349
+ * @return {string|List} Returns `this` component instance if at least one argument is provided, otherwise returns the current layout.
350
+ * @example
351
+ * list.alignment("top left"); // positions label at the top left corner of list item
352
+ * list.alignment("bottom"); // positions label at the bottom-center of list item
353
+ * list.alignment("top center"); // positions label at the top-center of list item
354
+ * list.alignment("center"); // positions label at the center vertically and horizontally
355
+ */
356
+ alignment()
357
+ {
358
+ return this.property("alignment", arguments);
359
+ }
360
+
361
+ /**
362
+ * Gets or sets a padding for each item in the list. See example below.
363
+ *
364
+ * @param {number|string} [padding] - Number for same padding on all sides, string to specify padding for each side "top right bottom left"
365
+ * @return {string|List} Returns `this` component instance if at least one argument is provided, otherwise returns current padding.
366
+ * @example
367
+ * list.itemPadding(3); // defines same padding for top, right, bottom and left.
368
+ * list.itemPadding("5 0 5 3"); // defines padding for each side separately, top=5, right=0, bottom=5 and left=3.
369
+ * const padding = list.itemPadding(); // gets the padding object
370
+ */
371
+ itemPadding(...args)
372
+ {
373
+ if(args.length === 0)
374
+ {
375
+ const padding = this.property("itemPadding", []);
376
+ return `${padding.top ?? 0} ${padding.right ?? 0} ${padding.bottom ?? 0} ${padding.left ?? 0}`;
377
+ }
378
+ else
379
+ {
380
+ let padding;
381
+
382
+ if(typeof args[0] === "string")
383
+ {
384
+ const nums = args[0].match(/\d+/g)?.map(Number).slice(0, 4) || [];
385
+ padding = {top: nums[0] ?? 0, right: nums[1] ?? 0, bottom: nums[2] ?? 0, left: nums[3] ?? 0};
386
+ }
387
+ else
388
+ {
389
+ args[0] = parseInt(args[0]);
390
+ padding = {top: args[0], right: args[0], bottom: args[0], left: args[0]};
391
+ }
392
+
393
+ return this.property("itemPadding", [padding]);
394
+ }
395
+ }
396
+
397
+ /**
398
+ * Sets or gets whether to allow selecting list items with a click of a right mouse button.
399
+ * @param {boolean} [enable] - Boolean value that enables or disables right-click item selection.
400
+ * @return {boolean|List} Returns `this` component instance if at least one argument is provided, otherwise returns current value.
401
+ */
402
+ rightClickSelect(...args)
403
+ {
404
+ if(args.length > 0) args[0] = (args[0] === true); // ensure boolean
405
+ return this.property("rightClickSelect", arguments);
406
+ }
407
+
408
+ /**
409
+ * Finds items whose text matches the string argument. If item is {text: "First Item", value: "item1"}, it should be found by passing value "First Item".
410
+ *
411
+ * @param {string} value - Search by this text
412
+ * @return {ListItem[]} Returns an array of found items. Each found item will have an `index` property fo convenience.
413
+ */
414
+ findByText(value)
415
+ {
416
+ return ui.sendToGUI({control: this.id, get: "findBy", data: {by: "text", q: value}});
417
+ }
418
+
419
+ /**
420
+ * Finds first item whose value matches the argument. If item is {text: "First Item", value: "item1", id: 1}, it should be found by passing value "item1".
421
+ *
422
+ * @param {string|number} value - Search by this text or number
423
+ * @return {ListItem[]} Returns an array of found items. Each found item will have an `index` property fo convenience.
424
+ */
425
+ findByValue(value)
426
+ {
427
+ return ui.sendToGUI({control: this.id, get: "findBy", data: {by: "value", q: value}});
428
+ }
429
+
430
+ /**
431
+ * Finds first item whose ID matches the argument. If item is {text: "First Item", value: "item1", id: 1}, it should be found by passing value 1.
432
+ *
433
+ * @param {string|number} value - Search by this text or number
434
+ * @return {ListItem[]} Returns an array of found items. Each found item will have an `index` property fo convenience.
435
+ */
436
+ findByID(value)
437
+ {
438
+ return ui.sendToGUI({control: this.id, get: "findBy", data: {by: "id", q: value}});
439
+ }
440
+
441
+ /**
442
+ * Scrolls the scroll bars to make sure the item at specified index is visible. If position is specified, the item will be placed at the specified position between the top and bottom of the List component.
443
+ *
444
+ * @param {number} index - Index of a list item to make visible.
445
+ * @param {number} [position] - A decimal number between 0 and 1 indicating vertical position in percentages (0% - 100% of the height of the component). If omitted, the item will only become visible, but not at a specific location.
446
+ */
447
+ scrollToIndex(index = 0, position = undefined)
448
+ {
449
+ if(typeof index !== "number") throw new Error(`List.scrollToIndex(index) expects a number as a first argument, but ${typeof index} is received.`);
450
+ return this.property("scrollToIndex", [{index: index, position: position}]);
451
+ }
452
+ }