forked from mbk-lab/rui_orig
2
0
Fork 0

bug fixing

This commit is contained in:
Alexei Anoshenko 2022-08-24 15:00:25 +03:00
parent 3d52de161b
commit 379d98fe4a
2 changed files with 15 additions and 67 deletions

View File

@ -206,61 +206,13 @@ func checkboxKeyListener(view View, event KeyEvent) {
} }
func (button *checkboxData) setChangedListener(value any) bool { func (button *checkboxData) setChangedListener(value any) bool {
if value == nil { listeners, ok := valueToEventListeners[Checkbox, bool](value)
if len(button.checkedListeners) > 0 { if !ok {
button.checkedListeners = []func(Checkbox, bool){} return false
} } else if listeners == nil {
return true listeners = []func(Checkbox, bool){}
}
switch value := value.(type) {
case func(Checkbox, bool):
button.checkedListeners = []func(Checkbox, bool){value}
case func(bool):
fn := func(_ Checkbox, checked bool) {
value(checked)
}
button.checkedListeners = []func(Checkbox, bool){fn}
case []func(Checkbox, bool):
button.checkedListeners = value
case []func(bool):
listeners := make([]func(Checkbox, bool), len(value))
for i, val := range value {
if val == nil {
return false
}
listeners[i] = func(_ Checkbox, checked bool) {
val(checked)
}
}
button.checkedListeners = listeners
case []any:
listeners := make([]func(Checkbox, bool), len(value))
for i, val := range value {
if val == nil {
return false
}
switch val := val.(type) {
case func(Checkbox, bool):
listeners[i] = val
case func(bool):
listeners[i] = func(_ Checkbox, date bool) {
val(date)
}
default:
return false
}
}
button.checkedListeners = listeners
} }
button.checkedListeners = listeners
return true return true
} }
@ -370,7 +322,7 @@ func (button *checkboxData) htmlSubviews(self View, buffer *strings.Builder) {
} }
func (button *checkboxData) cssHorizontalAlign() string { func (button *checkboxData) cssHorizontalAlign() string {
align := GetCheckboxHorizontalAlign(button, "") align := GetHorizontalAlign(button, "")
values := enumProperties[CellHorizontalAlign].cssValues values := enumProperties[CellHorizontalAlign].cssValues
if align >= 0 && align < len(values) { if align >= 0 && align < len(values) {
return values[align] return values[align]
@ -379,7 +331,7 @@ func (button *checkboxData) cssHorizontalAlign() string {
} }
func (button *checkboxData) cssVerticalAlign() string { func (button *checkboxData) cssVerticalAlign() string {
align := GetCheckboxVerticalAlign(button, "") align := GetVerticalAlign(button, "")
values := enumProperties[CellVerticalAlign].cssValues values := enumProperties[CellVerticalAlign].cssValues
if align >= 0 && align < len(values) { if align >= 0 && align < len(values) {
return values[align] return values[align]

View File

@ -1086,19 +1086,15 @@ func (listView *listViewData) onItemResize(self View, index string, x, y, width,
} }
// GetVerticalAlign return the vertical align of a list: TopAlign (0), BottomAlign (1), CenterAlign (2), StretchAlign (3) // GetVerticalAlign return the vertical align of a list: TopAlign (0), BottomAlign (1), CenterAlign (2), StretchAlign (3)
func GetVerticalAlign(view View) int { // If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
if align, ok := enumProperty(view, VerticalAlign, view.Session(), TopAlign); ok { func GetVerticalAlign(view View, subviewID string) int {
return align return enumStyledProperty(view, subviewID, VerticalAlign, TopAlign, false)
}
return TopAlign
} }
// GetHorizontalAlign return the vertical align of a list: LeftAlign (0), RightAlign (1), CenterAlign (2), StretchAlign (3) // GetHorizontalAlign return the vertical align of a list/checkbox: LeftAlign (0), RightAlign (1), CenterAlign (2), StretchAlign (3)
func GetHorizontalAlign(view View) int { // If the second argument (subviewID) is "" then a value from the first argument (view) is returned.
if align, ok := enumProperty(view, HorizontalAlign, view.Session(), LeftAlign); ok { func GetHorizontalAlign(view View, subviewID string) int {
return align return enumStyledProperty(view, subviewID, HorizontalAlign, LeftAlign, false)
}
return LeftAlign
} }
// GetListItemClickedListeners returns a ListItemClickedListener of the ListView. // GetListItemClickedListeners returns a ListItemClickedListener of the ListView.