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()
session.startUpdateScript(htmlID)
updateProperty(htmlID, "ontransitionend", "transitionEndEvent(this, event)", view.session)
updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)", view.session)
session.updateProperty(htmlID, "ontransitionend", "transitionEndEvent(this, event)")
session.updateProperty(htmlID, "ontransitioncancel", "transitionCancelEvent(this, event)")
if prevAnimation, ok := view.transitions[tag]; ok {
view.singleTransition[tag] = prevAnimation
@ -701,7 +701,7 @@ func (style *viewStyle) transitionCSS(session Session) string {
}
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 {
@ -732,7 +732,7 @@ func (style *viewStyle) SetTransition(tag string, animation Animation) {
func (view *viewData) SetTransition(tag string, animation Animation) {
view.viewStyle.SetTransition(tag, animation)
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 {
view.properties[tag] = listeners
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 {
return false
@ -82,7 +82,7 @@ func (view *viewData) removeTransitionListener(tag string) {
delete(view.properties, tag)
if view.created {
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 {
view.properties[tag] = listeners
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 {
return false
@ -148,7 +148,7 @@ func (view *viewData) removeAnimationListener(tag string) {
delete(view.properties, tag)
if view.created {
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
}
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:
@ -106,7 +106,7 @@ func (button *checkboxData) set(tag string, value any) bool {
return false
}
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:
@ -159,13 +159,13 @@ func (button *checkboxData) remove(tag string) {
case VerticalAlign:
delete(button.properties, tag)
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:
delete(button.properties, tag)
if button.created {
updateCSSProperty(button.htmlID()+"content", "justify-items", button.cssHorizontalAlign(), button.session)
button.session.updateCSSProperty(button.htmlID()+"content", "justify-items", button.cssHorizontalAlign())
}
default:
@ -189,7 +189,7 @@ func (button *checkboxData) changedCheckboxState(state bool) {
defer freeStringBuilder(buffer)
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) {

View File

@ -89,10 +89,10 @@ func (columnLayout *columnLayoutData) remove(tag string) {
if columnLayout.created {
switch tag {
case ColumnCount, ColumnWidth, ColumnGap:
updateCSSProperty(columnLayout.htmlID(), tag, "", columnLayout.Session())
columnLayout.session.updateCSSProperty(columnLayout.htmlID(), tag, "")
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)
css = separator.cssValue(columnLayout.Session())
}
updateCSSProperty(columnLayout.htmlID(), "column-rule", css, session)
session.updateCSSProperty(columnLayout.htmlID(), "column-rule", css)
case ColumnCount:
session := columnLayout.Session()
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 {
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:
delete(picker.properties, DatePickerMin)
if picker.created {
removeProperty(picker.htmlID(), Min, picker.session)
picker.session.removeProperty(picker.htmlID(), Min)
}
case DatePickerMax:
delete(picker.properties, DatePickerMax)
if picker.created {
removeProperty(picker.htmlID(), Max, picker.session)
picker.session.removeProperty(picker.htmlID(), Max)
}
case DatePickerStep:
delete(picker.properties, DatePickerStep)
if picker.created {
removeProperty(picker.htmlID(), Step, picker.session)
picker.session.removeProperty(picker.htmlID(), Step)
}
case DatePickerValue:
@ -183,7 +183,7 @@ func (picker *datePickerData) set(tag string, value any) bool {
if date, ok := setTimeValue(DatePickerMin); ok {
if !oldOK || date != old {
if picker.created {
updateProperty(picker.htmlID(), Min, date.Format(dateFormat), picker.session)
picker.session.updateProperty(picker.htmlID(), Min, date.Format(dateFormat))
}
picker.propertyChangedEvent(tag)
}
@ -195,7 +195,7 @@ func (picker *datePickerData) set(tag string, value any) bool {
if date, ok := setTimeValue(DatePickerMax); ok {
if !oldOK || date != old {
if picker.created {
updateProperty(picker.htmlID(), Max, date.Format(dateFormat), picker.session)
picker.session.updateProperty(picker.htmlID(), Max, date.Format(dateFormat))
}
picker.propertyChangedEvent(tag)
}
@ -208,9 +208,9 @@ func (picker *datePickerData) set(tag string, value any) bool {
if step := GetDatePickerStep(picker); oldStep != step {
if picker.created {
if step > 0 {
updateProperty(picker.htmlID(), Step, strconv.Itoa(step), picker.session)
picker.session.updateProperty(picker.htmlID(), Step, strconv.Itoa(step))
} else {
removeProperty(picker.htmlID(), Step, picker.session)
picker.session.removeProperty(picker.htmlID(), Step)
}
}
picker.propertyChangedEvent(tag)

View File

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

View File

@ -129,7 +129,7 @@ func (picker *filePickerData) remove(tag string) {
case Accept:
delete(picker.properties, tag)
if picker.created {
removeProperty(picker.htmlID(), "accept", picker.Session())
picker.session.removeProperty(picker.htmlID(), "accept")
}
picker.propertyChangedEvent(tag)
@ -196,9 +196,9 @@ func (picker *filePickerData) set(tag string, value any) bool {
if picker.created {
if css := picker.acceptCSS(); css != "" {
updateProperty(picker.htmlID(), "accept", css, picker.Session())
picker.session.updateProperty(picker.htmlID(), "accept", css)
} else {
removeProperty(picker.htmlID(), "accept", picker.Session())
picker.session.removeProperty(picker.htmlID(), "accept")
}
}
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 {
view.properties[tag] = listeners
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 {
return false
@ -120,7 +120,7 @@ func (view *viewData) removeFocusListener(tag string) {
delete(view.properties, tag)
if view.created {
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 {
switch tag {
case CellWidth:
updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`,
gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session), gridLayout.session)
gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`,
gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session))
case CellHeight:
updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`,
gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session), gridLayout.session)
gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`,
gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session))
}
}
@ -259,12 +259,12 @@ func (gridLayout *gridLayoutData) set(tag string, value any) bool {
if gridLayout.created {
switch tag {
case CellWidth:
updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`,
gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session), gridLayout.session)
gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-columns`,
gridLayout.gridCellSizesCSS(CellWidth, gridLayout.session))
case CellHeight:
updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`,
gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session), gridLayout.session)
gridLayout.session.updateCSSProperty(gridLayout.htmlID(), `grid-template-rows`,
gridLayout.gridCellSizesCSS(CellHeight, gridLayout.session))
}
}

View File

@ -102,8 +102,8 @@ func (imageView *imageViewData) remove(tag string) {
if imageView.created {
switch tag {
case Source:
updateProperty(imageView.htmlID(), "src", "", imageView.session)
removeProperty(imageView.htmlID(), "srcset", imageView.session)
imageView.session.updateProperty(imageView.htmlID(), "src", "")
imageView.session.removeProperty(imageView.htmlID(), "srcset")
case AltText:
updateInnerHTML(imageView.htmlID(), imageView.session)
@ -133,11 +133,11 @@ func (imageView *imageViewData) set(tag string, value any) bool {
if src != "" && src[0] == '@' {
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 != "" {
updateProperty(imageView.htmlID(), "srcset", srcset, imageView.session)
imageView.session.updateProperty(imageView.htmlID(), "srcset", srcset)
} else {
removeProperty(imageView.htmlID(), "srcset", imageView.session)
imageView.session.removeProperty(imageView.htmlID(), "srcset")
}
}
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 {
view.properties[tag] = listeners
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 {
return false
@ -222,7 +222,7 @@ func (view *viewData) removeKeyListener(tag string) {
delete(view.properties, tag)
if view.created {
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>`)
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) {

View File

@ -463,21 +463,21 @@ func (player *mediaPlayerData) propertyChanged(tag string) {
if player.created {
switch tag {
case Controls, Loop:
value, _ := boolProperty(player, tag, player.Session())
value, _ := boolProperty(player, tag, player.session)
if value {
updateBoolProperty(player.htmlID(), tag, value, player.Session())
player.session.updateBoolProperty(player.htmlID(), tag, value)
} else {
removeProperty(player.htmlID(), tag, player.Session())
player.session.removeProperty(player.htmlID(), tag)
}
case Muted:
value, _ := boolProperty(player, tag, player.Session())
player.Session().runFunc("setMediaMuted", player.htmlID(), value)
value, _ := boolProperty(player, tag, player.session)
player.session.runFunc("setMediaMuted", player.htmlID(), value)
case Preload:
value, _ := enumProperty(player, tag, player.Session(), 0)
value, _ := enumProperty(player, tag, player.session, 0)
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,
EndedEvent, LoadedDataEvent, LoadedMetadataEvent, PauseEvent, PlayEvent, PlayingEvent, ProgressEvent,
@ -490,53 +490,53 @@ func (player *mediaPlayerData) propertyChanged(tag string) {
case []func(MediaPlayer):
if len(value) > 0 {
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
}
}
}
updateProperty(player.htmlID(), tag, "", player.Session())
player.session.updateProperty(player.htmlID(), tag, "")
break
}
}
case TimeUpdateEvent:
if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "ontimeupdate", "playerTimeUpdatedEvent(this)", player.Session())
player.session.updateProperty(player.htmlID(), "ontimeupdate", "playerTimeUpdatedEvent(this)")
} else {
updateProperty(player.htmlID(), "ontimeupdate", "", player.Session())
player.session.updateProperty(player.htmlID(), "ontimeupdate", "")
}
case VolumeChangedEvent:
if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "onvolumechange", "playerVolumeChangedEvent(this)", player.Session())
player.session.updateProperty(player.htmlID(), "onvolumechange", "playerVolumeChangedEvent(this)")
} else {
updateProperty(player.htmlID(), "onvolumechange", "", player.Session())
player.session.updateProperty(player.htmlID(), "onvolumechange", "")
}
case DurationChangedEvent:
if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "ondurationchange", "playerDurationChangedEvent(this)", player.Session())
player.session.updateProperty(player.htmlID(), "ondurationchange", "playerDurationChangedEvent(this)")
} else {
updateProperty(player.htmlID(), "ondurationchange", "", player.Session())
player.session.updateProperty(player.htmlID(), "ondurationchange", "")
}
case RateChangedEvent:
if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "onratechange", "playerRateChangedEvent(this)", player.Session())
player.session.updateProperty(player.htmlID(), "onratechange", "playerRateChangedEvent(this)")
} else {
updateProperty(player.htmlID(), "onratechange", "", player.Session())
player.session.updateProperty(player.htmlID(), "onratechange", "")
}
case PlayerErrorEvent:
if value := player.getRaw(tag); value != nil {
updateProperty(player.htmlID(), "onerror", "playerErrorEvent(this)", player.Session())
player.session.updateProperty(player.htmlID(), "onerror", "playerErrorEvent(this)")
} else {
updateProperty(player.htmlID(), "onerror", "", player.Session())
player.session.updateProperty(player.htmlID(), "onerror", "")
}
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) {
if value := player.getRaw(Source); value != nil {
if sources, ok := value.([]MediaSource); ok && len(sources) > 0 {
session := player.Session()
session := player.session
for _, src := range sources {
if url, ok := session.resolveConstants(src.Url); ok && url != "" {
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) {
player.viewData.htmlProperties(self, buffer)
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.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
buffer.WriteString(` preload="`)
buffer.WriteString(values[value])
@ -667,7 +667,7 @@ func (player *mediaPlayerData) SetCurrentTime(seconds float64) {
}
func (player *mediaPlayerData) getFloatPlayerProperty(tag string) (float64, bool) {
value := player.Session().htmlPropertyValue(player.htmlID(), tag)
value := player.session.htmlPropertyValue(player.htmlID(), tag)
if value != "" {
result, err := strconv.ParseFloat(value, 32)
if err == nil {
@ -718,7 +718,7 @@ func (player *mediaPlayerData) Volume() float64 {
}
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":
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 {
view.properties[tag] = listeners
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 {
return false
@ -179,7 +179,7 @@ func (view *viewData) removeMouseListener(tag string) {
delete(view.properties, tag)
if view.created {
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 {
case NumberPickerType:
if GetNumberPickerType(picker) == NumberSlider {
updateProperty(picker.htmlID(), "type", "range", picker.session)
picker.session.updateProperty(picker.htmlID(), "type", "range")
} else {
updateProperty(picker.htmlID(), "type", "number", picker.session)
picker.session.updateProperty(picker.htmlID(), "type", "number")
}
case NumberPickerMin:
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:
_, 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:
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 {
updateProperty(picker.htmlID(), Step, "any", picker.session)
picker.session.updateProperty(picker.htmlID(), Step, "any")
}
case NumberPickerValue:

View File

@ -108,7 +108,7 @@ func (view *viewData) setPointerListener(tag string, value any) bool {
} else if js, ok := pointerEvents[tag]; ok {
view.properties[tag] = listeners
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 {
return false
@ -120,7 +120,7 @@ func (view *viewData) removePointerListener(tag string) {
delete(view.properties, tag)
if view.created {
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) {
if manager.popups == nil {
manager.popups = []Popup{}
session.runFunc("updateInnerHTML", "ruiPopupLayer", "")
session.updateInnerHTML("ruiPopupLayer", "")
return
}
@ -620,7 +620,7 @@ func (manager *popupManager) updatePopupLayerInnerHTML(session Session) {
for _, popup := range manager.popups {
popup.html(buffer)
}
session.runFunc("updateInnerHTML", "ruiPopupLayer", buffer.String())
session.updateInnerHTML("ruiPopupLayer", buffer.String())
}
func (manager *popupManager) showPopup(popup Popup) {
@ -637,8 +637,8 @@ func (manager *popupManager) showPopup(popup Popup) {
session.runFunc("blurCurrent")
manager.updatePopupLayerInnerHTML(session)
updateCSSProperty("ruiPopupLayer", "visibility", "visible", session)
updateCSSProperty("ruiRoot", "pointer-events", "none", session)
session.updateCSSProperty("ruiPopupLayer", "visibility", "visible")
session.updateCSSProperty("ruiRoot", "pointer-events", "none")
}
func (manager *popupManager) dismissPopup(popup Popup) {
@ -656,9 +656,9 @@ func (manager *popupManager) dismissPopup(popup Popup) {
if manager.popups[count-1] == popup {
if count == 1 {
manager.popups = []Popup{}
updateCSSProperty("ruiRoot", "pointer-events", "auto", session)
updateCSSProperty("ruiPopupLayer", "visibility", "hidden", session)
session.runFunc("updateInnerHTML", "ruiPopupLayer", "")
session.updateCSSProperty("ruiRoot", "pointer-events", "auto")
session.updateCSSProperty("ruiPopupLayer", "visibility", "hidden")
session.updateInnerHTML("ruiPopupLayer", "")
} else {
manager.popups = manager.popups[:count-1]
manager.updatePopupLayerInnerHTML(session)

View File

@ -65,10 +65,12 @@ func (progress *progressBarData) propertyChanged(tag string) {
if progress.created {
switch tag {
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:
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()
column, row := resizable.cellSizeCSS()
updateCSSProperty(htmlID, "grid-template-columns", column, session)
updateCSSProperty(htmlID, "grid-template-rows", row, session)
session.updateCSSProperty(htmlID, "grid-template-columns", column)
session.updateCSSProperty(htmlID, "grid-template-rows", row)
}
}

View File

@ -9,6 +9,11 @@ import (
type webBrige interface {
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)
writeMessage(text string) bool
canvasTextMetrics(htmlID, font, text string) TextMetrics
@ -99,6 +104,12 @@ type Session interface {
setBrige(events chan DataObject, brige webBrige)
writeInitScript(writer *strings.Builder)
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)
canvasTextMetrics(htmlID, font, text string) TextMetrics
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) {
if session.brige != nil {
session.brige.writeMessage(script)

View File

@ -1,7 +1,6 @@
package rui
import (
"fmt"
"strings"
)
@ -60,19 +59,12 @@ func updateInnerHTML(htmlID string, session Session) {
script.Grow(32 * 1024)
view.htmlSubviews(view, script)
session.runFunc("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)
session.updateInnerHTML(view.htmlID(), script.String())
}
}
}
/*
func updateProperty(htmlID, property, value string, session Session) {
if !session.ignoreViewUpdates() {
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) {
if !session.ignoreViewUpdates() {

View File

@ -122,11 +122,11 @@ func (layout *stackLayoutData) set(tag string, value any) bool {
setCurrent := func(index int) {
if index != layout.peek {
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
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)
}
}
@ -204,11 +204,11 @@ func (layout *stackLayoutData) MoveToFront(view View) bool {
if view2.htmlID() == htmlID {
if i != peek {
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
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)
}
return true
@ -225,11 +225,11 @@ func (layout *stackLayoutData) MoveToFrontByID(viewID string) bool {
if view.ID() == viewID {
if i != peek {
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
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)
}
return true
@ -319,8 +319,8 @@ func (layout *stackLayoutData) Push(view View, animation int, onPushFinished fun
viewHTML(layout.pushView, buffer)
buffer.WriteString(`</div>`)
appendToInnerHTML(htmlID, buffer.String(), session)
updateCSSProperty(htmlID+"push", "transform", "translate(0px, 0px)", layout.session)
session.appendToInnerHTML(htmlID, buffer.String())
layout.session.updateCSSProperty(htmlID+"push", "transform", "translate(0px, 0px)")
layout.views = append(layout.views, view)
view.setParentID(htmlID)
@ -357,7 +357,7 @@ func (layout *stackLayoutData) Pop(animation int, onPopFinished func(View)) bool
viewHTML(layout.popView, buffer)
buffer.WriteString(`</div>`)
appendToInnerHTML(htmlID, buffer.String(), session)
session.appendToInnerHTML(htmlID, buffer.String())
var value string
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)
}
updateCSSProperty(htmlID+"pop", "transform", value, layout.session)
layout.session.updateCSSProperty(htmlID+"pop", "transform", value)
return true
}

View File

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

View File

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

View File

@ -125,14 +125,14 @@ func (textView *textViewData) set(tag string, value any) bool {
func (textView *textViewData) textOverflowUpdated() {
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
if n >= 0 && n < len(values) {
updateCSSProperty(textView.htmlID(), TextOverflow, values[n], session)
session.updateCSSProperty(textView.htmlID(), TextOverflow, values[n])
return
}
}
updateCSSProperty(textView.htmlID(), TextOverflow, "", session)
session.updateCSSProperty(textView.htmlID(), TextOverflow, "")
}
func (textView *textViewData) htmlSubviews(self View, buffer *strings.Builder) {

View File

@ -77,19 +77,19 @@ func (picker *timePickerData) remove(tag string) {
case TimePickerMin:
delete(picker.properties, TimePickerMin)
if picker.created {
removeProperty(picker.htmlID(), Min, picker.session)
picker.session.removeProperty(picker.htmlID(), Min)
}
case TimePickerMax:
delete(picker.properties, TimePickerMax)
if picker.created {
removeProperty(picker.htmlID(), Max, picker.session)
picker.session.removeProperty(picker.htmlID(), Max)
}
case TimePickerStep:
delete(picker.properties, TimePickerStep)
if picker.created {
removeProperty(picker.htmlID(), Step, picker.session)
picker.session.removeProperty(picker.htmlID(), Step)
}
case TimePickerValue:
@ -171,7 +171,7 @@ func (picker *timePickerData) set(tag string, value any) bool {
if time, ok := setTimeValue(TimePickerMin); ok {
if !oldOK || time != old {
if picker.created {
updateProperty(picker.htmlID(), Min, time.Format(timeFormat), picker.session)
picker.session.updateProperty(picker.htmlID(), Min, time.Format(timeFormat))
}
picker.propertyChangedEvent(tag)
}
@ -183,7 +183,7 @@ func (picker *timePickerData) set(tag string, value any) bool {
if time, ok := setTimeValue(TimePickerMax); ok {
if !oldOK || time != old {
if picker.created {
updateProperty(picker.htmlID(), Max, time.Format(timeFormat), picker.session)
picker.session.updateProperty(picker.htmlID(), Max, time.Format(timeFormat))
}
picker.propertyChangedEvent(tag)
}
@ -196,9 +196,9 @@ func (picker *timePickerData) set(tag string, value any) bool {
if step := GetTimePickerStep(picker); oldStep != step {
if picker.created {
if step > 0 {
updateProperty(picker.htmlID(), Step, strconv.Itoa(step), picker.session)
picker.session.updateProperty(picker.htmlID(), Step, strconv.Itoa(step))
} else {
removeProperty(picker.htmlID(), Step, picker.session)
picker.session.removeProperty(picker.htmlID(), Step)
}
}
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 {
view.properties[tag] = listeners
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 {
return false
@ -121,7 +121,7 @@ func (view *viewData) removeTouchListener(tag string) {
delete(view.properties, tag)
if view.created {
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:
delete(player.properties, tag)
removeProperty(player.htmlID(), "width", player.Session())
player.session.removeProperty(player.htmlID(), "width")
case VideoHeight:
delete(player.properties, tag)
removeProperty(player.htmlID(), "height", player.Session())
player.session.removeProperty(player.htmlID(), "height")
case Poster:
delete(player.properties, tag)
removeProperty(player.htmlID(), Poster, player.Session())
player.session.removeProperty(player.htmlID(), Poster)
default:
player.mediaPlayerData.remove(tag)
@ -91,9 +91,9 @@ func (player *videoPlayerData) set(tag string, value any) bool {
updateSize := func(cssTag string) {
if size, ok := floatTextProperty(player, tag, session, 0); ok {
if size != "0" {
updateProperty(player.htmlID(), cssTag, size, session)
session.updateProperty(player.htmlID(), cssTag, size)
} 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:
if url, ok := stringProperty(player, Poster, session); ok {
updateProperty(player.htmlID(), Poster, url, session)
session.updateProperty(player.htmlID(), Poster, url)
}
}
return true

120
view.go
View File

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

View File

@ -250,15 +250,15 @@ func (view *viewData) updateTransformProperty(tag string) bool {
if x.Type != Auto || y.Type != Auto {
value = x.cssString("50%", session) + " " + y.cssString("50%", session)
}
updateCSSProperty(htmlID, "perspective-origin", value, session)
session.updateCSSProperty(htmlID, "perspective-origin", value)
}
case BackfaceVisible:
if getTransform3D(view, session) {
if GetBackfaceVisible(view) {
updateCSSProperty(htmlID, BackfaceVisible, "visible", session)
session.updateCSSProperty(htmlID, BackfaceVisible, "visible")
} 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)
}
}
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:
updateCSSProperty(htmlID, "transform", view.transform(session), session)
session.updateCSSProperty(htmlID, "transform", view.transform(session))
default:
return false

View File

@ -134,6 +134,26 @@ func (brige *wsBrige) runFunc(funcName string, args ...any) bool {
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) {
_, p, err := brige.conn.ReadMessage()
if err != nil {