DropDownList
Regular state
Expanded state
An element that allows to select an item from a list of options. We can set the possible values for the drop-down list by assigning them to the "items" property. The selected item is determined by the "current" property, which defaults to 0
Create from source
func NewDropDownList(session Session, params Params) DropDownList
Create new drop down list object and returns its interface
Create from resource
DropDownList {
id = dropDownList,
current = 0,
items = [
"item 1",
"item 2"
],
}
Interface description
Inherit methods, properties and events from View
Properties
"current"
Current selected item
Constant: Current
Types: int
, string
Values
int | string | Description |
---|---|---|
-1 |
"-1" | No item has been selected |
>= 0 |
>= "0" | Index of selected item |
"disabled-items"
An array of disabled(non selectable) items indices
Constant: DisabledItems
Types: []int
, string
, []string
, []any
containing elements of string
or int
Internal type is []int
, other types converted to it during assignment
Rules of conversion
[]int
- Array of indices
string
- Single index value or multiple index values separated by comma(,
)
[]string
- Array of indices in text format
[]any
- Array of strings or integer values
Examples
DropDownList {
items = [
"Value 1",
"Value 2",
"Value 3",
"Value 4",
"Value 5",
],
disabled-items = "0, 3",
}
dropdown := rui.NewDropDownList(session, rui.Params{
rui.Items: []string{
"Value 1",
"Value 2",
"Value 3",
"Value 4",
"Value 5",
},
rui.DisabledItems: []int{
0, 3,
},
})
"items"
Array of data elements
Constant: Items
Types: []string
, string
, []fmt.Stringer
, []Color
, []SizeUnit
, []AngleUnit
, []any
containing elements of string
, fmt.Stringer
, bool
, rune
, float32
, float64
, int
, int8
… int64
, uint
, uint8
… uint64
Internal type is []string
, other types converted to it during assignment
Conversion rules
string
- contain single item
[]string
- an array of items
[]fmt.Stringer
- an array of objects convertible to string
[]Color
- An array of color values which will be converted to a string array
[]SizeUnit
- an array of size unit values which will be converted to a string array
[]any
- this array must contain only types which were listed in Types section
Examples
DropDownList {
items = [
"Value 1",
"Value 2",
],
}
DropDownList {
items = [
1px,
1em,
],
}
DropDownList {
items = [
#FF000000,
#FFFFFFFF,
],
}
dropdown := rui.NewDropDownList(session, rui.Params{
rui.Items: []string{
"Value 1",
"Value 2",
},
})
dropdown := rui.NewDropDownList(session, rui.Params{
rui.Items: []rui.SizeUnit{
rui.Px(1),
rui.Em(1),
},
})
dropdown := rui.NewDropDownList(session, rui.Params{
rui.Items: []rui.Color{
rui.Black,
rui.White,
},
})
"item-separators"
An array of indices of DropDownList
items after which a separator should be added
Constant: ItemSeparators
Types: []int
, string
, []string
, []any
containing elements of string
or int
Internal type is []int
, other types converted to it during assignment
Rules of conversion
[]int
- Array of indices
string
- Single index value or multiple index values separated by comma(,
)
[]string
- Array of indices in text format
[]any
- Array of strings or integer values
Examples
DropDownList {
items = [
"Value 1",
"Value 2",
"Value 3",
"Value 4",
"Value 5",
],
item-separators = "1, 3",
}
dropdown := rui.NewDropDownList(session, rui.Params{
rui.Items: []string{
"Value 1",
"Value 2",
"Value 3",
"Value 4",
"Value 5",
},
rui.ItemSeparators: []int{
1, 3,
},
})
Events
"drop-down-event"
Occur when a list item becomes selected
Constant: DropDownEvent
General listener format:
func(list rui.DropDownList, index int)
where: * list - Interface of a drop down list which generated this event * index - Index of a newly selected item
Allowed listener formats:
Related global functions
func DropDownListByID(rootView View, id string) DropDownList
Return a DropDownListView
with id equal to the argument of the function or nil if there is no such View or View is not a DropDownListView
func GetDropDownDisabledItems(view View, subviewID ...string) []int
Return the list of DropDownList
disabled item indexes. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.
func GetDropDownItems(view View, subviewID ...string) []string
Return the DropDownList
items list. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.
func GetDropDownItemSeparators(view View, subviewID ...string) []int
Returns an array of indices of DropDownList
items after which a separator should be added. If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetDropDownListeners(view View, subviewID ...string) []func(DropDownList, int, int)
Returns the "drop-down-event" listener list. If there are no listeners then the empty list is returned. If the second argument (subviewID) is not specified or is an empty string then a value from the first argument (view) is returned.