forked from mbk-lab/rui_orig
Bug fixing
This commit is contained in:
parent
dc2ea14cac
commit
3d44aa3ba3
103
listView.go
103
listView.go
|
@ -129,78 +129,92 @@ func (listView *listViewData) remove(tag string) {
|
|||
case Gap:
|
||||
listView.remove(ListRowGap)
|
||||
listView.remove(ListColumnGap)
|
||||
return
|
||||
|
||||
case Checked:
|
||||
if len(listView.checkedItem) > 0 {
|
||||
if len(listView.checkedItem) == 0 {
|
||||
return
|
||||
}
|
||||
listView.checkedItem = []int{}
|
||||
if listView.created {
|
||||
updateInnerHTML(listView.htmlID(), listView.session)
|
||||
}
|
||||
listView.propertyChangedEvent(tag)
|
||||
}
|
||||
|
||||
case Items:
|
||||
if listView.adapter != nil {
|
||||
if listView.adapter == nil {
|
||||
return
|
||||
}
|
||||
listView.adapter = nil
|
||||
if listView.created {
|
||||
updateInnerHTML(listView.htmlID(), listView.session)
|
||||
}
|
||||
listView.propertyChangedEvent(tag)
|
||||
}
|
||||
|
||||
case Orientation, ListWrap:
|
||||
if _, ok := listView.properties[tag]; ok {
|
||||
if _, ok := listView.properties[tag]; !ok {
|
||||
return
|
||||
}
|
||||
delete(listView.properties, tag)
|
||||
if listView.created {
|
||||
updateCSSStyle(listView.htmlID(), listView.session)
|
||||
}
|
||||
listView.propertyChangedEvent(tag)
|
||||
}
|
||||
|
||||
case Current:
|
||||
current := GetCurrent(listView)
|
||||
if current == -1 {
|
||||
return
|
||||
}
|
||||
delete(listView.properties, tag)
|
||||
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 {
|
||||
for _, listener := range listView.selectedListeners {
|
||||
listener(listView, -1)
|
||||
}
|
||||
listView.propertyChangedEvent(tag)
|
||||
}
|
||||
|
||||
case ItemWidth, ItemHeight, ItemHorizontalAlign, ItemVerticalAlign, ItemCheckbox,
|
||||
CheckboxHorizontalAlign, CheckboxVerticalAlign, ListItemStyle, CurrentStyle, CurrentInactiveStyle:
|
||||
if _, ok := listView.properties[tag]; ok {
|
||||
CheckboxHorizontalAlign, CheckboxVerticalAlign:
|
||||
if _, ok := listView.properties[tag]; !ok {
|
||||
return
|
||||
}
|
||||
delete(listView.properties, tag)
|
||||
if listView.created {
|
||||
updateInnerHTML(listView.htmlID(), listView.session)
|
||||
}
|
||||
listView.propertyChangedEvent(tag)
|
||||
|
||||
case ListItemStyle, CurrentStyle, CurrentInactiveStyle:
|
||||
if !listView.setItemStyle(tag, "") {
|
||||
return
|
||||
}
|
||||
|
||||
case ListItemClickedEvent:
|
||||
if len(listView.clickedListeners) > 0 {
|
||||
listView.clickedListeners = []func(ListView, int){}
|
||||
listView.propertyChangedEvent(tag)
|
||||
if len(listView.clickedListeners) == 0 {
|
||||
return
|
||||
}
|
||||
listView.clickedListeners = []func(ListView, int){}
|
||||
|
||||
case ListItemSelectedEvent:
|
||||
if len(listView.selectedListeners) > 0 {
|
||||
listView.selectedListeners = []func(ListView, int){}
|
||||
listView.propertyChangedEvent(tag)
|
||||
if len(listView.selectedListeners) == 0 {
|
||||
return
|
||||
}
|
||||
listView.selectedListeners = []func(ListView, int){}
|
||||
|
||||
case ListItemCheckedEvent:
|
||||
if len(listView.checkedListeners) > 0 {
|
||||
listView.checkedListeners = []func(ListView, []int){}
|
||||
listView.propertyChangedEvent(tag)
|
||||
if len(listView.checkedListeners) == 0 {
|
||||
return
|
||||
}
|
||||
listView.checkedListeners = []func(ListView, []int){}
|
||||
|
||||
default:
|
||||
listView.viewData.remove(tag)
|
||||
return
|
||||
}
|
||||
|
||||
listView.propertyChangedEvent(tag)
|
||||
}
|
||||
|
||||
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) {
|
||||
return false
|
||||
}
|
||||
|
||||
current := GetCurrent(listView)
|
||||
if oldCurrent == current {
|
||||
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 {
|
||||
listener(listView, current)
|
||||
}
|
||||
|
@ -290,12 +313,7 @@ func (listView *listViewData) set(tag string, value any) bool {
|
|||
}
|
||||
|
||||
case ListItemStyle, CurrentStyle, CurrentInactiveStyle:
|
||||
switch value := value.(type) {
|
||||
case string:
|
||||
listView.properties[tag] = value
|
||||
|
||||
default:
|
||||
notCompatibleType(tag, value)
|
||||
if !listView.setItemStyle(tag, value) {
|
||||
return false
|
||||
}
|
||||
|
||||
|
@ -310,6 +328,33 @@ func (listView *listViewData) set(tag string, value any) bool {
|
|||
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 {
|
||||
return listView.get(listView.normalizeTag(tag))
|
||||
}
|
||||
|
|
|
@ -28,17 +28,9 @@ func ShowQuestion(title, text string, session Session, onYes func(), onNo func()
|
|||
CloseButton: false,
|
||||
OutsideClose: false,
|
||||
Buttons: []PopupButton{
|
||||
{
|
||||
Title: "No",
|
||||
OnClick: func(popup Popup) {
|
||||
popup.Dismiss()
|
||||
if onNo != nil {
|
||||
onNo()
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
Title: "Yes",
|
||||
Type: DefaultButton,
|
||||
OnClick: func(popup Popup) {
|
||||
popup.Dismiss()
|
||||
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 != "" {
|
||||
|
@ -68,11 +70,12 @@ func ShowCancellableQuestion(title, text string, session Session, onYes func(),
|
|||
OutsideClose: false,
|
||||
Buttons: []PopupButton{
|
||||
{
|
||||
Title: "Cancel",
|
||||
Title: "Yes",
|
||||
Type: DefaultButton,
|
||||
OnClick: func(popup Popup) {
|
||||
popup.Dismiss()
|
||||
if onCancel != nil {
|
||||
onCancel()
|
||||
if onYes != nil {
|
||||
onYes()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
@ -86,11 +89,12 @@ func ShowCancellableQuestion(title, text string, session Session, onYes func(),
|
|||
},
|
||||
},
|
||||
{
|
||||
Title: "Yes",
|
||||
Title: "Cancel",
|
||||
Type: CancelButton,
|
||||
OnClick: func(popup Popup) {
|
||||
popup.Dismiss()
|
||||
if onYes != nil {
|
||||
onYes()
|
||||
if onCancel != nil {
|
||||
onCancel()
|
||||
}
|
||||
},
|
||||
},
|
||||
|
|
20
theme.go
20
theme.go
|
@ -49,6 +49,7 @@ type Theme interface {
|
|||
ImageConstantTags() []string
|
||||
Style(tag string) ViewStyle
|
||||
SetStyle(tag string, style ViewStyle)
|
||||
RemoveStyle(tag string)
|
||||
MediaStyle(tag string, orientation, maxWidth, maxHeight int) ViewStyle
|
||||
SetMediaStyle(tag string, orientation, maxWidth, maxHeight int, style ViewStyle)
|
||||
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 {
|
||||
for _, styles := range theme.mediaStyles {
|
||||
if styles.orientation == orientation && styles.maxWidth == maxWidth && styles.maxHeight == maxHeight {
|
||||
|
|
Loading…
Reference in New Issue