forked from mbk-lab/rui_orig
2
0
Fork 0

Optimisation

This commit is contained in:
anoshenko 2022-10-30 17:22:33 +03:00
parent 76413c931a
commit f8d797a4c1
32 changed files with 344 additions and 250 deletions

View File

@ -624,8 +624,8 @@ func (view *viewData) SetAnimated(tag string, value any, animation Animation) bo
htmlID := view.htmlID() htmlID := view.htmlID()
session.startUpdateScript(htmlID) session.startUpdateScript(htmlID)
updateProperty(htmlID, "ontransitionend", "transitionEndEvent(this, event)", view.session) session.updateProperty(htmlID, "ontransitionend", "transitionEndEvent(this, event)")
updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)", view.session) session.updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)")
if prevAnimation, ok := view.transitions[tag]; ok { if prevAnimation, ok := view.transitions[tag]; ok {
view.singleTransition[tag] = prevAnimation view.singleTransition[tag] = prevAnimation
@ -701,7 +701,7 @@ func (style *viewStyle) transitionCSS(session Session) string {
} }
func (view *viewData) updateTransitionCSS() { func (view *viewData) updateTransitionCSS() {
updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.Session()), view.Session()) view.session.updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.session))
} }
func (style *viewStyle) Transition(tag string) Animation { func (style *viewStyle) Transition(tag string) Animation {
@ -732,7 +732,7 @@ func (style *viewStyle) SetTransition(tag string, animation Animation) {
func (view *viewData) SetTransition(tag string, animation Animation) { func (view *viewData) SetTransition(tag string, animation Animation) {
view.viewStyle.SetTransition(tag, animation) view.viewStyle.SetTransition(tag, animation)
if view.created { if view.created {
updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.Session()), view.Session()) view.session.updateCSSProperty(view.htmlID(), "transition", view.transitionCSS(view.session))
} }
} }

View File

@ -70,7 +70,7 @@ func (view *viewData) setTransitionListener(tag string, value any) bool {
} else if js, ok := transitionEvents[tag]; ok { } else if js, ok := transitionEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -82,7 +82,7 @@ func (view *viewData) removeTransitionListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := transitionEvents[tag]; ok { if js, ok := transitionEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }
@ -136,7 +136,7 @@ func (view *viewData) setAnimationListener(tag string, value any) bool {
} else if js, ok := animationEvents[tag]; ok { } else if js, ok := animationEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -148,7 +148,7 @@ func (view *viewData) removeAnimationListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := animationEvents[tag]; ok { if js, ok := animationEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }

View File

@ -98,7 +98,7 @@ func (button *checkboxData) set(tag string, value any) bool {
return false return false
} }
if button.created { if button.created {
updateCSSProperty(button.htmlID()+"content", "align-items", button.cssVerticalAlign(), button.session) button.session.updateCSSProperty(button.htmlID()+"content", "align-items", button.cssVerticalAlign())
} }
case HorizontalAlign: case HorizontalAlign:
@ -106,7 +106,7 @@ func (button *checkboxData) set(tag string, value any) bool {
return false return false
} }
if button.created { if button.created {
updateCSSProperty(button.htmlID()+"content", "justify-items", button.cssHorizontalAlign(), button.session) button.session.updateCSSProperty(button.htmlID()+"content", "justify-items", button.cssHorizontalAlign())
} }
case CellVerticalAlign, CellHorizontalAlign, CellWidth, CellHeight: case CellVerticalAlign, CellHorizontalAlign, CellWidth, CellHeight:
@ -159,13 +159,13 @@ func (button *checkboxData) remove(tag string) {
case VerticalAlign: case VerticalAlign:
delete(button.properties, tag) delete(button.properties, tag)
if button.created { if button.created {
updateCSSProperty(button.htmlID()+"content", "align-items", button.cssVerticalAlign(), button.session) button.session.updateCSSProperty(button.htmlID()+"content", "align-items", button.cssVerticalAlign())
} }
case HorizontalAlign: case HorizontalAlign:
delete(button.properties, tag) delete(button.properties, tag)
if button.created { if button.created {
updateCSSProperty(button.htmlID()+"content", "justify-items", button.cssHorizontalAlign(), button.session) button.session.updateCSSProperty(button.htmlID()+"content", "justify-items", button.cssHorizontalAlign())
} }
default: default:
@ -189,7 +189,7 @@ func (button *checkboxData) changedCheckboxState(state bool) {
defer freeStringBuilder(buffer) defer freeStringBuilder(buffer)
button.htmlCheckbox(buffer, state) button.htmlCheckbox(buffer, state)
button.Session().runFunc("updateInnerHTML", button.htmlID()+"checkbox", buffer.String()) button.Session().updateInnerHTML(button.htmlID()+"checkbox", buffer.String())
} }
func checkboxClickListener(view View) { func checkboxClickListener(view View) {

View File

@ -89,10 +89,10 @@ func (columnLayout *columnLayoutData) remove(tag string) {
if columnLayout.created { if columnLayout.created {
switch tag { switch tag {
case ColumnCount, ColumnWidth, ColumnGap: case ColumnCount, ColumnWidth, ColumnGap:
updateCSSProperty(columnLayout.htmlID(), tag, "", columnLayout.Session()) columnLayout.session.updateCSSProperty(columnLayout.htmlID(), tag, "")
case ColumnSeparator: case ColumnSeparator:
updateCSSProperty(columnLayout.htmlID(), "column-rule", "", columnLayout.Session()) columnLayout.session.updateCSSProperty(columnLayout.htmlID(), "column-rule", "")
} }
} }
} }
@ -120,14 +120,14 @@ func (columnLayout *columnLayoutData) set(tag string, value any) bool {
separator := val.(ColumnSeparatorProperty) separator := val.(ColumnSeparatorProperty)
css = separator.cssValue(columnLayout.Session()) css = separator.cssValue(columnLayout.Session())
} }
updateCSSProperty(columnLayout.htmlID(), "column-rule", css, session) session.updateCSSProperty(columnLayout.htmlID(), "column-rule", css)
case ColumnCount: case ColumnCount:
session := columnLayout.Session() session := columnLayout.Session()
if count, ok := intProperty(columnLayout, tag, session, 0); ok && count > 0 { if count, ok := intProperty(columnLayout, tag, session, 0); ok && count > 0 {
updateCSSProperty(columnLayout.htmlID(), tag, strconv.Itoa(count), session) session.updateCSSProperty(columnLayout.htmlID(), tag, strconv.Itoa(count))
} else { } else {
updateCSSProperty(columnLayout.htmlID(), tag, "auto", session) session.updateCSSProperty(columnLayout.htmlID(), tag, "auto")
} }
} }
} }

View File

