1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//build: 20240329
//Dropdown control
import utils from "./uiUtils.js"
import base from "./uiBase.js"
let dropdown = {}
 
dropdown.build = function (id, parent) {
    let temp = utils.validateBuild(dropdown.all, id, parent, 'dropdown')
    let my = {type: 'dropdown'}
    my.obj = new utils.GG.NativeDropdown({ uid: id }, temp)
    my.id = id
    /**
     * Set dropdown option content
     * @param {array} arr Option content, a string array where each item is an option
     */
    my.setOptions = function (arr) {
        this.obj.setOptions(arr.join('\n'))
    }
    /**
     * Get dropdown option list
     * @returns Returns list object, a base class object that can have its font set separately
     */
    my.getList = function () {
        let res = {}
        res.obj = this.obj.getList()
        return Object.assign(res, base)
    }
    /**
     * Set selected item, this will be selected by default
     * @param {number} index Selected item index
     */
    my.setSelected = function (index) {
        this.obj.setSelected(index)
    }
    /**
     * Get selected item index
     * @returns Returns the currently selected index
     */
    my.getSelected = function () {
        return this.obj.getSelected()
    }
    /**
     * Set dropdown accessory icon, default is a downward arrow
     * @param {string} icon Icon address
     */
    my.setSymbol = function (icon) {
        this.obj.setSymbol(icon)
    }
    let comp = Object.assign(my, base);
    utils.setParent(this.all, comp, parent)
    return comp;
}
export default dropdown;