forked from mbk-lab/rui_orig
2
0
Fork 0

Bug fixing

This commit is contained in:
anoshenko 2023-05-18 12:26:54 +03:00
parent dc2ea14cac
commit 3d44aa3ba3
4 changed files with 127 additions and 58 deletions

View File

@ -129,78 +129,92 @@ func (listView *listViewData) remove(tag string) {
case Gap: case Gap:
listView.remove(ListRowGap) listView.remove(ListRowGap)
listView.remove(ListColumnGap) listView.remove(ListColumnGap)
return
case Checked: case Checked:
if len(listView.checkedItem) > 0 { if len(listView.checkedItem) == 0 {
return
}
listView.checkedItem = []int{} listView.checkedItem = []int{}
if listView.created { if listView.created {
updateInnerHTML(listView.htmlID(), listView.session) updateInnerHTML(listView.htmlID(), listView.session)
} }
listView.propertyChangedEvent(tag)
}
case Items: case Items:
if listView.adapter != nil { if listView.adapter == nil {
return
}
listView.adapter = nil listView.adapter = nil
if listView.created { if listView.created {
updateInnerHTML(listView.htmlID(), listView.session) updateInnerHTML(listView.htmlID(), listView.session)
} }
listView.propertyChangedEvent(tag)
}
case Orientation, ListWrap: case Orientation, ListWrap:
if _, ok := listView.properties[tag]; ok { if _, ok := listView.properties[tag]; !ok {
return
}
delete(listView.properties, tag) delete(listView.properties, tag)
if listView.created { if listView.created {
updateCSSStyle(listView.htmlID(), listView.session) updateCSSStyle(listView.htmlID(), listView.session)
} }
listView.propertyChangedEvent(tag)
}
case Current: case Current:
current := GetCurrent(listView) current := GetCurrent(listView)
if current == -1 {
return
}
delete(listView.properties, tag) delete(listView.properties, tag)
if listView.created { if listView.created {
updateInnerHTML(listView.htmlID(), listView.session) htmlID := listView.htmlID()
session := listView.session
session.removeProperty(htmlID, "data-current")
updateInnerHTML(htmlID, session)
} }
if current != -1 { if current != -1 {
for _, listener := range listView.selectedListeners { for _, listener := range listView.selectedListeners {
listener(listView, -1) listener(listView, -1)
} }
listView.propertyChangedEvent(tag)
} }
case ItemWidth, ItemHeight, ItemHorizontalAlign, ItemVerticalAlign, ItemCheckbox, case ItemWidth, ItemHeight, ItemHorizontalAlign, ItemVerticalAlign, ItemCheckbox,
CheckboxHorizontalAlign, CheckboxVerticalAlign, ListItemStyle, CurrentStyle, CurrentInactiveStyle: CheckboxHorizontalAlign, CheckboxVerticalAlign:
if _, ok := listView.properties[tag]; ok { if _, ok := listView.properties[tag]; !ok {
return
}
delete(listView.properties, tag) delete(listView.properties, tag)
if listView.created { if listView.created {
updateInnerHTML(listView.htmlID(), listView.session) updateInnerHTML(listView.htmlID(), listView.session)
} }
listView.propertyChangedEvent(tag)
case ListItemStyle, CurrentStyle, CurrentInactiveStyle:
if !listView.setItemStyle(tag, "") {
return
} }
case ListItemClickedEvent: case ListItemClickedEvent:
if len(listView.clickedListeners) > 0 { if len(listView.clickedListeners) == 0 {
listView.clickedListeners = []func(ListView, int){} return
listView.propertyChangedEvent(tag)
} }
listView.clickedListeners = []func(ListView, int){}
case ListItemSelectedEvent: case ListItemSelectedEvent:
if len(listView.selectedListeners) > 0 { if len(listView.selectedListeners) == 0 {
listView.selectedListeners = []func(ListView, int){} return
listView.propertyChangedEvent(tag)
} }
listView.selectedListeners = []func(ListView, int){}
case ListItemCheckedEvent: case ListItemCheckedEvent:
if len(listView.checkedListeners) > 0 { if len(listView.checkedListeners) == 0 {
listView.checkedListeners = []func(ListView, []int){} return
listView.propertyChangedEvent(tag)
} }
listView.checkedListeners = []func(ListView, []int){}
default: default:
listView.viewData.remove(tag) listView.viewData.remove(tag)
return
} }
listView.propertyChangedEvent(tag)
} }
func (listView *listViewData) Set(tag string, value any) bool { func (listView *listViewData) Set(tag string, value any) bool {
@ -268,11 +282,20 @@ func (listView *listViewData) set(tag string, value any) bool {
if !listView.setIntProperty(Current, value) { if !listView.setIntProperty(Current, value) {
return false return false
} }
current := GetCurrent(listView) current := GetCurrent(listView)
if oldCurrent == current { if oldCurrent == current {
return true return true
} }
if listView.created {
htmlID := listView.htmlID()
if current >= 0 {
listView.session.updateProperty(htmlID, "data-current", fmt.Sprintf("%s-%d", htmlID, current))
} else {
listView.session.removeProperty(htmlID, "data-current")
}
}
for _, listener := range listView.selectedListeners { for _, listener := range listView.selectedListeners {
listener(listView, current) listener(listView, current)
} }
@ -290,12 +313,7 @@ func (listView *listViewData) set(tag string, value any) bool {
} }
case ListItemStyle, CurrentStyle, CurrentInactiveStyle: case ListItemStyle, CurrentStyle, CurrentInactiveStyle:
switch value := value.(type) { if !listView.setItemStyle(tag, value) {
case string:
listView.properties[tag] = value
default:
notCompatibleType(tag, value)
return false return false
} }
@ -310,6 +328,33 @@ func (listView *listViewData) set(tag string, value any) bool {
return true return true
} }
func (listView *listViewData) setItemStyle(tag string, value any) bool {
switch value := value.(type) {
case string:
if value == "" {
delete(listView.properties, tag)
} else {
listView.properties[tag] = value
}
default:
notCompatibleType(tag, value)
return false
}
if listView.created {
switch tag {
case CurrentStyle:
listView.session.updateProperty(listView.htmlID(), "data-focusitemstyle", listView.currentStyle())
case CurrentInactiveStyle:
listView.session.updateProperty(listView.htmlID(), "data-bluritemstyle", listView.currentInactiveStyle())
}
}
return true
}
func (listView *listViewData) Get(tag string) any { func (listView *listViewData) Get(tag string) any {
return listView.get(listView.normalizeTag(tag)) return listView.get(listView.normalizeTag(tag))
} }

View File

@ -28,17 +28,9 @@ func ShowQuestion(title, text string, session Session, onYes func(), onNo func()
CloseButton: false, CloseButton: false,
OutsideClose: false, OutsideClose: false,
Buttons: []PopupButton{ Buttons: []PopupButton{
{
Title: "No",
OnClick: func(popup Popup) {
popup.Dismiss()
if onNo != nil {
onNo()
}
},
},
{ {
Title: "Yes", Title: "Yes",
Type: DefaultButton,
OnClick: func(popup Popup) { OnClick: func(popup Popup) {
popup.Dismiss() popup.Dismiss()
if onYes != nil { if onYes != nil {
@ -46,6 +38,16 @@ func ShowQuestion(title, text string, session Session, onYes func(), onNo func()
} }
}, },
}, },
{
Title: "No",
Type: CancelButton,
OnClick: func(popup Popup) {
popup.Dismiss()
if onNo != nil {
onNo()
}
},
},
}, },
} }
if title != "" { if title != "" {
@ -68,11 +70,12 @@ func ShowCancellableQuestion(title, text string, session Session, onYes func(),
OutsideClose: false, OutsideClose: false,
Buttons: []PopupButton{ Buttons: []PopupButton{
{ {
Title: "Cancel", Title: "Yes",
Type: DefaultButton,
OnClick: func(popup Popup) { OnClick: func(popup Popup) {
popup.Dismiss() popup.Dismiss()
if onCancel != nil { if onYes != nil {
onCancel() onYes()
} }
}, },
}, },
@ -86,11 +89,12 @@ func ShowCancellableQuestion(title, text string, session Session, onYes func(),
}, },
}, },
{ {
Title: "Yes", Title: "Cancel",
Type: CancelButton,
OnClick: func(popup Popup) { OnClick: func(popup Popup) {
popup.Dismiss() popup.Dismiss()
if onYes != nil { if onCancel != nil {
onYes() onCancel()
} }
}, },
}, },

View File

@ -49,6 +49,7 @@ type Theme interface {
ImageConstantTags() []string ImageConstantTags() []string
Style(tag string) ViewStyle Style(tag string) ViewStyle
SetStyle(tag string, style ViewStyle) SetStyle(tag string, style ViewStyle)
RemoveStyle(tag string)
MediaStyle(tag string, orientation, maxWidth, maxHeight int) ViewStyle MediaStyle(tag string, orientation, maxWidth, maxHeight int) ViewStyle
SetMediaStyle(tag string, orientation, maxWidth, maxHeight int, style ViewStyle) SetMediaStyle(tag string, orientation, maxWidth, maxHeight int, style ViewStyle)
StyleTags() []string StyleTags() []string
@ -264,6 +265,25 @@ func (theme *theme) SetStyle(tag string, style ViewStyle) {
} }
} }
func (theme *theme) RemoveStyle(tag string) {
tag2 := tag + ":"
remove := func(styles map[string]ViewStyle) {
tags := []string{tag}
for t := range styles {
if strings.HasPrefix(t, tag2) {
tags = append(tags, t)
}
}
for _, t := range tags {
delete(styles, t)
}
}
remove(theme.styles)
for _, mediaStyle := range theme.mediaStyles {
remove(mediaStyle.styles)
}
}
func (theme *theme) MediaStyle(tag string, orientation, maxWidth, maxHeight int) ViewStyle { func (theme *theme) MediaStyle(tag string, orientation, maxWidth, maxHeight int) ViewStyle {
for _, styles := range theme.mediaStyles { for _, styles := range theme.mediaStyles {
if styles.orientation == orientation && styles.maxWidth == maxWidth && styles.maxHeight == maxHeight { if styles.orientation == orientation && styles.maxWidth == maxWidth && styles.maxHeight == maxHeight {