@ -77,19 +77,19 @@ func (picker *datePickerData) remove(tag string) {
case DatePickerMin: case DatePickerMin:
delete(picker.properties, DatePickerMin) delete(picker.properties, DatePickerMin)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), Min, picker.session) picker.session.removeProperty(picker.htmlID(), Min)
} }
case DatePickerMax: case DatePickerMax:
delete(picker.properties, DatePickerMax) delete(picker.properties, DatePickerMax)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), Max, picker.session) picker.session.removeProperty(picker.htmlID(), Max)
} }
case DatePickerStep: case DatePickerStep:
delete(picker.properties, DatePickerStep) delete(picker.properties, DatePickerStep)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), Step, picker.session) picker.session.removeProperty(picker.htmlID(), Step)
} }
case DatePickerValue: case DatePickerValue:
@ -183,7 +183,7 @@ func (picker *datePickerData) set(tag string, value any) bool {
if date, ok := setTimeValue(DatePickerMin); ok { if date, ok := setTimeValue(DatePickerMin); ok {
if !oldOK || date != old { if !oldOK || date != old {
if picker.created { if picker.created {
updateProperty(picker.htmlID(), Min, date.Format(dateFormat), picker.session) picker.session.updateProperty(picker.htmlID(), Min, date.Format(dateFormat))
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
@ -195,7 +195,7 @@ func (picker *datePickerData) set(tag string, value any) bool {
if date, ok := setTimeValue(DatePickerMax); ok { if date, ok := setTimeValue(DatePickerMax); ok {
if !oldOK || date != old { if !oldOK || date != old {
if picker.created { if picker.created {
updateProperty(picker.htmlID(), Max, date.Format(dateFormat), picker.session) picker.session.updateProperty(picker.htmlID(), Max, date.Format(dateFormat))
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
@ -208,9 +208,9 @@ func (picker *datePickerData) set(tag string, value any) bool {
if step := GetDatePickerStep(picker); oldStep != step { if step := GetDatePickerStep(picker); oldStep != step {
if picker.created { if picker.created {
if step > 0 { if step > 0 {
updateProperty(picker.htmlID(), Step, strconv.Itoa(step), picker.session) picker.session.updateProperty(picker.htmlID(), Step, strconv.Itoa(step))
} else { } else {
removeProperty(picker.htmlID(), Step, picker.session) picker.session.removeProperty(picker.htmlID(), Step)
} }
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)

View File

@ -63,7 +63,7 @@ func (detailsView *detailsViewData) remove(tag string) {
updateInnerHTML(detailsView.htmlID(), detailsView.Session()) updateInnerHTML(detailsView.htmlID(), detailsView.Session())
case Expanded: case Expanded:
removeProperty(detailsView.htmlID(), "open", detailsView.Session()) detailsView.session.removeProperty(detailsView.htmlID(), "open")
} }
} }
} }
@ -111,9 +111,9 @@ func (detailsView *detailsViewData) set(tag string, value any) bool {
} }
if detailsView.created { if detailsView.created {
if IsDetailsExpanded(detailsView) { if IsDetailsExpanded(detailsView) {
updateProperty(detailsView.htmlID(), "open", "", detailsView.Session()) detailsView.session.updateProperty(detailsView.htmlID(), "open", "")
} else { } else {
removeProperty(detailsView.htmlID(), "open", detailsView.Session()) detailsView.session.removeProperty(detailsView.htmlID(), "open")
} }
} }

View File

@ -100,7 +100,7 @@ func (edit *editViewData) remove(tag string) {
if exists { if exists {
delete(edit.properties, Hint) delete(edit.properties, Hint)
if edit.created { if edit.created {
removeProperty(edit.htmlID(), "placeholder", edit.session) edit.session.removeProperty(edit.htmlID(), "placeholder")
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
} }
@ -109,7 +109,7 @@ func (edit *editViewData) remove(tag string) {
if exists { if exists {
delete(edit.properties, MaxLength) delete(edit.properties, MaxLength)
if edit.created { if edit.created {
removeProperty(edit.htmlID(), "maxlength", edit.session) edit.session.removeProperty(edit.htmlID(), "maxlength")
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
} }
@ -118,7 +118,7 @@ func (edit *editViewData) remove(tag string) {
if exists { if exists {
delete(edit.properties, tag) delete(edit.properties, tag)
if edit.created { if edit.created {
updateBoolProperty(edit.htmlID(), tag, false, edit.session) edit.session.updateBoolProperty(edit.htmlID(), tag, false)
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
} }
@ -147,7 +147,7 @@ func (edit *editViewData) remove(tag string) {
delete(edit.properties, tag) delete(edit.properties, tag)
if oldText != "" { if oldText != "" {
if edit.created { if edit.created {
removeProperty(edit.htmlID(), Pattern, edit.session) edit.session.removeProperty(edit.htmlID(), Pattern)
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
} }
@ -173,9 +173,9 @@ func (edit *editViewData) remove(tag string) {
if wrap := IsEditViewWrap(edit); wrap != oldWrap { if wrap := IsEditViewWrap(edit); wrap != oldWrap {
if edit.created { if edit.created {
if wrap { if wrap {
updateProperty(edit.htmlID(), "wrap", "soft", edit.session) edit.session.updateProperty(edit.htmlID(), "wrap", "soft")
} else { } else {
updateProperty(edit.htmlID(), "wrap", "off", edit.session) edit.session.updateProperty(edit.htmlID(), "wrap", "off")
} }
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
@ -225,9 +225,9 @@ func (edit *editViewData) set(tag string, value any) bool {
if text = GetHint(edit); oldText != text { if text = GetHint(edit); oldText != text {
if edit.created { if edit.created {
if text != "" { if text != "" {
updateProperty(edit.htmlID(), "placeholder", text, edit.session) edit.session.updateProperty(edit.htmlID(), "placeholder", text)
} else { } else {
removeProperty(edit.htmlID(), "placeholder", edit.session) edit.session.removeProperty(edit.htmlID(), "placeholder")
} }
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
@ -242,9 +242,9 @@ func (edit *editViewData) set(tag string, value any) bool {
if maxLength := GetMaxLength(edit); maxLength != oldMaxLength { if maxLength := GetMaxLength(edit); maxLength != oldMaxLength {
if edit.created { if edit.created {
if maxLength > 0 { if maxLength > 0 {
updateProperty(edit.htmlID(), "maxlength", strconv.Itoa(maxLength), edit.session) edit.session.updateProperty(edit.htmlID(), "maxlength", strconv.Itoa(maxLength))
} else { } else {
removeProperty(edit.htmlID(), "maxlength", edit.session) edit.session.removeProperty(edit.htmlID(), "maxlength")
} }
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
@ -257,9 +257,9 @@ func (edit *editViewData) set(tag string, value any) bool {
if edit.setBoolProperty(ReadOnly, value) { if edit.setBoolProperty(ReadOnly, value) {
if edit.created { if edit.created {
if IsReadOnly(edit) { if IsReadOnly(edit) {
updateProperty(edit.htmlID(), ReadOnly, "", edit.session) edit.session.updateProperty(edit.htmlID(), ReadOnly, "")
} else { } else {
removeProperty(edit.htmlID(), ReadOnly, edit.session) edit.session.removeProperty(edit.htmlID(), ReadOnly)
} }
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
@ -270,7 +270,7 @@ func (edit *editViewData) set(tag string, value any) bool {
case Spellcheck: case Spellcheck:
if edit.setBoolProperty(Spellcheck, value) { if edit.setBoolProperty(Spellcheck, value) {
if edit.created { if edit.created {
updateBoolProperty(edit.htmlID(), Spellcheck, IsSpellcheck(edit), edit.session) edit.session.updateBoolProperty(edit.htmlID(), Spellcheck, IsSpellcheck(edit))
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
return true return true
@ -284,9 +284,9 @@ func (edit *editViewData) set(tag string, value any) bool {
if text = GetEditViewPattern(edit); oldText != text { if text = GetEditViewPattern(edit); oldText != text {
if edit.created { if edit.created {
if text != "" { if text != "" {
updateProperty(edit.htmlID(), Pattern, text, edit.session) edit.session.updateProperty(edit.htmlID(), Pattern, text)
} else { } else {
removeProperty(edit.htmlID(), Pattern, edit.session) edit.session.removeProperty(edit.htmlID(), Pattern)
} }
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)
@ -315,9 +315,9 @@ func (edit *editViewData) set(tag string, value any) bool {
if wrap := IsEditViewWrap(edit); wrap != oldWrap { if wrap := IsEditViewWrap(edit); wrap != oldWrap {
if edit.created { if edit.created {
if wrap { if wrap {
updateProperty(edit.htmlID(), "wrap", "soft", edit.session) edit.session.updateProperty(edit.htmlID(), "wrap", "soft")
} else { } else {
updateProperty(edit.htmlID(), "wrap", "off", edit.session) edit.session.updateProperty(edit.htmlID(), "wrap", "off")
} }
} }
edit.propertyChangedEvent(tag) edit.propertyChangedEvent(tag)

View File

@ -129,7 +129,7 @@ func (picker *filePickerData) remove(tag string) {
case Accept: case Accept:
delete(picker.properties, tag) delete(picker.properties, tag)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), "accept", picker.Session()) picker.session.removeProperty(picker.htmlID(), "accept")
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
@ -196,9 +196,9 @@ func (picker *filePickerData) set(tag string, value any) bool {
if picker.created { if picker.created {
if css := picker.acceptCSS(); css != "" { if css := picker.acceptCSS(); css != "" {
updateProperty(picker.htmlID(), "accept", css, picker.Session()) picker.session.updateProperty(picker.htmlID(), "accept", css)
} else { } else {
removeProperty(picker.htmlID(), "accept", picker.Session()) picker.session.removeProperty(picker.htmlID(), "accept")
} }
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)

View File

@ -108,7 +108,7 @@ func (view *viewData) setFocusListener(tag string, value any) bool {
} else if js, ok := focusEvents[tag]; ok { } else if js, ok := focusEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -120,7 +120,7 @@ func (view *viewData) removeFocusListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := focusEvents[tag]; ok { if js, ok := focusEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }

View File

@ -230,12 +230,12 @@ func (gridLayout *gridLayoutData) remove(tag string) {
if gridLayout.created { if gridLayout.created {
switch tag { switch tag {
case CellWidth: case CellWidth:
updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`, gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`,
gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session), gridLayout.session) gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session))
case CellHeight: case CellHeight:
updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`, gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`,
gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session), gridLayout.session) gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session))
} }
} }
@ -259,12 +259,12 @@ func (gridLayout *gridLayoutData) set(tag string, value any) bool {
if gridLayout.created { if gridLayout.created {
switch tag { switch tag {
case CellWidth: case CellWidth:
updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`, gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`,
gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session), gridLayout.session) gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session))
case CellHeight: case CellHeight:
updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`, gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`,
gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session), gridLayout.session) gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session))
} }
} }

View File

@ -102,8 +102,8 @@ func (imageView *imageViewData) remove(tag string) {
if imageView.created { if imageView.created {
switch tag { switch tag {
case Source: case Source:
updateProperty(imageView.htmlID(), "src", "", imageView.session) imageView.session.updateProperty(imageView.htmlID(), "src", "")
removeProperty(imageView.htmlID(), "srcset", imageView.session) imageView.session.removeProperty(imageView.htmlID(), "srcset")
case AltText: case AltText:
updateInnerHTML(imageView.htmlID(), imageView.session) updateInnerHTML(imageView.htmlID(), imageView.session)
@ -133,11 +133,11 @@ func (imageView *imageViewData) set(tag string, value any) bool {
if src != "" && src[0] == '@' { if src != "" && src[0] == '@' {
src, _ = imageProperty(imageView, Source, imageView.session) src, _ = imageProperty(imageView, Source, imageView.session)
} }
updateProperty(imageView.htmlID(), "src", src, imageView.session) imageView.session.updateProperty(imageView.htmlID(), "src", src)
if srcset := imageView.srcSet(src); srcset != "" { if srcset := imageView.srcSet(src); srcset != "" {
updateProperty(imageView.htmlID(), "srcset", srcset, imageView.session) imageView.session.updateProperty(imageView.htmlID(), "srcset", srcset)
} else { } else {
removeProperty(imageView.htmlID(), "srcset", imageView.session) imageView.session.removeProperty(imageView.htmlID(), "srcset")
} }
} }
imageView.propertyChangedEvent(Source) imageView.propertyChangedEvent(Source)

View File

@ -210,7 +210,7 @@ func (view *viewData) setKeyListener(tag string, value any) bool {
} else if js, ok := keyEvents[tag]; ok { } else if js, ok := keyEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -222,7 +222,7 @@ func (view *viewData) removeKeyListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := keyEvents[tag]; ok { if js, ok := keyEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }

View File

@ -837,7 +837,7 @@ func (listView *listViewData) updateCheckboxItem(index int, checked bool) {
} }
} }
buffer.WriteString(`</div></div>`) buffer.WriteString(`</div></div>`)
session.runFunc("updateInnerHTML", listView.htmlID()+"-"+strconv.Itoa(index), buffer.String()) session.updateInnerHTML(listView.htmlID()+"-"+strconv.Itoa(index), buffer.String())
} }
func (listView *listViewData) htmlProperties(self View, buffer *strings.Builder) { func (listView *listViewData) htmlProperties(self View, buffer *strings.Builder) {

View File

@ -463,21 +463,21 @@ func (player *mediaPlayerData) propertyChanged(tag string) {
if player.created { if player.created {
switch tag { switch tag {
case Controls, Loop: case Controls, Loop:
value, _ := boolProperty(player, tag, player.Session()) value, _ := boolProperty(player, tag, player.session)
if value { if value {
updateBoolProperty(player.htmlID(), tag, value, player.Session()) player.session.updateBoolProperty(player.htmlID(), tag, value)
} else { } else {
removeProperty(player.htmlID(), tag, player.Session()) player.session.removeProperty(player.htmlID(), tag)
} }
case Muted: case Muted:
value, _ := boolProperty(player, tag, player.Session()) value, _ := boolProperty(player, tag, player.session)
player.Session().runFunc("setMediaMuted", player.htmlID(), value) player.session.runFunc("setMediaMuted", player.htmlID(), value)
case Preload: case Preload:
value, _ := enumProperty(player, tag, player.Session(), 0) value, _ := enumProperty(player, tag, player.session, 0)
values := enumProperties[Preload].values values := enumProperties[Preload].values
updateProperty(player.htmlID(), tag, values[value], player.Session()) player.session.updateProperty(player.htmlID(), tag, values[value])
case AbortEvent, CanPlayEvent, CanPlayThroughEvent, CompleteEvent, EmptiedEvent, case AbortEvent, CanPlayEvent, CanPlayThroughEvent, CompleteEvent, EmptiedEvent,
EndedEvent, LoadedDataEvent, LoadedMetadataEvent, PauseEvent, PlayEvent, PlayingEvent, ProgressEvent, EndedEvent, LoadedDataEvent, LoadedMetadataEvent, PauseEvent, PlayEvent, PlayingEvent, ProgressEvent,
@ -490,53 +490,53 @@ func (player *mediaPlayerData) propertyChanged(tag string) {
case []func(MediaPlayer): case []func(MediaPlayer):
if len(value) > 0 { if len(value) > 0 {
fn := fmt.Sprintf(`playerEvent(this, "%s")`, event.tag) fn := fmt.Sprintf(`playerEvent(this, "%s")`, event.tag)
updateProperty(player.htmlID(), event.cssTag, fn, player.Session()) player.session.updateProperty(player.htmlID(), event.cssTag, fn)
return return
} }
} }
} }
updateProperty(player.htmlID(), tag, "", player.Session()) player.session.updateProperty(player.htmlID(), tag, "")
break break
} }
} }
case TimeUpdateEvent: case TimeUpdateEvent:
if value := player.getRaw(tag); value != nil { if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "ontimeupdate", "playerTimeUpdatedEvent(this)", player.Session()) player.session.updateProperty(player.htmlID(), "ontimeupdate", "playerTimeUpdatedEvent(this)")
} else { } else {
updateProperty(player.htmlID(), "ontimeupdate", "", player.Session()) player.session.updateProperty(player.htmlID(), "ontimeupdate", "")
} }
case VolumeChangedEvent: case VolumeChangedEvent:
if value := player.getRaw(tag); value != nil { if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "onvolumechange", "playerVolumeChangedEvent(this)", player.Session()) player.session.updateProperty(player.htmlID(), "onvolumechange", "playerVolumeChangedEvent(this)")
} else { } else {
updateProperty(player.htmlID(), "onvolumechange", "", player.Session()) player.session.updateProperty(player.htmlID(), "onvolumechange", "")
} }
case DurationChangedEvent: case DurationChangedEvent:
if value := player.getRaw(tag); value != nil { if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "ondurationchange", "playerDurationChangedEvent(this)", player.Session()) player.session.updateProperty(player.htmlID(), "ondurationchange", "playerDurationChangedEvent(this)")
} else { } else {
updateProperty(player.htmlID(), "ondurationchange", "", player.Session()) player.session.updateProperty(player.htmlID(), "ondurationchange", "")
} }
case RateChangedEvent: case RateChangedEvent:
if value := player.getRaw(tag); value != nil { if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "onratechange", "playerRateChangedEvent(this)", player.Session()) player.session.updateProperty(player.htmlID(), "onratechange", "playerRateChangedEvent(this)")
} else { } else {
updateProperty(player.htmlID(), "onratechange", "", player.Session()) player.session.updateProperty(player.htmlID(), "onratechange", "")
} }
case PlayerErrorEvent: case PlayerErrorEvent:
if value := player.getRaw(tag); value != nil { if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "onerror", "playerErrorEvent(this)", player.Session()) player.session.updateProperty(player.htmlID(), "onerror", "playerErrorEvent(this)")
} else { } else {
updateProperty(player.htmlID(), "onerror", "", player.Session()) player.session.updateProperty(player.htmlID(), "onerror", "")
} }
case Source: case Source:
updateInnerHTML(player.htmlID(), player.Session()) updateInnerHTML(player.htmlID(), player.session)
} }
} }
} }
@ -544,7 +544,7 @@ func (player *mediaPlayerData) propertyChanged(tag string) {
func (player *mediaPlayerData) htmlSubviews(self View, buffer *strings.Builder) { func (player *mediaPlayerData) htmlSubviews(self View, buffer *strings.Builder) {
if value := player.getRaw(Source); value != nil { if value := player.getRaw(Source); value != nil {
if sources, ok := value.([]MediaSource); ok && len(sources) > 0 { if sources, ok := value.([]MediaSource); ok && len(sources) > 0 {
session := player.Session() session := player.session
for _, src := range sources { for _, src := range sources {
if url, ok := session.resolveConstants(src.Url); ok && url != "" { if url, ok := session.resolveConstants(src.Url); ok && url != "" {
buffer.WriteString(`<source src="`) buffer.WriteString(`<source src="`)
@ -565,13 +565,13 @@ func (player *mediaPlayerData) htmlSubviews(self View, buffer *strings.Builder)
func (player *mediaPlayerData) htmlProperties(self View, buffer *strings.Builder) { func (player *mediaPlayerData) htmlProperties(self View, buffer *strings.Builder) {
player.viewData.htmlProperties(self, buffer) player.viewData.htmlProperties(self, buffer)
for _, tag := range []string{Controls, Loop, Muted, Preload} { for _, tag := range []string{Controls, Loop, Muted, Preload} {
if value, _ := boolProperty(player, tag, player.Session()); value { if value, _ := boolProperty(player, tag, player.session); value {
buffer.WriteRune(' ') buffer.WriteRune(' ')
buffer.WriteString(tag) buffer.WriteString(tag)
} }
} }
if value, ok := enumProperty(player, Preload, player.Session(), 0); ok { if value, ok := enumProperty(player, Preload, player.session, 0); ok {
values := enumProperties[Preload].values values := enumProperties[Preload].values
buffer.WriteString(` preload="`) buffer.WriteString(` preload="`)
buffer.WriteString(values[value]) buffer.WriteString(values[value])
@ -667,7 +667,7 @@ func (player *mediaPlayerData) SetCurrentTime(seconds float64) {
} }
func (player *mediaPlayerData) getFloatPlayerProperty(tag string) (float64, bool) { func (player *mediaPlayerData) getFloatPlayerProperty(tag string) (float64, bool) {
value := player.Session().htmlPropertyValue(player.htmlID(), tag) value := player.session.htmlPropertyValue(player.htmlID(), tag)
if value != "" { if value != "" {
result, err := strconv.ParseFloat(value, 32) result, err := strconv.ParseFloat(value, 32)
if err == nil { if err == nil {
@ -718,7 +718,7 @@ func (player *mediaPlayerData) Volume() float64 {
} }
func (player *mediaPlayerData) getBoolPlayerProperty(tag string) (bool, bool) { func (player *mediaPlayerData) getBoolPlayerProperty(tag string) (bool, bool) {
switch value := player.Session().htmlPropertyValue(player.htmlID(), tag); strings.ToLower(value) { switch value := player.session.htmlPropertyValue(player.htmlID(), tag); strings.ToLower(value) {
case "0", "false", "off": case "0", "false", "off":
return false, true return false, true

View File

@ -167,7 +167,7 @@ func (view *viewData) setMouseListener(tag string, value any) bool {
} else if js, ok := mouseEvents[tag]; ok { } else if js, ok := mouseEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -179,7 +179,7 @@ func (view *viewData) removeMouseListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := mouseEvents[tag]; ok { if js, ok := mouseEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }

View File

@ -140,24 +140,24 @@ func (picker *numberPickerData) propertyChanged(tag string) {
switch tag { switch tag {
case NumberPickerType: case NumberPickerType:
if GetNumberPickerType(picker) == NumberSlider { if GetNumberPickerType(picker) == NumberSlider {
updateProperty(picker.htmlID(), "type", "range", picker.session) picker.session.updateProperty(picker.htmlID(), "type", "range")
} else { } else {
updateProperty(picker.htmlID(), "type", "number", picker.session) picker.session.updateProperty(picker.htmlID(), "type", "number")
} }
case NumberPickerMin: case NumberPickerMin:
min, _ := GetNumberPickerMinMax(picker) min, _ := GetNumberPickerMinMax(picker)
updateProperty(picker.htmlID(), Min, strconv.FormatFloat(min, 'f', -1, 32), picker.session) picker.session.updateProperty(picker.htmlID(), Min, strconv.FormatFloat(min, 'f', -1, 32))
case NumberPickerMax: case NumberPickerMax:
_, max := GetNumberPickerMinMax(picker) _, max := GetNumberPickerMinMax(picker)
updateProperty(picker.htmlID(), Max, strconv.FormatFloat(max, 'f', -1, 32), picker.session) picker.session.updateProperty(picker.htmlID(), Max, strconv.FormatFloat(max, 'f', -1, 32))
case NumberPickerStep: case NumberPickerStep:
if step := GetNumberPickerStep(picker); step > 0 { if step := GetNumberPickerStep(picker); step > 0 {
updateProperty(picker.htmlID(), Step, strconv.FormatFloat(step, 'f', -1, 32), picker.session) picker.session.updateProperty(picker.htmlID(), Step, strconv.FormatFloat(step, 'f', -1, 32))
} else { } else {
updateProperty(picker.htmlID(), Step, "any", picker.session) picker.session.updateProperty(picker.htmlID(), Step, "any")
} }
case NumberPickerValue: case NumberPickerValue:

View File

@ -108,7 +108,7 @@ func (view *viewData) setPointerListener(tag string, value any) bool {
} else if js, ok := pointerEvents[tag]; ok { } else if js, ok := pointerEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -120,7 +120,7 @@ func (view *viewData) removePointerListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := pointerEvents[tag]; ok { if js, ok := pointerEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }

View File

@ -610,7 +610,7 @@ func ShowPopup(view View, param Params) Popup {
func (manager *popupManager) updatePopupLayerInnerHTML(session Session) { func (manager *popupManager) updatePopupLayerInnerHTML(session Session) {
if manager.popups == nil { if manager.popups == nil {
manager.popups = []Popup{} manager.popups = []Popup{}
session.runFunc("updateInnerHTML", "ruiPopupLayer", "") session.updateInnerHTML("ruiPopupLayer", "")
return return
} }
@ -620,7 +620,7 @@ func (manager *popupManager) updatePopupLayerInnerHTML(session Session) {
for _, popup := range manager.popups { for _, popup := range manager.popups {
popup.html(buffer) popup.html(buffer)
} }
session.runFunc("updateInnerHTML", "ruiPopupLayer", buffer.String()) session.updateInnerHTML("ruiPopupLayer", buffer.String())
} }
func (manager *popupManager) showPopup(popup Popup) { func (manager *popupManager) showPopup(popup Popup) {
@ -637,8 +637,8 @@ func (manager *popupManager) showPopup(popup Popup) {
session.runFunc("blurCurrent") session.runFunc("blurCurrent")
manager.updatePopupLayerInnerHTML(session) manager.updatePopupLayerInnerHTML(session)
updateCSSProperty("ruiPopupLayer", "visibility", "visible", session) session.updateCSSProperty("ruiPopupLayer", "visibility", "visible")
updateCSSProperty("ruiRoot", "pointer-events", "none", session) session.updateCSSProperty("ruiRoot", "pointer-events", "none")
} }
func (manager *popupManager) dismissPopup(popup Popup) { func (manager *popupManager) dismissPopup(popup Popup) {
@ -656,9 +656,9 @@ func (manager *popupManager) dismissPopup(popup Popup) {
if manager.popups[count-1] == popup { if manager.popups[count-1] == popup {
if count == 1 { if count == 1 {
manager.popups = []Popup{} manager.popups = []Popup{}
updateCSSProperty("ruiRoot", "pointer-events", "auto", session) session.updateCSSProperty("ruiRoot", "pointer-events", "auto")
updateCSSProperty("ruiPopupLayer", "visibility", "hidden", session) session.updateCSSProperty("ruiPopupLayer", "visibility", "hidden")
session.runFunc("updateInnerHTML", "ruiPopupLayer", "") session.updateInnerHTML("ruiPopupLayer", "")
} else { } else {
manager.popups = manager.popups[:count-1] manager.popups = manager.popups[:count-1]
manager.updatePopupLayerInnerHTML(session) manager.updatePopupLayerInnerHTML(session)

View File

@ -65,10 +65,12 @@ func (progress *progressBarData) propertyChanged(tag string) {
if progress.created { if progress.created {
switch tag { switch tag {
case ProgressBarMax: case ProgressBarMax:
updateProperty(progress.htmlID(), Max, strconv.FormatFloat(GetProgressBarMax(progress), 'f', -1, 32), progress.session) progress.session.updateProperty(progress.htmlID(), Max,
strconv.FormatFloat(GetProgressBarMax(progress), 'f', -1, 32))
case ProgressBarValue: case ProgressBarValue:
updateProperty(progress.htmlID(), Value, strconv.FormatFloat(GetProgressBarValue(progress), 'f', -1, 32), progress.session) progress.session.updateProperty(progress.htmlID(), Value,
strconv.FormatFloat(GetProgressBarValue(progress), 'f', -1, 32))
} }
} }
} }

View File

@ -334,8 +334,8 @@ func (resizable *resizableData) updateResizeBorderWidth() {
session := resizable.Session() session := resizable.Session()
column, row := resizable.cellSizeCSS() column, row := resizable.cellSizeCSS()
updateCSSProperty(htmlID, "grid-template-columns", column, session) session.updateCSSProperty(htmlID, "grid-template-columns", column)
updateCSSProperty(htmlID, "grid-template-rows", row, session) session.updateCSSProperty(htmlID, "grid-template-rows", row)
} }
} }

View File

@ -9,6 +9,11 @@ import (
type webBrige interface { type webBrige interface {
runFunc(funcName string, args ...any) bool runFunc(funcName string, args ...any) bool
updateInnerHTML(htmlID, html string)
appendToInnerHTML(htmlID, html string)
updateCSSProperty(htmlID, property, value string)
updateProperty(htmlID, property, value any)
removeProperty(htmlID, property string)
readMessage() (string, bool) readMessage() (string, bool)
writeMessage(text string) bool writeMessage(text string) bool
canvasTextMetrics(htmlID, font, text string) TextMetrics canvasTextMetrics(htmlID, font, text string) TextMetrics
@ -99,6 +104,12 @@ type Session interface {
setBrige(events chan DataObject, brige webBrige) setBrige(events chan DataObject, brige webBrige)
writeInitScript(writer *strings.Builder) writeInitScript(writer *strings.Builder)
runFunc(funcName string, args ...any) runFunc(funcName string, args ...any)
updateInnerHTML(htmlID, html string)
appendToInnerHTML(htmlID, html string)
updateCSSProperty(htmlID, property, value string)
updateProperty(htmlID, property, value string)
updateBoolProperty(htmlID, property string, value bool)
removeProperty(htmlID, property string)
runScript(script string) runScript(script string)
canvasTextMetrics(htmlID, font, text string) TextMetrics canvasTextMetrics(htmlID, font, text string) TextMetrics
htmlPropertyValue(htmlID, name string) string htmlPropertyValue(htmlID, name string) string
@ -333,6 +344,74 @@ func (session *sessionData) runFunc(funcName string, args ...any) {
} }
} }
func (session *sessionData) updateInnerHTML(htmlID, html string) {
if !session.ignoreViewUpdates() {
if session.brige != nil {
session.brige.updateInnerHTML(htmlID, html)
} else {
ErrorLog("No connection")
}
}
}
func (session *sessionData) appendToInnerHTML(htmlID, html string) {
if !session.ignoreViewUpdates() {
if session.brige != nil {
session.brige.appendToInnerHTML(htmlID, html)
} else {
ErrorLog("No connection")
}
}
}
func (session *sessionData) updateCSSProperty(htmlID, property, value string) {
if !session.ignoreViewUpdates() {
if buffer := session.updateScript(htmlID); buffer != nil {
buffer.WriteString(fmt.Sprintf(`element.style['%v'] = '%v';`, property, value))
buffer.WriteRune('\n')
} else {
session.runFunc("updateCSSProperty", htmlID, property, value)
}
}
}
func (session *sessionData) updateProperty(htmlID, property, value string) {
if !session.ignoreViewUpdates() {
if buffer := session.updateScript(htmlID); buffer != nil {
buffer.WriteString(fmt.Sprintf(`element.setAttribute('%v', '%v');`, property, value))
buffer.WriteRune('\n')
} else {
session.runFunc("updateProperty", htmlID, property, value)
}
}
}
func (session *sessionData) updateBoolProperty(htmlID, property string, value bool) {
if !session.ignoreViewUpdates() {
if buffer := session.updateScript(htmlID); buffer != nil {
if value {
buffer.WriteString(fmt.Sprintf(`element.setAttribute('%v', true);`, property))
} else {
buffer.WriteString(fmt.Sprintf(`element.setAttribute('%v', false);`, property))
}
buffer.WriteRune('\n')
} else {
session.runFunc("updateProperty", htmlID, property, value)
}
}
}
func (session *sessionData) removeProperty(htmlID, property string) {
if !session.ignoreViewUpdates() {
if buffer := session.updateScript(htmlID); buffer != nil {
buffer.WriteString(fmt.Sprintf(`if (element.hasAttribute('%v')) { element.removeAttribute('%v');}`, property, property))
buffer.WriteRune('\n')
} else {
session.runFunc("removeProperty", htmlID, property)
}
}
}
func (session *sessionData) runScript(script string) { func (session *sessionData) runScript(script string) {
if session.brige != nil { if session.brige != nil {
session.brige.writeMessage(script) session.brige.writeMessage(script)

View File

@ -1,7 +1,6 @@
package rui package rui
import ( import (
"fmt"
"strings" "strings"
) )
@ -60,19 +59,12 @@ func updateInnerHTML(htmlID string, session Session) {
script.Grow(32 * 1024) script.Grow(32 * 1024)
view.htmlSubviews(view, script) view.htmlSubviews(view, script)
session.runFunc("updateInnerHTML", view.htmlID(), script.String()) session.updateInnerHTML(view.htmlID(), script.String())
}
}
}
func appendToInnerHTML(htmlID, content string, session Session) {
if !session.ignoreViewUpdates() {
if view := session.viewByHTMLID(htmlID); view != nil {
session.runFunc("appendToInnerHTML", view.htmlID(), content)
} }
} }
} }
/*
func updateProperty(htmlID, property, value string, session Session) { func updateProperty(htmlID, property, value string, session Session) {
if !session.ignoreViewUpdates() { if !session.ignoreViewUpdates() {
if buffer := session.updateScript(htmlID); buffer != nil { if buffer := session.updateScript(htmlID); buffer != nil {
@ -120,7 +112,7 @@ func removeProperty(htmlID, property string, session Session) {
} }
} }
} }
*/
/* /*
func setDisabled(htmlID string, disabled bool, session Session) { func setDisabled(htmlID string, disabled bool, session Session) {
if !session.ignoreViewUpdates() { if !session.ignoreViewUpdates() {

View File

@ -122,11 +122,11 @@ func (layout *stackLayoutData) set(tag string, value any) bool {
setCurrent := func(index int) { setCurrent := func(index int) {
if index != layout.peek { if index != layout.peek {
if layout.peek < len(layout.views) { if layout.peek < len(layout.views) {
updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(layout.peek), "visibility", "hidden", layout.Session()) layout.Session().updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(layout.peek), "visibility", "hidden")
} }
layout.peek = index layout.peek = index
updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(index), "visibility", "visible", layout.Session()) layout.Session().updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(index), "visibility", "visible")
layout.propertyChangedEvent(Current) layout.propertyChangedEvent(Current)
} }
} }
@ -204,11 +204,11 @@ func (layout *stackLayoutData) MoveToFront(view View) bool {
if view2.htmlID() == htmlID { if view2.htmlID() == htmlID {
if i != peek { if i != peek {
if peek < len(layout.views) { if peek < len(layout.views) {
updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(peek), "visibility", "hidden", layout.Session()) layout.Session().updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(peek), "visibility", "hidden")
} }
layout.peek = i layout.peek = i
updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(i), "visibility", "visible", layout.Session()) layout.Session().updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(i), "visibility", "visible")
layout.propertyChangedEvent(Current) layout.propertyChangedEvent(Current)
} }
return true return true
@ -225,11 +225,11 @@ func (layout *stackLayoutData) MoveToFrontByID(viewID string) bool {
if view.ID() == viewID { if view.ID() == viewID {
if i != peek { if i != peek {
if peek < len(layout.views) { if peek < len(layout.views) {
updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(peek), "visibility", "hidden", layout.Session()) layout.Session().updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(peek), "visibility", "hidden")
} }
layout.peek = i layout.peek = i
updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(i), "visibility", "visible", layout.Session()) layout.Session().updateCSSProperty(layout.htmlID()+"page"+strconv.Itoa(i), "visibility", "visible")
layout.propertyChangedEvent(Current) layout.propertyChangedEvent(Current)
} }
return true return true
@ -319,8 +319,8 @@ func (layout *stackLayoutData) Push(view View, animation int, onPushFinished fun
viewHTML(layout.pushView, buffer) viewHTML(layout.pushView, buffer)
buffer.WriteString(`</div>`) buffer.WriteString(`</div>`)
appendToInnerHTML(htmlID, buffer.String(), session) session.appendToInnerHTML(htmlID, buffer.String())
updateCSSProperty(htmlID+"push", "transform", "translate(0px, 0px)", layout.session) layout.session.updateCSSProperty(htmlID+"push", "transform", "translate(0px, 0px)")
layout.views = append(layout.views, view) layout.views = append(layout.views, view)
view.setParentID(htmlID) view.setParentID(htmlID)
@ -357,7 +357,7 @@ func (layout *stackLayoutData) Pop(animation int, onPopFinished func(View)) bool
viewHTML(layout.popView, buffer) viewHTML(layout.popView, buffer)
buffer.WriteString(`</div>`) buffer.WriteString(`</div>`)
appendToInnerHTML(htmlID, buffer.String(), session) session.appendToInnerHTML(htmlID, buffer.String())
var value string var value string
switch layout.animationType { switch layout.animationType {
@ -374,7 +374,7 @@ func (layout *stackLayoutData) Pop(animation int, onPopFinished func(View)) bool
value = fmt.Sprintf("translate(%gpx, 0px)", layout.frame.Width) value = fmt.Sprintf("translate(%gpx, 0px)", layout.frame.Width)
} }
updateCSSProperty(htmlID+"pop", "transform", value, layout.session) layout.session.updateCSSProperty(htmlID+"pop", "transform", value)
return true return true
} }

View File

@ -593,11 +593,11 @@ func (table *tableViewData) propertyChanged(tag string) {
session := table.Session() session := table.Session()
gap, ok := sizeProperty(table, Gap, session) gap, ok := sizeProperty(table, Gap, session)
if !ok || gap.Type == Auto || gap.Value <= 0 { if !ok || gap.Type == Auto || gap.Value <= 0 {
updateCSSProperty(htmlID, "border-spacing", "0", session) session.updateCSSProperty(htmlID, "border-spacing", "0")
updateCSSProperty(htmlID, "border-collapse", "collapse", session) session.updateCSSProperty(htmlID, "border-collapse", "collapse")
} else { } else {
updateCSSProperty(htmlID, "border-spacing", gap.cssString("0", session), session) session.updateCSSProperty(htmlID, "border-spacing", gap.cssString("0", session))
updateCSSProperty(htmlID, "border-collapse", "separate", session) session.updateCSSProperty(htmlID, "border-collapse", "separate")
} }
case SelectionMode: case SelectionMode:
@ -606,38 +606,38 @@ func (table *tableViewData) propertyChanged(tag string) {
switch GetTableSelectionMode(table) { switch GetTableSelectionMode(table) {
case CellSelection: case CellSelection:
updateProperty(htmlID, "tabindex", "0", session) session.updateProperty(htmlID, "tabindex", "0")
updateProperty(htmlID, "onfocus", "tableViewFocusEvent(this, event)", session) session.updateProperty(htmlID, "onfocus", "tableViewFocusEvent(this, event)")
updateProperty(htmlID, "onblur", "tableViewBlurEvent(this, event)", session) session.updateProperty(htmlID, "onblur", "tableViewBlurEvent(this, event)")
updateProperty(htmlID, "data-selection", "cell", session) session.updateProperty(htmlID, "data-selection", "cell")
updateProperty(htmlID, "data-focusitemstyle", table.currentStyle(), session) session.updateProperty(htmlID, "data-focusitemstyle", table.currentStyle())
updateProperty(htmlID, "data-bluritemstyle", table.currentInactiveStyle(), session) session.updateProperty(htmlID, "data-bluritemstyle", table.currentInactiveStyle())
if table.current.Row >= 0 && table.current.Column >= 0 { if table.current.Row >= 0 && table.current.Column >= 0 {
updateProperty(htmlID, "data-current", table.cellID(table.current.Row, table.current.Column), session) session.updateProperty(htmlID, "data-current", table.cellID(table.current.Row, table.current.Column))
} else { } else {
removeProperty(htmlID, "data-current", session) session.removeProperty(htmlID, "data-current")
} }
updateProperty(htmlID, "onkeydown", "tableViewCellKeyDownEvent(this, event)", session) session.updateProperty(htmlID, "onkeydown", "tableViewCellKeyDownEvent(this, event)")
case RowSelection: case RowSelection:
updateProperty(htmlID, "tabindex", "0", session) session.updateProperty(htmlID, "tabindex", "0")
updateProperty(htmlID, "onfocus", "tableViewFocusEvent(this, event)", session) session.updateProperty(htmlID, "onfocus", "tableViewFocusEvent(this, event)")
updateProperty(htmlID, "onblur", "tableViewBlurEvent(this, event)", session) session.updateProperty(htmlID, "onblur", "tableViewBlurEvent(this, event)")
updateProperty(htmlID, "data-selection", "row", session) session.updateProperty(htmlID, "data-selection", "row")
updateProperty(htmlID, "data-focusitemstyle", table.currentStyle(), session) session.updateProperty(htmlID, "data-focusitemstyle", table.currentStyle())
updateProperty(htmlID, "data-bluritemstyle", table.currentInactiveStyle(), session) session.updateProperty(htmlID, "data-bluritemstyle", table.currentInactiveStyle())
if table.current.Row >= 0 { if table.current.Row >= 0 {
updateProperty(htmlID, "data-current", table.rowID(table.current.Row), session) session.updateProperty(htmlID, "data-current", table.rowID(table.current.Row))
} else { } else {
removeProperty(htmlID, "data-current", session) session.removeProperty(htmlID, "data-current")
} }
updateProperty(htmlID, "onkeydown", "tableViewRowKeyDownEvent(this, event)", session) session.updateProperty(htmlID, "onkeydown", "tableViewRowKeyDownEvent(this, event)")
default: // NoneSelection default: // NoneSelection
for _, prop := range []string{"tabindex", "data-current", "onfocus", "onblur", "onkeydown", "data-selection"} { for _, prop := range []string{"tabindex", "data-current", "onfocus", "onblur", "onkeydown", "data-selection"} {
removeProperty(htmlID, prop, session) session.removeProperty(htmlID, prop)
} }
} }
updateInnerHTML(htmlID, session) updateInnerHTML(htmlID, session)
@ -1335,11 +1335,12 @@ func (table *tableViewData) cssStyle(self View, builder cssBuilder) {
func (table *tableViewData) ReloadTableData() { func (table *tableViewData) ReloadTableData() {
session := table.Session() session := table.Session()
htmlID := table.htmlID()
if content := table.content(); content != nil { if content := table.content(); content != nil {
updateProperty(table.htmlID(), "data-rows", strconv.Itoa(content.RowCount()), session) session.updateProperty(htmlID, "data-rows", strconv.Itoa(content.RowCount()))
updateProperty(table.htmlID(), "data-columns", strconv.Itoa(content.ColumnCount()), session) session.updateProperty(htmlID, "data-columns", strconv.Itoa(content.ColumnCount()))
} }
updateInnerHTML(table.htmlID(), session) updateInnerHTML(htmlID, session)
} }
func (table *tableViewData) onItemResize(self View, index string, x, y, width, height float64) { func (table *tableViewData) onItemResize(self View, index string, x, y, width, height float64) {

View File

@ -161,8 +161,8 @@ func (tabsLayout *tabsLayoutData) remove(tag string) {
delete(tabsLayout.properties, Tabs) delete(tabsLayout.properties, Tabs)
if tabsLayout.created { if tabsLayout.created {
htmlID := tabsLayout.htmlID() htmlID := tabsLayout.htmlID()
updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle())
updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle())
updateCSSStyle(htmlID, tabsLayout.session) updateCSSStyle(htmlID, tabsLayout.session)
updateInnerHTML(htmlID, tabsLayout.session) updateInnerHTML(htmlID, tabsLayout.session)
} }
@ -171,8 +171,8 @@ func (tabsLayout *tabsLayoutData) remove(tag string) {
delete(tabsLayout.properties, tag) delete(tabsLayout.properties, tag)
if tabsLayout.created { if tabsLayout.created {
htmlID := tabsLayout.htmlID() htmlID := tabsLayout.htmlID()
updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle())
updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle())
updateInnerHTML(htmlID, tabsLayout.session) updateInnerHTML(htmlID, tabsLayout.session)
} }
@ -247,8 +247,8 @@ func (tabsLayout *tabsLayoutData) set(tag string, value any) bool {
} }
if tabsLayout.created { if tabsLayout.created {
htmlID := tabsLayout.htmlID() htmlID := tabsLayout.htmlID()
updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle())
updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle())
updateCSSStyle(htmlID, tabsLayout.session) updateCSSStyle(htmlID, tabsLayout.session)
updateInnerHTML(htmlID, tabsLayout.session) updateInnerHTML(htmlID, tabsLayout.session)
} }
@ -267,8 +267,8 @@ func (tabsLayout *tabsLayoutData) set(tag string, value any) bool {
if tabsLayout.created { if tabsLayout.created {
htmlID := tabsLayout.htmlID() htmlID := tabsLayout.htmlID()
updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, inactiveTabStyle, tabsLayout.inactiveTabStyle())
updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle(), tabsLayout.session) tabsLayout.session.updateProperty(htmlID, activeTabStyle, tabsLayout.activeTabStyle())
updateInnerHTML(htmlID, tabsLayout.session) updateInnerHTML(htmlID, tabsLayout.session)
} }

View File

@ -125,14 +125,14 @@ func (textView *textViewData) set(tag string, value any) bool {
func (textView *textViewData) textOverflowUpdated() { func (textView *textViewData) textOverflowUpdated() {
session := textView.Session() session := textView.Session()
if n, ok := enumProperty(textView, TextOverflow, textView.session, 0); ok { if n, ok := enumProperty(textView, TextOverflow, session, 0); ok {
values := enumProperties[TextOverflow].cssValues values := enumProperties[TextOverflow].cssValues
if n >= 0 && n < len(values) { if n >= 0 && n < len(values) {
updateCSSProperty(textView.htmlID(), TextOverflow, values[n], session) session.updateCSSProperty(textView.htmlID(), TextOverflow, values[n])
return return
} }
} }
updateCSSProperty(textView.htmlID(), TextOverflow, "", session) session.updateCSSProperty(textView.htmlID(), TextOverflow, "")
} }
func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) { func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) {

View File

@ -77,19 +77,19 @@ func (picker *timePickerData) remove(tag string) {
case TimePickerMin: case TimePickerMin:
delete(picker.properties, TimePickerMin) delete(picker.properties, TimePickerMin)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), Min, picker.session) picker.session.removeProperty(picker.htmlID(), Min)
} }
case TimePickerMax: case TimePickerMax:
delete(picker.properties, TimePickerMax) delete(picker.properties, TimePickerMax)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), Max, picker.session) picker.session.removeProperty(picker.htmlID(), Max)
} }
case TimePickerStep: case TimePickerStep:
delete(picker.properties, TimePickerStep) delete(picker.properties, TimePickerStep)
if picker.created { if picker.created {
removeProperty(picker.htmlID(), Step, picker.session) picker.session.removeProperty(picker.htmlID(), Step)
} }
case TimePickerValue: case TimePickerValue:
@ -171,7 +171,7 @@ func (picker *timePickerData) set(tag string, value any) bool {
if time, ok := setTimeValue(TimePickerMin); ok { if time, ok := setTimeValue(TimePickerMin); ok {
if !oldOK || time != old { if !oldOK || time != old {
if picker.created { if picker.created {
updateProperty(picker.htmlID(), Min, time.Format(timeFormat), picker.session) picker.session.updateProperty(picker.htmlID(), Min, time.Format(timeFormat))
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
@ -183,7 +183,7 @@ func (picker *timePickerData) set(tag string, value any) bool {
if time, ok := setTimeValue(TimePickerMax); ok { if time, ok := setTimeValue(TimePickerMax); ok {
if !oldOK || time != old { if !oldOK || time != old {
if picker.created { if picker.created {
updateProperty(picker.htmlID(), Max, time.Format(timeFormat), picker.session) picker.session.updateProperty(picker.htmlID(), Max, time.Format(timeFormat))
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)
} }
@ -196,9 +196,9 @@ func (picker *timePickerData) set(tag string, value any) bool {
if step := GetTimePickerStep(picker); oldStep != step { if step := GetTimePickerStep(picker); oldStep != step {
if picker.created { if picker.created {
if step > 0 { if step > 0 {
updateProperty(picker.htmlID(), Step, strconv.Itoa(step), picker.session) picker.session.updateProperty(picker.htmlID(), Step, strconv.Itoa(step))
} else { } else {
removeProperty(picker.htmlID(), Step, picker.session) picker.session.removeProperty(picker.htmlID(), Step)
} }
} }
picker.propertyChangedEvent(tag) picker.propertyChangedEvent(tag)

View File

@ -109,7 +109,7 @@ func (view *viewData) setTouchListener(tag string, value any) bool {
} else if js, ok := touchEvents[tag]; ok { } else if js, ok := touchEvents[tag]; ok {
view.properties[tag] = listeners view.properties[tag] = listeners
if view.created { if view.created {
updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)", view.Session()) view.session.updateProperty(view.htmlID(), js.jsEvent, js.jsFunc+"(this, event)")
} }
} else { } else {
return false return false
@ -121,7 +121,7 @@ func (view *viewData) removeTouchListener(tag string) {
delete(view.properties, tag) delete(view.properties, tag)
if view.created { if view.created {
if js, ok := touchEvents[tag]; ok { if js, ok := touchEvents[tag]; ok {
removeProperty(view.htmlID(), js.jsEvent, view.Session()) view.session.removeProperty(view.htmlID(), js.jsEvent)
} }
} }
} }

View File

@ -61,15 +61,15 @@ func (player *videoPlayerData) remove(tag string) {
case VideoWidth: case VideoWidth:
delete(player.properties, tag) delete(player.properties, tag)
removeProperty(player.htmlID(), "width", player.Session()) player.session.removeProperty(player.htmlID(), "width")
case VideoHeight: case VideoHeight:
delete(player.properties, tag) delete(player.properties, tag)
removeProperty(player.htmlID(), "height", player.Session()) player.session.removeProperty(player.htmlID(), "height")
case Poster: case Poster:
delete(player.properties, tag) delete(player.properties, tag)
removeProperty(player.htmlID(), Poster, player.Session()) player.session.removeProperty(player.htmlID(), Poster)
default: default:
player.mediaPlayerData.remove(tag) player.mediaPlayerData.remove(tag)
@ -91,9 +91,9 @@ func (player *videoPlayerData) set(tag string, value any) bool {
updateSize := func(cssTag string) { updateSize := func(cssTag string) {
if size, ok := floatTextProperty(player, tag, session, 0); ok { if size, ok := floatTextProperty(player, tag, session, 0); ok {
if size != "0" { if size != "0" {
updateProperty(player.htmlID(), cssTag, size, session) session.updateProperty(player.htmlID(), cssTag, size)
} else { } else {
removeProperty(player.htmlID(), cssTag, session) session.removeProperty(player.htmlID(), cssTag)
} }
} }
} }
@ -107,7 +107,7 @@ func (player *videoPlayerData) set(tag string, value any) bool {
case Poster: case Poster:
if url, ok := stringProperty(player, Poster, session); ok { if url, ok := stringProperty(player, Poster, session); ok {
updateProperty(player.htmlID(), Poster, url, session) session.updateProperty(player.htmlID(), Poster, url)
} }
} }
return true return true

120
view.go
View File

@ -193,7 +193,7 @@ func (view *viewData) remove(tag string) {
case Style, StyleDisabled: case Style, StyleDisabled:
if _, ok := view.properties[tag]; ok { if _, ok := view.properties[tag]; ok {
delete(view.properties, tag) delete(view.properties, tag)
updateProperty(view.htmlID(), "class", view.htmlClass(IsDisabled(view)), view.session) view.session.updateProperty(view.htmlID(), "class", view.htmlClass(IsDisabled(view)))
} }
case FocusEvent, LostFocusEvent: case FocusEvent, LostFocusEvent:
@ -323,7 +323,7 @@ func (view *viewData) set(tag string, value any) bool {
} }
view.properties[tag] = text view.properties[tag] = text
if view.created { if view.created {
updateProperty(view.htmlID(), "class", view.htmlClass(IsDisabled(view)), view.session) view.session.updateProperty(view.htmlID(), "class", view.htmlClass(IsDisabled(view)))
} }
case FocusEvent, LostFocusEvent: case FocusEvent, LostFocusEvent:
@ -379,21 +379,21 @@ func viewPropertyChanged(view *viewData, tag string) {
case Visibility: case Visibility:
switch GetVisibility(view) { switch GetVisibility(view) {
case Invisible: case Invisible:
updateCSSProperty(htmlID, Visibility, "hidden", session) session.updateCSSProperty(htmlID, Visibility, "hidden")
updateCSSProperty(htmlID, "display", "", session) session.updateCSSProperty(htmlID, "display", "")
case Gone: case Gone:
updateCSSProperty(htmlID, Visibility, "hidden", session) session.updateCSSProperty(htmlID, Visibility, "hidden")
updateCSSProperty(htmlID, "display", "none", session) session.updateCSSProperty(htmlID, "display", "none")
default: default:
updateCSSProperty(htmlID, Visibility, "visible", session) session.updateCSSProperty(htmlID, Visibility, "visible")
updateCSSProperty(htmlID, "display", "", session) session.updateCSSProperty(htmlID, "display", "")
} }
return return
case Background: case Background:
updateCSSProperty(htmlID, Background, view.backgroundCSS(session), session) session.updateCSSProperty(htmlID, Background, view.backgroundCSS(session))
return return
case Border: case Border:
@ -402,9 +402,9 @@ func viewPropertyChanged(view *viewData, tag string) {
if buffer == nil { if buffer == nil {
session.startUpdateScript(htmlID) session.startUpdateScript(htmlID)
} }
updateCSSProperty(htmlID, BorderWidth, "", session) session.updateCSSProperty(htmlID, BorderWidth, "")
updateCSSProperty(htmlID, BorderColor, "", session) session.updateCSSProperty(htmlID, BorderColor, "")
updateCSSProperty(htmlID, BorderStyle, "none", session) session.updateCSSProperty(htmlID, BorderStyle, "none")
if buffer == nil { if buffer == nil {
session.finishUpdateScript(htmlID) session.finishUpdateScript(htmlID)
} }
@ -418,9 +418,9 @@ func viewPropertyChanged(view *viewData, tag string) {
if buffer == nil { if buffer == nil {
session.startUpdateScript(htmlID) session.startUpdateScript(htmlID)
} }
updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session), session) session.updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session))
updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session), session) session.updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session))
updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session), session) session.updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session))
if buffer == nil { if buffer == nil {
session.finishUpdateScript(htmlID) session.finishUpdateScript(htmlID)
} }
@ -429,32 +429,32 @@ func viewPropertyChanged(view *viewData, tag string) {
case BorderStyle, BorderLeftStyle, BorderRightStyle, BorderTopStyle, BorderBottomStyle: case BorderStyle, BorderLeftStyle, BorderRightStyle, BorderTopStyle, BorderBottomStyle:
if border := getBorder(view, Border); border != nil { if border := getBorder(view, Border); border != nil {
updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session), session) session.updateCSSProperty(htmlID, BorderStyle, border.cssStyleValue(session))
} }
return return
case BorderColor, BorderLeftColor, BorderRightColor, BorderTopColor, BorderBottomColor: case BorderColor, BorderLeftColor, BorderRightColor, BorderTopColor, BorderBottomColor:
if border := getBorder(view, Border); border != nil { if border := getBorder(view, Border); border != nil {
updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session), session) session.updateCSSProperty(htmlID, BorderColor, border.cssColorValue(session))
} }
return return
case BorderWidth, BorderLeftWidth, BorderRightWidth, BorderTopWidth, BorderBottomWidth: case BorderWidth, BorderLeftWidth, BorderRightWidth, BorderTopWidth, BorderBottomWidth:
if border := getBorder(view, Border); border != nil { if border := getBorder(view, Border); border != nil {
updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session), session) session.updateCSSProperty(htmlID, BorderWidth, border.cssWidthValue(session))
} }
return return
case Outline, OutlineColor, OutlineStyle, OutlineWidth: case Outline, OutlineColor, OutlineStyle, OutlineWidth:
updateCSSProperty(htmlID, Outline, GetOutline(view).cssString(session), session) session.updateCSSProperty(htmlID, Outline, GetOutline(view).cssString(session))
return return
case Shadow: case Shadow:
updateCSSProperty(htmlID, "box-shadow", shadowCSS(view, Shadow, session), session) session.updateCSSProperty(htmlID, "box-shadow", shadowCSS(view, Shadow, session))
return return
case TextShadow: case TextShadow:
updateCSSProperty(htmlID, "text-shadow", shadowCSS(view, TextShadow, session), session) session.updateCSSProperty(htmlID, "text-shadow", shadowCSS(view, TextShadow, session))
return return
case Radius, RadiusX, RadiusY, RadiusTopLeft, RadiusTopLeftX, RadiusTopLeftY, case Radius, RadiusX, RadiusY, RadiusTopLeft, RadiusTopLeftX, RadiusTopLeftY,
@ -462,44 +462,44 @@ func viewPropertyChanged(view *viewData, tag string) {
RadiusBottomLeft, RadiusBottomLeftX, RadiusBottomLeftY, RadiusBottomLeft, RadiusBottomLeftX, RadiusBottomLeftY,
RadiusBottomRight, RadiusBottomRightX, RadiusBottomRightY: RadiusBottomRight, RadiusBottomRightX, RadiusBottomRightY:
radius := GetRadius(view) radius := GetRadius(view)
updateCSSProperty(htmlID, "border-radius", radius.cssString(session), session) session.updateCSSProperty(htmlID, "border-radius", radius.cssString(session))
return return
case Margin, MarginTop, MarginRight, MarginBottom, MarginLeft, case Margin, MarginTop, MarginRight, MarginBottom, MarginLeft,
"top-margin", "right-margin", "bottom-margin", "left-margin": "top-margin", "right-margin", "bottom-margin", "left-margin":
margin := GetMargin(view) margin := GetMargin(view)
updateCSSProperty(htmlID, Margin, margin.cssString(session), session) session.updateCSSProperty(htmlID, Margin, margin.cssString(session))
return return
case Padding, PaddingTop, PaddingRight, PaddingBottom, PaddingLeft, case Padding, PaddingTop, PaddingRight, PaddingBottom, PaddingLeft,
"top-padding", "right-padding", "bottom-padding", "left-padding": "top-padding", "right-padding", "bottom-padding", "left-padding":
padding := GetPadding(view) padding := GetPadding(view)
updateCSSProperty(htmlID, Padding, padding.cssString(session), session) session.updateCSSProperty(htmlID, Padding, padding.cssString(session))
return return
case AvoidBreak: case AvoidBreak:
if avoid, ok := boolProperty(view, AvoidBreak, session); ok { if avoid, ok := boolProperty(view, AvoidBreak, session); ok {
if avoid { if avoid {
updateCSSProperty(htmlID, "break-inside", "avoid", session) session.updateCSSProperty(htmlID, "break-inside", "avoid")
} else { } else {
updateCSSProperty(htmlID, "break-inside", "auto", session) session.updateCSSProperty(htmlID, "break-inside", "auto")
} }
} }
return return
case Clip: case Clip:
if clip := getClipShape(view, Clip, session); clip != nil && clip.valid(session) { if clip := getClipShape(view, Clip, session); clip != nil && clip.valid(session) {
updateCSSProperty(htmlID, `clip-path`, clip.cssStyle(session), session) session.updateCSSProperty(htmlID, `clip-path`, clip.cssStyle(session))
} else { } else {
updateCSSProperty(htmlID, `clip-path`, "none", session) session.updateCSSProperty(htmlID, `clip-path`, "none")
} }
return return
case ShapeOutside: case ShapeOutside:
if clip := getClipShape(view, ShapeOutside, session); clip != nil && clip.valid(session) { if clip := getClipShape(view, ShapeOutside, session); clip != nil && clip.valid(session) {
updateCSSProperty(htmlID, ShapeOutside, clip.cssStyle(session), session) session.updateCSSProperty(htmlID, ShapeOutside, clip.cssStyle(session))
} else { } else {
updateCSSProperty(htmlID, ShapeOutside, "none", session) session.updateCSSProperty(htmlID, ShapeOutside, "none")
} }
return return
@ -510,7 +510,7 @@ func viewPropertyChanged(view *viewData, tag string) {
text = filter.cssStyle(session) text = filter.cssStyle(session)
} }
} }
updateCSSProperty(htmlID, tag, text, session) session.updateCSSProperty(htmlID, tag, text)
return return
case BackdropFilter: case BackdropFilter:
@ -524,8 +524,8 @@ func viewPropertyChanged(view *viewData, tag string) {
if buffer == nil { if buffer == nil {
session.startUpdateScript(htmlID) session.startUpdateScript(htmlID)
} }
updateCSSProperty(htmlID, "-webkit-backdrop-filter", text, session) session.updateCSSProperty(htmlID, "-webkit-backdrop-filter", text)
updateCSSProperty(htmlID, tag, text, session) session.updateCSSProperty(htmlID, tag, text)
if buffer == nil { if buffer == nil {
session.finishUpdateScript(htmlID) session.finishUpdateScript(htmlID)
} }
@ -533,38 +533,38 @@ func viewPropertyChanged(view *viewData, tag string) {
case FontName: case FontName:
if font, ok := stringProperty(view, FontName, session); ok { if font, ok := stringProperty(view, FontName, session); ok {
updateCSSProperty(htmlID, "font-family", font, session) session.updateCSSProperty(htmlID, "font-family", font)
} else { } else {
updateCSSProperty(htmlID, "font-family", "", session) session.updateCSSProperty(htmlID, "font-family", "")
} }
return return
case Italic: case Italic:
if state, ok := boolProperty(view, tag, session); ok { if state, ok := boolProperty(view, tag, session); ok {
if state { if state {
updateCSSProperty(htmlID, "font-style", "italic", session) session.updateCSSProperty(htmlID, "font-style", "italic")
} else { } else {
updateCSSProperty(htmlID, "font-style", "normal", session) session.updateCSSProperty(htmlID, "font-style", "normal")
} }
} else { } else {
updateCSSProperty(htmlID, "font-style", "", session) session.updateCSSProperty(htmlID, "font-style", "")
} }
return return
case SmallCaps: case SmallCaps:
if state, ok := boolProperty(view, tag, session); ok { if state, ok := boolProperty(view, tag, session); ok {
if state { if state {
updateCSSProperty(htmlID, "font-variant", "small-caps", session) session.updateCSSProperty(htmlID, "font-variant", "small-caps")
} else { } else {
updateCSSProperty(htmlID, "font-variant", "normal", session) session.updateCSSProperty(htmlID, "font-variant", "normal")
} }
} else { } else {
updateCSSProperty(htmlID, "font-variant", "", session) session.updateCSSProperty(htmlID, "font-variant", "")
} }
return return
case Strikethrough, Overline, Underline: case Strikethrough, Overline, Underline:
updateCSSProperty(htmlID, "text-decoration", view.cssTextDecoration(session), session) session.updateCSSProperty(htmlID, "text-decoration", view.cssTextDecoration(session))
for _, tag2 := range []string{TextLineColor, TextLineStyle, TextLineThickness} { for _, tag2 := range []string{TextLineColor, TextLineStyle, TextLineThickness} {
viewPropertyChanged(view, tag2) viewPropertyChanged(view, tag2)
} }
@ -575,29 +575,29 @@ func viewPropertyChanged(view *viewData, tag string) {
return return
case AnimationTag: case AnimationTag:
updateCSSProperty(htmlID, AnimationTag, view.animationCSS(session), session) session.updateCSSProperty(htmlID, AnimationTag, view.animationCSS(session))
return return
case AnimationPaused: case AnimationPaused:
paused, ok := boolProperty(view, AnimationPaused, session) paused, ok := boolProperty(view, AnimationPaused, session)
if !ok { if !ok {
updateCSSProperty(htmlID, `animation-play-state`, ``, session) session.updateCSSProperty(htmlID, `animation-play-state`, ``)
} else if paused { } else if paused {
updateCSSProperty(htmlID, `animation-play-state`, `paused`, session) session.updateCSSProperty(htmlID, `animation-play-state`, `paused`)
} else { } else {
updateCSSProperty(htmlID, `animation-play-state`, `running`, session) session.updateCSSProperty(htmlID, `animation-play-state`, `running`)
} }
return return
case ZIndex, TabSize: case ZIndex, TabSize:
if i, ok := intProperty(view, tag, session, 0); ok { if i, ok := intProperty(view, tag, session, 0); ok {
updateCSSProperty(htmlID, tag, strconv.Itoa(i), session) session.updateCSSProperty(htmlID, tag, strconv.Itoa(i))
} }
return return
case Row, Column: case Row, Column:
if parent := view.parentHTMLID(); parent != "" { if parentID := view.parentHTMLID(); parentID != "" {
updateInnerHTML(parent, session) updateInnerHTML(parentID, session)
} }
return return
@ -608,15 +608,15 @@ func viewPropertyChanged(view *viewData, tag string) {
} }
if userSelect, ok := boolProperty(view, UserSelect, session); ok { if userSelect, ok := boolProperty(view, UserSelect, session); ok {
if userSelect { if userSelect {
updateCSSProperty(htmlID, "-webkit-user-select", "auto", session) session.updateCSSProperty(htmlID, "-webkit-user-select", "auto")
updateCSSProperty(htmlID, "user-select", "auto", session) session.updateCSSProperty(htmlID, "user-select", "auto")
} else { } else {
updateCSSProperty(htmlID, "-webkit-user-select", "none", session) session.updateCSSProperty(htmlID, "-webkit-user-select", "none")
updateCSSProperty(htmlID, "user-select", "none", session) session.updateCSSProperty(htmlID, "user-select", "none")
} }
} else { } else {
updateCSSProperty(htmlID, "-webkit-user-select", "", session) session.updateCSSProperty(htmlID, "-webkit-user-select", "")
updateCSSProperty(htmlID, "user-select", "", session) session.updateCSSProperty(htmlID, "user-select", "")
} }
if buffer == nil { if buffer == nil {
session.finishUpdateScript(htmlID) session.finishUpdateScript(htmlID)
@ -626,7 +626,7 @@ func viewPropertyChanged(view *viewData, tag string) {
if cssTag, ok := sizeProperties[tag]; ok { if cssTag, ok := sizeProperties[tag]; ok {
size, _ := sizeProperty(view, tag, session) size, _ := sizeProperty(view, tag, session)
updateCSSProperty(htmlID, cssTag, size.cssString("", session), session) session.updateCSSProperty(htmlID, cssTag, size.cssString("", session))
return return
} }
@ -639,23 +639,23 @@ func viewPropertyChanged(view *viewData, tag string) {
} }
if cssTag, ok := colorTags[tag]; ok { if cssTag, ok := colorTags[tag]; ok {
if color, ok := colorProperty(view, tag, session); ok { if color, ok := colorProperty(view, tag, session); ok {
updateCSSProperty(htmlID, cssTag, color.cssString(), session) session.updateCSSProperty(htmlID, cssTag, color.cssString())
} else { } else {
updateCSSProperty(htmlID, cssTag, "", session) session.updateCSSProperty(htmlID, cssTag, "")
} }
return return
} }
if valuesData, ok := enumProperties[tag]; ok && valuesData.cssTag != "" { if valuesData, ok := enumProperties[tag]; ok && valuesData.cssTag != "" {
n, _ := enumProperty(view, tag, session, 0) n, _ := enumProperty(view, tag, session, 0)
updateCSSProperty(htmlID, valuesData.cssTag, valuesData.cssValues[n], session) session.updateCSSProperty(htmlID, valuesData.cssTag, valuesData.cssValues[n])
return return
} }
for _, floatTag := range []string{Opacity, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ} { for _, floatTag := range []string{Opacity, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ} {
if tag == floatTag { if tag == floatTag {
if f, ok := floatTextProperty(view, floatTag, session, 0); ok { if f, ok := floatTextProperty(view, floatTag, session, 0); ok {
updateCSSProperty(htmlID, floatTag, f, session) session.updateCSSProperty(htmlID, floatTag, f)
} }
return return
} }

View File

@ -250,15 +250,15 @@ func (view *viewData) updateTransformProperty(tag string) bool {
if x.Type != Auto || y.Type != Auto { if x.Type != Auto || y.Type != Auto {
value = x.cssString("50%", session) + " " + y.cssString("50%", session) value = x.cssString("50%", session) + " " + y.cssString("50%", session)
} }
updateCSSProperty(htmlID, "perspective-origin", value, session) session.updateCSSProperty(htmlID, "perspective-origin", value)
} }
case BackfaceVisible: case BackfaceVisible:
if getTransform3D(view, session) { if getTransform3D(view, session) {
if GetBackfaceVisible(view) { if GetBackfaceVisible(view) {
updateCSSProperty(htmlID, BackfaceVisible, "visible", session) session.updateCSSProperty(htmlID, BackfaceVisible, "visible")
} else { } else {
updateCSSProperty(htmlID, BackfaceVisible, "hidden", session) session.updateCSSProperty(htmlID, BackfaceVisible, "hidden")
} }
} }
@ -274,10 +274,10 @@ func (view *viewData) updateTransformProperty(tag string) bool {
value = x.cssString("50%", session) + " " + y.cssString("50%", session) value = x.cssString("50%", session) + " " + y.cssString("50%", session)
} }
} }
updateCSSProperty(htmlID, "transform-origin", value, session) session.updateCSSProperty(htmlID, "transform-origin", value)
case SkewX, SkewY, TranslateX, TranslateY, TranslateZ, ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ: case SkewX, SkewY, TranslateX, TranslateY, TranslateZ, ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ:
updateCSSProperty(htmlID, "transform", view.transform(session), session) session.updateCSSProperty(htmlID, "transform", view.transform(session))
default: default:
return false return false

View File

@ -134,6 +134,26 @@ func (brige *wsBrige) runFunc(funcName string, args ...any) bool {
return true return true
} }
func (brige *wsBrige) updateInnerHTML(htmlID, html string) {
brige.runFunc("updateInnerHTML", htmlID, html)
}
func (brige *wsBrige) appendToInnerHTML(htmlID, html string) {
brige.runFunc("appendToInnerHTML", htmlID, html)
}
func (brige *wsBrige) updateCSSProperty(htmlID, property, value string) {
brige.runFunc("updateCSSProperty", htmlID, property, value)
}
func (brige *wsBrige) updateProperty(htmlID, property, value any) {
brige.runFunc("updateProperty", htmlID, property, value)
}
func (brige *wsBrige) removeProperty(htmlID, property string) {
brige.runFunc("removeProperty", htmlID, property)
}
func (brige *wsBrige) readMessage() (string, bool) { func (brige *wsBrige) readMessage() (string, bool) {
_, p, err := brige.conn.ReadMessage() _, p, err := brige.conn.ReadMessage()
if err != nil { if err != nil {