Optimisation

This commit is contained in:
Alexei Anoshenko 2025-08-06 19:31:17 +03:00
parent 049a2b365f
commit 942d7c45d3
10 changed files with 44 additions and 35 deletions

View File

@ -926,7 +926,7 @@ func (session *sessionData) registerAnimation(props []AnimatedProperty) string {
}
cssBuilder.startAnimationFrame("from")
NewViewStyle(fromParams).cssViewStyle(&cssBuilder, session)
writeViewStyleCSS(NewViewStyle(fromParams), &cssBuilder, session)
cssBuilder.endAnimationFrame()
if len(frames) > 0 {
@ -942,14 +942,14 @@ func (session *sessionData) registerAnimation(props []AnimatedProperty) string {
if len(params) > 0 {
cssBuilder.startAnimationFrame(strconv.Itoa(frame) + "%")
NewViewStyle(params).cssViewStyle(&cssBuilder, session)
writeViewStyleCSS(NewViewStyle(params), &cssBuilder, session)
cssBuilder.endAnimationFrame()
}
}
}
cssBuilder.startAnimationFrame("to")
NewViewStyle(toParams).cssViewStyle(&cssBuilder, session)
writeViewStyleCSS(NewViewStyle(toParams), &cssBuilder, session)
cssBuilder.endAnimationFrame()
cssBuilder.endAnimation()

View File

