mirror of https://github.com/anoshenko/rui.git
Added "item-separators" property to DropDownList and GetDropDownItemSeparators function
This commit is contained in:
parent
10cf3a69fc
commit
5707ca3088
|
@ -5,6 +5,7 @@
|
||||||
* Added "transform" property and Transform interface
|
* Added "transform" property and Transform interface
|
||||||
* Added OpenRawResource, GetCheckboxChangedListeners functions
|
* Added OpenRawResource, GetCheckboxChangedListeners functions
|
||||||
* Added RemoveClientItem method to Session interface
|
* Added RemoveClientItem method to Session interface
|
||||||
|
* Added "item-separators" property to DropDownList and GetDropDownItemSeparators function
|
||||||
* Added NewPath and NewPathFromSvg methods to Canvas interface
|
* Added NewPath and NewPathFromSvg methods to Canvas interface
|
||||||
* Removed NewPath function
|
* Removed NewPath function
|
||||||
* Removed Reset methods from Path interface
|
* Removed Reset methods from Path interface
|
||||||
|
|
|
@ -3643,6 +3643,13 @@ float32, float64, int, int8…int64, uint, uint8…uint64.
|
||||||
|
|
||||||
func GetDropDownDisabledItems(view View, subviewID ...string) []int
|
func GetDropDownDisabledItems(view View, subviewID ...string) []int
|
||||||
|
|
||||||
|
Между пунктами списка можно добавлять разделителями. Для этого используется свойство "item-separators" (константа ItemSeparators).
|
||||||
|
Данному свойству присваивается массив индексов пунктов после которых необходимо добавить разделители.
|
||||||
|
Свойству "item-separators" могут присваиваться теже типы данных что и свойству "disabled-items".
|
||||||
|
Прочитать значение свойства "item-separators" можно с помощью функции
|
||||||
|
|
||||||
|
func GetDropDownItemSeparators(view View, subviewID ...string) []int
|
||||||
|
|
||||||
Выбранное значение определяется int свойством "current" (константа Current). Значение по умолчанию 0.
|
Выбранное значение определяется int свойством "current" (константа Current). Значение по умолчанию 0.
|
||||||
Прочитать значение данного свойства можно с помощью функции
|
Прочитать значение данного свойства можно с помощью функции
|
||||||
|
|
||||||
|
|
|
@ -3620,6 +3620,13 @@ You can read the value of the "disabled-items" property using the function
|
||||||
|
|
||||||
func GetDropDownDisabledItems(view View, subviewID ...string) []int
|
func GetDropDownDisabledItems(view View, subviewID ...string) []int
|
||||||
|
|
||||||
|
You can add separators between list items. To do this, use the "item-separators" property (the ItemSeparators constant).
|
||||||
|
This property is assigned an array of item indices after which separators must be added.
|
||||||
|
The "item-separators" property can be assigned the same data types as the "disabled-items" property.
|
||||||
|
You can read the value of the "item-separators" property using the function
|
||||||
|
|
||||||
|
func GetDropDownItemSeparators(view View, subviewID ...string) []int
|
||||||
|
|
||||||
The selected value is determined by the int property "current" (Current constant). The default is 0.
|
The selected value is determined by the int property "current" (Current constant). The default is 0.
|
||||||
You can read the value of this property using the function
|
You can read the value of this property using the function
|
||||||
|
|
||||||
|
|
135
dropDownList.go
135
dropDownList.go
|
@ -21,6 +21,7 @@ type dropDownListData struct {
|
||||||
viewData
|
viewData
|
||||||
items []string
|
items []string
|
||||||
disabledItems []any
|
disabledItems []any
|
||||||
|
itemSeparators []any
|
||||||
dropDownListener []func(DropDownList, int, int)
|
dropDownListener []func(DropDownList, int, int)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,6 +43,7 @@ func (list *dropDownListData) init(session Session) {
|
||||||
list.hasHtmlDisabled = true
|
list.hasHtmlDisabled = true
|
||||||
list.items = []string{}
|
list.items = []string{}
|
||||||
list.disabledItems = []any{}
|
list.disabledItems = []any{}
|
||||||
|
list.itemSeparators = []any{}
|
||||||
list.dropDownListener = []func(DropDownList, int, int){}
|
list.dropDownListener = []func(DropDownList, int, int){}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,6 +79,15 @@ func (list *dropDownListData) remove(tag string) {
|
||||||
list.propertyChangedEvent(tag)
|
list.propertyChangedEvent(tag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case ItemSeparators, "separators":
|
||||||
|
if len(list.itemSeparators) > 0 {
|
||||||
|
list.itemSeparators = []any{}
|
||||||
|
if list.created {
|
||||||
|
updateInnerHTML(list.htmlID(), list.session)
|
||||||
|
}
|
||||||
|
list.propertyChangedEvent(ItemSeparators)
|
||||||
|
}
|
||||||
|
|
||||||
case DropDownEvent:
|
case DropDownEvent:
|
||||||
if len(list.dropDownListener) > 0 {
|
if len(list.dropDownListener) > 0 {
|
||||||
list.dropDownListener = []func(DropDownList, int, int){}
|
list.dropDownListener = []func(DropDownList, int, int){}
|
||||||
|
@ -95,7 +106,6 @@ func (list *dropDownListData) remove(tag string) {
|
||||||
|
|
||||||
default:
|
default:
|
||||||
list.viewData.remove(tag)
|
list.viewData.remove(tag)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,7 +124,30 @@ func (list *dropDownListData) set(tag string, value any) bool {
|
||||||
return list.setItems(value)
|
return list.setItems(value)
|
||||||
|
|
||||||
case DisabledItems:
|
case DisabledItems:
|
||||||
return list.setDisabledItems(value)
|
items, ok := list.parseIndicesArray(value)
|
||||||
|
if !ok {
|
||||||
|
notCompatibleType(tag, value)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
list.disabledItems = items
|
||||||
|
if list.created {
|
||||||
|
updateInnerHTML(list.htmlID(), list.session)
|
||||||
|
}
|
||||||
|
list.propertyChangedEvent(tag)
|
||||||
|
return true
|
||||||
|
|
||||||
|
case ItemSeparators, "separators":
|
||||||
|
items, ok := list.parseIndicesArray(value)
|
||||||
|
if !ok {
|
||||||
|
notCompatibleType(ItemSeparators, value)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
list.itemSeparators = items
|
||||||
|
if list.created {
|
||||||
|
updateInnerHTML(list.htmlID(), list.session)
|
||||||
|
}
|
||||||
|
list.propertyChangedEvent(ItemSeparators)
|
||||||
|
return true
|
||||||
|
|
||||||
case DropDownEvent:
|
case DropDownEvent:
|
||||||
listeners, ok := valueToEventWithOldListeners[DropDownList, int](value)
|
listeners, ok := valueToEventWithOldListeners[DropDownList, int](value)
|
||||||
|
@ -312,89 +345,75 @@ func anyToStringArray(value any) ([]string, bool) {
|
||||||
return []string{}, false
|
return []string{}, false
|
||||||
}
|
}
|
||||||
|
|
||||||
func (list *dropDownListData) setDisabledItems(value any) bool {
|
func (list *dropDownListData) parseIndicesArray(value any) ([]any, bool) {
|
||||||
switch value := value.(type) {
|
switch value := value.(type) {
|
||||||
case []int:
|
case []int:
|
||||||
list.disabledItems = make([]any, len(value))
|
items := make([]any, len(value))
|
||||||
for i, n := range value {
|
for i, n := range value {
|
||||||
list.disabledItems[i] = n
|
items[i] = n
|
||||||
}
|
}
|
||||||
|
return items, true
|
||||||
|
|
||||||
case []any:
|
case []any:
|
||||||
disabledItems := make([]any, len(value))
|
items := make([]any, len(value))
|
||||||
for i, val := range value {
|
for i, val := range value {
|
||||||
if val == nil {
|
if val == nil {
|
||||||
notCompatibleType(DisabledItems, value)
|
return nil, false
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
switch val := val.(type) {
|
switch val := val.(type) {
|
||||||
case string:
|
case string:
|
||||||
if isConstantName(val) {
|
if isConstantName(val) {
|
||||||
disabledItems[i] = val
|
items[i] = val
|
||||||
} else {
|
} else {
|
||||||
n, err := strconv.Atoi(val)
|
n, err := strconv.Atoi(val)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notCompatibleType(DisabledItems, value)
|
return nil, false
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
disabledItems[i] = n
|
items[i] = n
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
if n, ok := isInt(val); ok {
|
if n, ok := isInt(val); ok {
|
||||||
disabledItems[i] = n
|
items[i] = n
|
||||||
} else {
|
} else {
|
||||||
notCompatibleType(DisabledItems, value)
|
return nil, false
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
list.disabledItems = disabledItems
|
return items, true
|
||||||
|
|
||||||
case string:
|
case string:
|
||||||
values := strings.Split(value, ",")
|
values := strings.Split(value, ",")
|
||||||
disabledItems := make([]any, len(values))
|
items := make([]any, len(values))
|
||||||
for i, str := range values {
|
for i, str := range values {
|
||||||
str = strings.Trim(str, " ")
|
str = strings.Trim(str, " ")
|
||||||
if str == "" {
|
if str == "" {
|
||||||
notCompatibleType(DisabledItems, value)
|
return nil, false
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
if isConstantName(str) {
|
if isConstantName(str) {
|
||||||
disabledItems[i] = str
|
items[i] = str
|
||||||
} else {
|
} else {
|
||||||
n, err := strconv.Atoi(str)
|
n, err := strconv.Atoi(str)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
notCompatibleType(DisabledItems, value)
|
return nil, false
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
disabledItems[i] = n
|
items[i] = n
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list.disabledItems = disabledItems
|
return items, true
|
||||||
|
|
||||||
case []DataValue:
|
case []DataValue:
|
||||||
disabledItems := make([]any, 0, len(value))
|
items := make([]any, 0, len(value))
|
||||||
for _, val := range value {
|
for _, val := range value {
|
||||||
if !val.IsObject() {
|
if !val.IsObject() {
|
||||||
disabledItems = append(disabledItems, val.Value())
|
items = append(items, val.Value())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return list.setDisabledItems(disabledItems)
|
return list.parseIndicesArray(items)
|
||||||
|
|
||||||
default:
|
|
||||||
notCompatibleType(DisabledItems, value)
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if list.created {
|
return nil, false
|
||||||
updateInnerHTML(list.htmlID(), list.session)
|
|
||||||
}
|
|
||||||
|
|
||||||
list.propertyChangedEvent(Items)
|
|
||||||
return true
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (list *dropDownListData) Get(tag string) any {
|
func (list *dropDownListData) Get(tag string) any {
|
||||||
|
@ -409,6 +428,9 @@ func (list *dropDownListData) get(tag string) any {
|
||||||
case DisabledItems:
|
case DisabledItems:
|
||||||
return list.disabledItems
|
return list.disabledItems
|
||||||
|
|
||||||
|
case ItemSeparators:
|
||||||
|
return list.itemSeparators
|
||||||
|
|
||||||
case Current:
|
case Current:
|
||||||
result, _ := intProperty(list, Current, list.session, 0)
|
result, _ := intProperty(list, Current, list.session, 0)
|
||||||
return result
|
return result
|
||||||
|
@ -433,6 +455,7 @@ func (list *dropDownListData) htmlSubviews(self View, buffer *strings.Builder) {
|
||||||
current := GetCurrent(list)
|
current := GetCurrent(list)
|
||||||
notTranslate := GetNotTranslate(list)
|
notTranslate := GetNotTranslate(list)
|
||||||
disabledItems := GetDropDownDisabledItems(list)
|
disabledItems := GetDropDownDisabledItems(list)
|
||||||
|
separators := GetDropDownItemSeparators(list)
|
||||||
for i, item := range list.items {
|
for i, item := range list.items {
|
||||||
disabled := false
|
disabled := false
|
||||||
for _, index := range disabledItems {
|
for _, index := range disabledItems {
|
||||||
|
@ -455,6 +478,12 @@ func (list *dropDownListData) htmlSubviews(self View, buffer *strings.Builder) {
|
||||||
|
|
||||||
buffer.WriteString(item)
|
buffer.WriteString(item)
|
||||||
buffer.WriteString("</option>")
|
buffer.WriteString("</option>")
|
||||||
|
for _, index := range separators {
|
||||||
|
if i == index {
|
||||||
|
buffer.WriteString("<hr>")
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -512,15 +541,9 @@ func GetDropDownItems(view View, subviewID ...string) []string {
|
||||||
return []string{}
|
return []string{}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDropDownDisabledItems return the list of DropDownList disabled item indexes.
|
func getIndicesArray(view View, tag string) []int {
|
||||||
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
|
||||||
func GetDropDownDisabledItems(view View, subviewID ...string) []int {
|
|
||||||
if len(subviewID) > 0 && subviewID[0] != "" {
|
|
||||||
view = ViewByID(view, subviewID[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
if view != nil {
|
if view != nil {
|
||||||
if value := view.Get(DisabledItems); value != nil {
|
if value := view.Get(tag); value != nil {
|
||||||
if values, ok := value.([]any); ok {
|
if values, ok := value.([]any); ok {
|
||||||
count := len(values)
|
count := len(values)
|
||||||
if count > 0 {
|
if count > 0 {
|
||||||
|
@ -547,3 +570,23 @@ func GetDropDownDisabledItems(view View, subviewID ...string) []int {
|
||||||
}
|
}
|
||||||
return []int{}
|
return []int{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDropDownDisabledItems return an array of disabled(non selectable) items indices of DropDownList.
|
||||||
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
||||||
|
func GetDropDownDisabledItems(view View, subviewID ...string) []int {
|
||||||
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
||||||
|
view = ViewByID(view, subviewID[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
return getIndicesArray(view, DisabledItems)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDropDownItemSeparators return 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 GetDropDownItemSeparators(view View, subviewID ...string) []int {
|
||||||
|
if len(subviewID) > 0 && subviewID[0] != "" {
|
||||||
|
view = ViewByID(view, subviewID[0])
|
||||||
|
}
|
||||||
|
|
||||||
|
return getIndicesArray(view, ItemSeparators)
|
||||||
|
}
|
||||||
|
|
|
@ -457,8 +457,13 @@ const (
|
||||||
Items = "items"
|
Items = "items"
|
||||||
|
|
||||||
// DisabledItems is the constant for the "disabled-items" property tag.
|
// DisabledItems is the constant for the "disabled-items" property tag.
|
||||||
|
// The "disabled-items" []int property specifies an array of disabled(non selectable) items indices of DropDownList.
|
||||||
DisabledItems = "disabled-items"
|
DisabledItems = "disabled-items"
|
||||||
|
|
||||||
|
// ItemSeparators is the constant for the "item-separators" property tag.
|
||||||
|
// The "item-separators" []int property specifies an array of indices of DropDownList items after which a separator should be added.
|
||||||
|
ItemSeparators = "item-separators"
|
||||||
|
|
||||||
// Current is the constant for the "current" property tag.
|
// Current is the constant for the "current" property tag.
|
||||||
Current = "current"
|
Current = "current"
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue