Bug fixing

This commit is contained in:
anoshenko 2024-04-23 18:24:51 +03:00
parent 9e4fdccd79
commit b1f085b891
9 changed files with 50 additions and 70 deletions

View File

@ -34,6 +34,7 @@ func newColorPicker(session Session) View {
func (picker *colorPickerData) init(session Session) { func (picker *colorPickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "ColorPicker" picker.tag = "ColorPicker"
picker.hasHtmlDisabled = true
picker.colorChangedListeners = []func(ColorPicker, Color, Color){} picker.colorChangedListeners = []func(ColorPicker, Color, Color){}
picker.properties[Padding] = Px(0) picker.properties[Padding] = Px(0)
} }
@ -153,13 +154,6 @@ func (picker *colorPickerData) htmlProperties(self View, buffer *strings.Builder
} }
} }
func (picker *colorPickerData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` disabled`)
}
picker.viewData.htmlDisabledProperties(self, buffer)
}
func (picker *colorPickerData) handleCommand(self View, command string, data DataObject) bool { func (picker *colorPickerData) handleCommand(self View, command string, data DataObject) bool {
switch command { switch command {
case "textChanged": case "textChanged":

View File

@ -188,10 +188,6 @@ func (customView *CustomViewData) htmlProperties(self View, buffer *strings.Buil
customView.superView.htmlProperties(customView.superView, buffer) customView.superView.htmlProperties(customView.superView, buffer)
} }
func (customView *CustomViewData) htmlDisabledProperties(self View, buffer *strings.Builder) {
customView.superView.htmlDisabledProperties(customView.superView, buffer)
}
func (customView *CustomViewData) cssStyle(self View, builder cssBuilder) { func (customView *CustomViewData) cssStyle(self View, builder cssBuilder) {
customView.superView.cssStyle(customView.superView, builder) customView.superView.cssStyle(customView.superView, builder)
} }

View File

@ -40,6 +40,7 @@ func newDatePicker(session Session) View {
func (picker *datePickerData) init(session Session) { func (picker *datePickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "DatePicker" picker.tag = "DatePicker"
picker.hasHtmlDisabled = true
picker.dateChangedListeners = []func(DatePicker, time.Time, time.Time){} picker.dateChangedListeners = []func(DatePicker, time.Time, time.Time){}
} }
@ -303,13 +304,6 @@ func (picker *datePickerData) htmlProperties(self View, buffer *strings.Builder)
} }
} }
func (picker *datePickerData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` disabled`)
}
picker.viewData.htmlDisabledProperties(self, buffer)
}
func (picker *datePickerData) handleCommand(self View, command string, data DataObject) bool { func (picker *datePickerData) handleCommand(self View, command string, data DataObject) bool {
switch command { switch command {
case "textChanged": case "textChanged":

View File

@ -39,6 +39,7 @@ func newDropDownList(session Session) View {
func (list *dropDownListData) init(session Session) { func (list *dropDownListData) init(session Session) {
list.viewData.init(session) list.viewData.init(session)
list.tag = "DropDownList" list.tag = "DropDownList"
list.hasHtmlDisabled = true
list.items = []string{} list.items = []string{}
list.disabledItems = []any{} list.disabledItems = []any{}
list.dropDownListener = []func(DropDownList, int, int){} list.dropDownListener = []func(DropDownList, int, int){}
@ -370,13 +371,6 @@ func (list *dropDownListData) htmlProperties(self View, buffer *strings.Builder)
buffer.WriteString(` size="1" onchange="dropDownListEvent(this, event)"`) buffer.WriteString(` size="1" onchange="dropDownListEvent(this, event)"`)
} }
func (list *dropDownListData) htmlDisabledProperties(self View, buffer *strings.Builder) {
list.viewData.htmlDisabledProperties(self, buffer)
if IsDisabled(list) {
buffer.WriteString(`disabled`)
}
}
func (list *dropDownListData) onSelectedItemChanged(number, old int) { func (list *dropDownListData) onSelectedItemChanged(number, old int) {
for _, listener := range list.dropDownListener { for _, listener := range list.dropDownListener {
listener(list, number, old) listener(list, number, old)

View File

@ -58,6 +58,7 @@ func newEditView(session Session) View {
func (edit *editViewData) init(session Session) { func (edit *editViewData) init(session Session) {
edit.viewData.init(session) edit.viewData.init(session)
edit.hasHtmlDisabled = true
edit.textChangeListeners = []func(EditView, string, string){} edit.textChangeListeners = []func(EditView, string, string){}
edit.tag = "EditView" edit.tag = "EditView"
} }
@ -466,13 +467,6 @@ func (edit *editViewData) htmlProperties(self View, buffer *strings.Builder) {
} }
} }
func (edit *editViewData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` disabled`)
}
edit.viewData.htmlDisabledProperties(self, buffer)
}
func (edit *editViewData) htmlSubviews(self View, buffer *strings.Builder) { func (edit *editViewData) htmlSubviews(self View, buffer *strings.Builder) {
if GetEditViewType(edit) == MultiLineText { if GetEditViewType(edit) == MultiLineText {
buffer.WriteString(GetText(edit)) buffer.WriteString(GetText(edit))

View File

@ -83,6 +83,7 @@ func newFilePicker(session Session) View {
func (picker *filePickerData) init(session Session) { func (picker *filePickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "FilePicker" picker.tag = "FilePicker"
picker.hasHtmlDisabled = true
picker.files = []FileInfo{} picker.files = []FileInfo{}
picker.loader = map[int]func(FileInfo, []byte){} picker.loader = map[int]func(FileInfo, []byte){}
picker.fileSelectedListeners = []func(FilePicker, []FileInfo){} picker.fileSelectedListeners = []func(FilePicker, []FileInfo){}
@ -260,13 +261,6 @@ func (picker *filePickerData) htmlProperties(self View, buffer *strings.Builder)
} }
} }
func (picker *filePickerData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` disabled`)
}
picker.viewData.htmlDisabledProperties(self, buffer)
}
func (picker *filePickerData) handleCommand(self View, command string, data DataObject) bool { func (picker *filePickerData) handleCommand(self View, command string, data DataObject) bool {
switch command { switch command {
case "fileSelected": case "fileSelected":

View File

@ -47,6 +47,7 @@ func newNumberPicker(session Session) View {
func (picker *numberPickerData) init(session Session) { func (picker *numberPickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "NumberPicker" picker.tag = "NumberPicker"
picker.hasHtmlDisabled = true
picker.numberChangedListeners = []func(NumberPicker, float64, float64){} picker.numberChangedListeners = []func(NumberPicker, float64, float64){}
} }
@ -232,13 +233,6 @@ func (picker *numberPickerData) htmlProperties(self View, buffer *strings.Builde
buffer.WriteString(` oninput="editViewInputEvent(this)"`) buffer.WriteString(` oninput="editViewInputEvent(this)"`)
} }
func (picker *numberPickerData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` disabled`)
}
picker.viewData.htmlDisabledProperties(self, buffer)
}
func (picker *numberPickerData) handleCommand(self View, command string, data DataObject) bool { func (picker *numberPickerData) handleCommand(self View, command string, data DataObject) bool {
switch command { switch command {
case "textChanged": case "textChanged":

View File

@ -40,6 +40,7 @@ func newTimePicker(session Session) View {
func (picker *timePickerData) init(session Session) { func (picker *timePickerData) init(session Session) {
picker.viewData.init(session) picker.viewData.init(session)
picker.tag = "TimePicker" picker.tag = "TimePicker"
picker.hasHtmlDisabled = true
picker.timeChangedListeners = []func(TimePicker, time.Time, time.Time){} picker.timeChangedListeners = []func(TimePicker, time.Time, time.Time){}
} }
@ -291,13 +292,6 @@ func (picker *timePickerData) htmlProperties(self View, buffer *strings.Builder)
} }
} }
func (picker *timePickerData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` disabled`)
}
picker.viewData.htmlDisabledProperties(self, buffer)
}
func (picker *timePickerData) handleCommand(self View, command string, data DataObject) bool { func (picker *timePickerData) handleCommand(self View, command string, data DataObject) bool {
switch command { switch command {
case "textChanged": case "textChanged":

60
view.go
View File

@ -65,7 +65,6 @@ type View interface {
setParentID(parentID string) setParentID(parentID string)
htmlSubviews(self View, buffer *strings.Builder) htmlSubviews(self View, buffer *strings.Builder)
htmlProperties(self View, buffer *strings.Builder) htmlProperties(self View, buffer *strings.Builder)
htmlDisabledProperties(self View, buffer *strings.Builder)
cssStyle(self View, builder cssBuilder) cssStyle(self View, builder cssBuilder)
addToCSSStyle(addCSS map[string]string) addToCSSStyle(addCSS map[string]string)
@ -93,6 +92,7 @@ type viewData struct {
noResizeEvent bool noResizeEvent bool
created bool created bool
hasFocus bool hasFocus bool
hasHtmlDisabled bool
//animation map[string]AnimationEndListener //animation map[string]AnimationEndListener
} }
@ -135,6 +135,7 @@ func (view *viewData) init(session Session) {
view.singleTransition = map[string]Animation{} view.singleTransition = map[string]Animation{}
view.noResizeEvent = false view.noResizeEvent = false
view.created = false view.created = false
view.hasHtmlDisabled = false
} }
func (view *viewData) Session() Session { func (view *viewData) Session() Session {
@ -302,7 +303,6 @@ func (view *viewData) propertyChangedEvent(tag string) {
if listener, ok := view.changeListener[tag]; ok { if listener, ok := view.changeListener[tag]; ok {
listener(view, tag) listener(view, tag)
} }
} }
func (view *viewData) Set(tag string, value any) bool { func (view *viewData) Set(tag string, value any) bool {
@ -404,7 +404,35 @@ func viewPropertyChanged(view *viewData, tag string) {
switch tag { switch tag {
case Disabled: case Disabled:
updateInnerHTML(view.parentHTMLID(), session) tabIndex := GetTabIndex(view, htmlID)
enabledClass := view.htmlClass(false)
disabledClass := view.htmlClass(true)
session.startUpdateScript(htmlID)
if IsDisabled(view) {
session.updateProperty(htmlID, "data-disabled", "1")
if view.hasHtmlDisabled {
session.updateProperty(htmlID, "disabled", true)
}
if tabIndex >= 0 {
session.updateProperty(htmlID, "tabindex", -1)
}
if enabledClass != disabledClass {
session.updateProperty(htmlID, "class", disabledClass)
}
} else {
session.updateProperty(htmlID, "data-disabled", "0")
if view.hasHtmlDisabled {
session.removeProperty(htmlID, "disabled")
}
if tabIndex >= 0 {
session.updateProperty(htmlID, "tabindex", tabIndex)
}
if enabledClass != disabledClass {
session.updateProperty(htmlID, "class", enabledClass)
}
}
session.finishUpdateScript(htmlID)
updateInnerHTML(htmlID, session)
return return
case Visibility: case Visibility:
@ -759,20 +787,22 @@ func (view *viewData) cssStyle(self View, builder cssBuilder) {
func (view *viewData) htmlProperties(self View, buffer *strings.Builder) { func (view *viewData) htmlProperties(self View, buffer *strings.Builder) {
view.created = true view.created = true
if IsDisabled(self) {
buffer.WriteString(` data-disabled="1"`)
if view.hasHtmlDisabled {
buffer.WriteString(` disabled`)
}
} else {
buffer.WriteString(` data-disabled="0"`)
}
if view.frame.Left != 0 || view.frame.Top != 0 || view.frame.Width != 0 || view.frame.Height != 0 { if view.frame.Left != 0 || view.frame.Top != 0 || view.frame.Width != 0 || view.frame.Height != 0 {
buffer.WriteString(fmt.Sprintf(` data-left="%g" data-top="%g" data-width="%g" data-height="%g"`, buffer.WriteString(fmt.Sprintf(` data-left="%g" data-top="%g" data-width="%g" data-height="%g"`,
view.frame.Left, view.frame.Top, view.frame.Width, view.frame.Height)) view.frame.Left, view.frame.Top, view.frame.Width, view.frame.Height))
} }
} }
func (view *viewData) htmlDisabledProperties(self View, buffer *strings.Builder) {
if IsDisabled(self) {
buffer.WriteString(` data-disabled="1"`)
} else {
buffer.WriteString(` data-disabled="0"`)
}
}
func viewHTML(view View, buffer *strings.Builder) { func viewHTML(view View, buffer *strings.Builder) {
viewHTMLTag := view.htmlTag() viewHTMLTag := view.htmlTag()
buffer.WriteRune('<') buffer.WriteRune('<')
@ -800,8 +830,6 @@ func viewHTML(view View, buffer *strings.Builder) {
buffer.WriteRune(' ') buffer.WriteRune(' ')
view.htmlProperties(view, buffer) view.htmlProperties(view, buffer)
buffer.WriteRune(' ')
view.htmlDisabledProperties(view, buffer)
if view.isNoResizeEvent() { if view.isNoResizeEvent() {
buffer.WriteString(` data-noresize="1" `) buffer.WriteString(` data-noresize="1" `)
@ -810,12 +838,10 @@ func viewHTML(view View, buffer *strings.Builder) {
} }
if !disabled { if !disabled {
if value, ok := intProperty(view, TabIndex, view.Session(), -1); ok { if tabIndex := GetTabIndex(view); tabIndex >= 0 {
buffer.WriteString(`tabindex="`) buffer.WriteString(`tabindex="`)
buffer.WriteString(strconv.Itoa(value)) buffer.WriteString(strconv.Itoa(tabIndex))
buffer.WriteString(`" `) buffer.WriteString(`" `)
} else if view.Focusable() {
buffer.WriteString(`tabindex="0" `)
} }
} }