@ -1,5 +1,7 @@
package rui
import "strings"
// Button represent a Button view
type Button interface {
ListLayout
@ -35,6 +37,15 @@ func (button *buttonData) Focusable() bool {
return true
}
func (button *buttonData) htmlSubviews(self View, buffer *strings.Builder) {
if button.views != nil {
for _, view := range button.views {
view.addToCSSStyle(map[string]string{`flex`: `0 0 auto`})
viewHTML(view, buffer, "")
}
}
}
// GetButtonVerticalAlign returns the vertical align of a Button subview:
// TopAlign (0), BottomAlign (1), CenterAlign (2), or StretchAlign (3)
//

View File

@ -128,10 +128,6 @@ func (customView *CustomViewData) Clear() {
customView.superView.Clear()
}
func (customView *CustomViewData) cssViewStyle(buffer cssBuilder, session Session) {
customView.superView.cssViewStyle(buffer, session)
}
// Session returns a current Session interface
func (customView *CustomViewData) Session() Session {
return customView.superView.Session()

View File

@ -802,21 +802,7 @@ func (listView *listViewData) cssStyle(self View, builder cssBuilder) {
}
*/
func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
adapter := listView.getAdapter()
if adapter == nil {
return
}
if listSize := adapter.ListSize(); listSize == 0 {
return
}
if !listView.session.ignoreViewUpdates() {
listView.session.setIgnoreViewUpdates(true)
defer listView.session.setIgnoreViewUpdates(false)
}
func listDiv(listView View, buffer *strings.Builder) {
buffer.WriteString(`<div style="display: flex; align-content: stretch;`)
if gap := GetListRowGap(listView); gap.Type != Auto {
@ -939,6 +925,24 @@ func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
}
buffer.WriteString(`">`)
}
func (listView *listViewData) htmlSubviews(self View, buffer *strings.Builder) {
adapter := listView.getAdapter()
if adapter == nil {
return
}
if listSize := adapter.ListSize(); listSize == 0 {
return
}
if !listView.session.ignoreViewUpdates() {
listView.session.setIgnoreViewUpdates(true)
defer listView.session.setIgnoreViewUpdates(false)
}
listDiv(listView, buffer)
checkbox := GetListViewCheckbox(listView)
if checkbox == NoneCheckbox {

View File

@ -1616,7 +1616,7 @@ func tableViewCurrent(view View) CellIndex {
func (table *tableViewData) cssStyle(self View, builder cssBuilder) {
session := table.Session()
table.viewData.cssViewStyle(builder, session)
writeViewStyleCSS(table, builder, session)
gap, ok := sizeProperty(table, Gap, session)
if !ok || gap.Type == Auto || gap.Value <= 0 {

View File

@ -18,7 +18,7 @@ func (cell *tableCellView) init(session Session) {
func (cell *tableCellView) cssStyle(self View, builder cssBuilder) {
session := cell.Session()
cell.viewData.cssViewStyle(builder, session)
writeViewStyleCSS(cell, builder, session)
if value, ok := enumProperty(cell, TableVerticalAlign, session, 0); ok {
builder.add("vertical-align", enumProperties[TableVerticalAlign].values[value])

View File

@ -661,7 +661,7 @@ func (theme *theme) cssText(session Session) string {
for _, tag := range styleList(theme.styles) {
if style := theme.styles[tag]; style != nil {
builder.startStyle(tag)
style.cssViewStyle(&builder, session)
writeViewStyleCSS(style, &builder, session)
builder.endStyle()
}
}
@ -671,7 +671,7 @@ func (theme *theme) cssText(session Session) string {
for _, tag := range styleList(media.styles) {
if style := media.styles[tag]; style != nil {
builder.startStyle(tag)
style.cssViewStyle(&builder, session)
writeViewStyleCSS(style, &builder, session)
builder.endStyle()
}
}

View File

@ -556,7 +556,7 @@ func (transform *transformPropertyData) transformCSS(session Session) string {
return result[:length-1]
}
func (style *viewStyle) writeViewTransformCSS(builder cssBuilder, session Session) {
func writeViewTransformCSS(style Properties, builder cssBuilder, session Session) {
x, y := getPerspectiveOrigin(style, session)
z := AutoSize()
if css := transformOriginCSS(x, y, z, session); css != "" {

View File

@ -1094,7 +1094,7 @@ func (view *viewData) addToCSSStyle(addCSS map[string]string) {
}
func (view *viewData) cssStyle(self View, builder cssBuilder) {
view.viewStyle.cssViewStyle(builder, view.session)
writeViewStyleCSS(view, builder, view.session)
if view.addCSS != nil {
for tag, value := range view.addCSS {
builder.add(tag, value)

View File

@ -22,8 +22,6 @@ type ViewStyle interface {
// removes the transition animation of the property if "animation" argument is nil.
// The "tag" argument is the property name.
SetTransition(tag PropertyName, animation AnimationProperty)
cssViewStyle(buffer cssBuilder, session Session)
}
type viewStyle struct {
@ -109,7 +107,7 @@ func split4Values(text string) []string {
return []string{}
}
func (style *viewStyle) cssListStyle(builder cssBuilder, session Session) {
func writeListStyleCSS(style Properties, builder cssBuilder, session Session) {
wrap, _ := enumProperty(style, ListWrap, session, 0)
orientation, ok := valueToOrientation(style.Get(Orientation), session)
if ok || wrap > 0 {
@ -189,7 +187,7 @@ func (style *viewStyle) cssListStyle(builder cssBuilder, session Session) {
}
func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) {
func writeViewStyleCSS(style Properties, builder cssBuilder, session Session) {
if visibility, ok := enumProperty(style, Visibility, session, Visible); ok {
switch visibility {
@ -355,7 +353,7 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) {
builder.add("text-shadow", css)
}
if value, ok := style.properties[ColumnSeparator]; ok {
if value := style.getRaw(ColumnSeparator); value != nil {
if separator, ok := value.(ColumnSeparatorProperty); ok {
if css := separator.cssValue(session); css != "" {
builder.add("column-rule", css)
@ -371,7 +369,7 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) {
}
}
style.cssListStyle(builder, session)
writeListStyleCSS(style, builder, session)
if r, ok := rangeProperty(style, Row, session); ok {
builder.add("grid-row", fmt.Sprintf("%d / %d", r.First+1, r.Last+2))
@ -386,7 +384,7 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) {
builder.add(`grid-template-rows`, text)
}
style.writeViewTransformCSS(builder, session)
writeViewTransformCSS(style, builder, session)
if clip := getClipShapeProperty(style, Clip, session); clip != nil && clip.valid(session) {
builder.add(`clip-path`, clip.cssStyle(session))