mirror of https://github.com/anoshenko/rui.git
Optimisation
This commit is contained in:
parent
0433f460e4
commit
bbbaf28aba
18
animation.go
18
animation.go
|
@ -2,6 +2,7 @@ package rui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"math"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
@ -661,7 +662,7 @@ func (animation *animationData) animationCSS(session Session) string {
|
|||
buffer.WriteString(animation.keyFramesName)
|
||||
|
||||
if duration, ok := floatProperty(animation, Duration, session, 1); ok && duration > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(" %gs ", duration))
|
||||
fmt.Fprintf(buffer, " %gs ", duration)
|
||||
} else {
|
||||
buffer.WriteString(" 1s ")
|
||||
}
|
||||
|
@ -669,7 +670,7 @@ func (animation *animationData) animationCSS(session Session) string {
|
|||
buffer.WriteString(timingFunctionCSS(animation, TimingFunction, session))
|
||||
|
||||
if delay, ok := floatProperty(animation, Delay, session, 0); ok && delay > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(" %gs", delay))
|
||||
fmt.Fprintf(buffer, " %gs", delay)
|
||||
} else {
|
||||
buffer.WriteString(" 0s")
|
||||
}
|
||||
|
@ -678,7 +679,7 @@ func (animation *animationData) animationCSS(session Session) string {
|
|||
if iterationCount == 0 {
|
||||
iterationCount = 1
|
||||
}
|
||||
buffer.WriteString(fmt.Sprintf(" %d ", iterationCount))
|
||||
fmt.Fprintf(buffer, " %d ", iterationCount)
|
||||
} else {
|
||||
buffer.WriteString(" infinite ")
|
||||
}
|
||||
|
@ -699,7 +700,7 @@ func (animation *animationData) animationCSS(session Session) string {
|
|||
func (animation *animationData) transitionCSS(buffer *strings.Builder, session Session) {
|
||||
|
||||
if duration, ok := floatProperty(animation, Duration, session, 1); ok && duration > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(" %gs ", duration))
|
||||
fmt.Fprintf(buffer, " %gs ", duration)
|
||||
} else {
|
||||
buffer.WriteString(" 1s ")
|
||||
}
|
||||
|
@ -707,7 +708,7 @@ func (animation *animationData) transitionCSS(buffer *strings.Builder, session S
|
|||
buffer.WriteString(timingFunctionCSS(animation, TimingFunction, session))
|
||||
|
||||
if delay, ok := floatProperty(animation, Delay, session, 0); ok && delay > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(" %gs", delay))
|
||||
fmt.Fprintf(buffer, " %gs", delay)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -979,11 +980,10 @@ func (style *viewStyle) Transition(tag PropertyName) AnimationProperty {
|
|||
}
|
||||
|
||||
func (style *viewStyle) Transitions() map[PropertyName]AnimationProperty {
|
||||
result := map[PropertyName]AnimationProperty{}
|
||||
for tag, animation := range getTransitionProperty(style) {
|
||||
result[tag] = animation
|
||||
if transitions := getTransitionProperty(style); transitions != nil {
|
||||
return maps.Clone(transitions)
|
||||
}
|
||||
return result
|
||||
return map[PropertyName]AnimationProperty{}
|
||||
}
|
||||
|
||||
func (style *viewStyle) SetTransition(tag PropertyName, animation AnimationProperty) {
|
||||
|
|
|
@ -575,7 +575,7 @@ func (canvas *canvasData) SetLineDash(dash []float64, offset float64) {
|
|||
for _, val := range dash {
|
||||
buffer.WriteRune(lead)
|
||||
lead = ','
|
||||
buffer.WriteString(fmt.Sprintf("%g", val))
|
||||
fmt.Fprintf(buffer, "%g", val))
|
||||
}
|
||||
buffer.WriteRune(']')
|
||||
|
||||
|
|
16
data.go
16
data.go
|
@ -1,6 +1,7 @@
|
|||
package rui
|
||||
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
"unicode"
|
||||
)
|
||||
|
@ -321,8 +322,8 @@ func (node *dataNode) ArrayAsParams() []Params {
|
|||
func ParseDataText(text string) DataObject {
|
||||
|
||||
if strings.ContainsAny(text, "\r") {
|
||||
text = strings.Replace(text, "\r\n", "\n", -1)
|
||||
text = strings.Replace(text, "\r", "\n", -1)
|
||||
text = strings.ReplaceAll(text, "\r\n", "\n")
|
||||
text = strings.ReplaceAll(text, "\r", "\n")
|
||||
}
|
||||
data := append([]rune(text), rune(0))
|
||||
pos := 0
|
||||
|
@ -518,15 +519,8 @@ func ParseDataText(text string) DataObject {
|
|||
}
|
||||
|
||||
stopSymbol := func(symbol rune) bool {
|
||||
if unicode.IsSpace(symbol) {
|
||||
return true
|
||||
}
|
||||
for _, sym := range []rune{'=', '{', '}', '[', ']', ',', ' ', '\t', '\n', '\'', '"', '`', '/'} {
|
||||
if sym == symbol {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return unicode.IsSpace(symbol) ||
|
||||
slices.Contains([]rune{'=', '{', '}', '[', ']', ',', ' ', '\t', '\n', '\'', '"', '`', '/'}, symbol)
|
||||
}
|
||||
|
||||
for pos < size && !stopSymbol(data[pos]) {
|
||||
|
|
|
@ -462,13 +462,13 @@ func dragAndDropHtml(view View, buffer *strings.Builder) {
|
|||
|
||||
if f := GetDragImageXOffset(view); f != 0 {
|
||||
buffer.WriteString(` data-drag-image-x="`)
|
||||
buffer.WriteString(fmt.Sprintf("%g", f))
|
||||
fmt.Fprintf(buffer, "%g", f)
|
||||
buffer.WriteString(`" `)
|
||||
}
|
||||
|
||||
if f := GetDragImageYOffset(view); f != 0 {
|
||||
buffer.WriteString(` data-drag-image-y="`)
|
||||
buffer.WriteString(fmt.Sprintf("%g", f))
|
||||
fmt.Fprintf(buffer, "%g", f)
|
||||
buffer.WriteString(`" `)
|
||||
}
|
||||
|
||||
|
|
|
@ -205,7 +205,7 @@ func imageViewSrcSet(view View, path string) string {
|
|||
buffer.WriteString(", ")
|
||||
}
|
||||
buffer.WriteString(src.path)
|
||||
buffer.WriteString(fmt.Sprintf(" %gx", src.scale))
|
||||
fmt.Fprintf(buffer, " %gx", src.scale)
|
||||
}
|
||||
return buffer.String()
|
||||
}
|
||||
|
|
|
@ -244,27 +244,27 @@ func (picker *numberPickerData) htmlProperties(self View, buffer *strings.Builde
|
|||
min, max := GetNumberPickerMinMax(picker)
|
||||
if min != math.Inf(-1) {
|
||||
buffer.WriteString(` min="`)
|
||||
buffer.WriteString(fmt.Sprintf(format, min))
|
||||
fmt.Fprintf(buffer, format, min)
|
||||
buffer.WriteByte('"')
|
||||
}
|
||||
|
||||
if max != math.Inf(1) {
|
||||
buffer.WriteString(` max="`)
|
||||
buffer.WriteString(fmt.Sprintf(format, max))
|
||||
fmt.Fprintf(buffer, format, max)
|
||||
buffer.WriteByte('"')
|
||||
}
|
||||
|
||||
step := GetNumberPickerStep(picker)
|
||||
if step != 0 {
|
||||
buffer.WriteString(` step="`)
|
||||
buffer.WriteString(fmt.Sprintf(format, step))
|
||||
fmt.Fprintf(buffer, format, step)
|
||||
buffer.WriteByte('"')
|
||||
} else {
|
||||
buffer.WriteString(` step="any"`)
|
||||
}
|
||||
|
||||
buffer.WriteString(` value="`)
|
||||
buffer.WriteString(fmt.Sprintf(format, GetNumberPickerValue(picker)))
|
||||
fmt.Fprintf(buffer, format, GetNumberPickerValue(picker))
|
||||
buffer.WriteByte('"')
|
||||
|
||||
buffer.WriteString(` oninput="editViewInputEvent(this)"`)
|
||||
|
|
|
@ -354,7 +354,7 @@ func (resizable *resizableData) htmlSubviews(self View, buffer *strings.Builder)
|
|||
}
|
||||
|
||||
writePos := func(x1, x2, y1, y2 int) {
|
||||
buffer.WriteString(fmt.Sprintf(` grid-column-start: %d; grid-column-end: %d; grid-row-start: %d; grid-row-end: %d;"></div>`, x1, x2, y1, y2))
|
||||
fmt.Fprintf(buffer, ` grid-column-start: %d; grid-column-end: %d; grid-row-start: %d; grid-row-end: %d;"></div>`, x1, x2, y1, y2)
|
||||
}
|
||||
//htmlID := resizable.htmlID()
|
||||
|
||||
|
|
|
@ -208,7 +208,7 @@ func (data *sizeFuncData) writeString(topFunc string, buffer *strings.Builder) {
|
|||
buffer.WriteString(arg.String())
|
||||
|
||||
case float64:
|
||||
buffer.WriteString(fmt.Sprintf("%g", arg))
|
||||
fmt.Fprintf(buffer, "%g", arg)
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -302,7 +302,7 @@ func (data *sizeFuncData) writeCSS(topFunc string, buffer *strings.Builder, sess
|
|||
buffer.WriteString(arg.String())
|
||||
|
||||
case float64:
|
||||
buffer.WriteString(fmt.Sprintf("%g", arg))
|
||||
fmt.Fprintf(buffer, "%g", arg)
|
||||
}
|
||||
|
||||
}
|
||||
|
|
12
tableView.go
12
tableView.go
|
@ -1270,10 +1270,10 @@ func (table *tableViewData) htmlSubviews(self View, buffer *strings.Builder) {
|
|||
buffer.WriteString(string(value))
|
||||
|
||||
case float32:
|
||||
buffer.WriteString(fmt.Sprintf("%g", float64(value)))
|
||||
fmt.Fprintf(buffer, "%g", float64(value))
|
||||
|
||||
case float64:
|
||||
buffer.WriteString(fmt.Sprintf("%g", value))
|
||||
fmt.Fprintf(buffer, "%g", value)
|
||||
|
||||
case bool:
|
||||
if value {
|
||||
|
@ -1284,7 +1284,7 @@ func (table *tableViewData) htmlSubviews(self View, buffer *strings.Builder) {
|
|||
|
||||
default:
|
||||
if n, ok := isInt(value); ok {
|
||||
buffer.WriteString(fmt.Sprintf("%d", n))
|
||||
fmt.Fprintf(buffer, "%d", n)
|
||||
} else {
|
||||
buffer.WriteString("<Unsupported value>")
|
||||
}
|
||||
|
@ -1537,10 +1537,10 @@ func (table *tableViewData) writeCellHtml(adapter TableAdapter, row, column int,
|
|||
buffer.WriteString(string(value))
|
||||
|
||||
case float32:
|
||||
buffer.WriteString(fmt.Sprintf("%g", float64(value)))
|
||||
fmt.Fprintf(buffer, "%g", float64(value))
|
||||
|
||||
case float64:
|
||||
buffer.WriteString(fmt.Sprintf("%g", value))
|
||||
fmt.Fprintf(buffer, "%g", value)
|
||||
|
||||
case bool:
|
||||
accentColor := Color(0)
|
||||
|
@ -1555,7 +1555,7 @@ func (table *tableViewData) writeCellHtml(adapter TableAdapter, row, column int,
|
|||
|
||||
default:
|
||||
if n, ok := isInt(value); ok {
|
||||
buffer.WriteString(fmt.Sprintf("%d", n))
|
||||
fmt.Fprintf(buffer, "%d", n)
|
||||
} else {
|
||||
buffer.WriteString("<Unsupported value>")
|
||||
}
|
||||
|
|
12
theme.go
12
theme.go
|
@ -975,10 +975,10 @@ func (theme *theme) String() string {
|
|||
buffer.WriteString(":landscape")
|
||||
}
|
||||
if maxWidth > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(":width%d", maxWidth))
|
||||
fmt.Fprintf(buffer, ":width%d", maxWidth)
|
||||
}
|
||||
if maxHeight > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(":height%d", maxHeight))
|
||||
fmt.Fprintf(buffer, ":height%d", maxHeight)
|
||||
}
|
||||
buffer.WriteString(" = [\n")
|
||||
|
||||
|
@ -1014,21 +1014,21 @@ func (theme *theme) String() string {
|
|||
}
|
||||
|
||||
if media.MinWidth > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(":width%d-", media.MinWidth))
|
||||
fmt.Fprintf(buffer, ":width%d-", media.MinWidth)
|
||||
if media.MaxWidth > 0 {
|
||||
buffer.WriteString(strconv.Itoa(media.MaxWidth))
|
||||
}
|
||||
} else if media.MaxWidth > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(":width%d", media.MaxWidth))
|
||||
fmt.Fprintf(buffer, ":width%d", media.MaxWidth)
|
||||
}
|
||||
|
||||
if media.MinHeight > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(":height%d-", media.MinHeight))
|
||||
fmt.Fprintf(buffer, ":height%d-", media.MinHeight)
|
||||
if media.MaxHeight > 0 {
|
||||
buffer.WriteString(strconv.Itoa(media.MaxHeight))
|
||||
}
|
||||
} else if media.MaxHeight > 0 {
|
||||
buffer.WriteString(fmt.Sprintf(":height%d", media.MaxHeight))
|
||||
fmt.Fprintf(buffer, ":height%d", media.MaxHeight)
|
||||
}
|
||||
|
||||
buffer.WriteString(" = [\n")
|
||||
|
|
4
view.go
4
view.go
|
@ -1066,8 +1066,8 @@ func (view *viewData) htmlProperties(self View, buffer *strings.Builder) {
|
|||
}
|
||||
|
||||
if view.frame.Left != 0 || view.frame.Top != 0 || view.frame.Width != 0 || view.frame.Height != 0 {
|
||||
buffer.WriteString(fmt.Sprintf(` data-left="%g" data-top="%g" data-width="%g" data-height="%g"`,
|
||||
view.frame.Left, view.frame.Top, view.frame.Width, view.frame.Height))
|
||||
fmt.Fprintf(buffer, ` data-left="%g" data-top="%g" data-width="%g" data-height="%g"`,
|
||||
view.frame.Left, view.frame.Top, view.frame.Width, view.frame.Height)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -190,7 +190,7 @@ func (bridge *webBridge) argToString(arg any) (string, bool) {
|
|||
for _, val := range arg {
|
||||
buffer.WriteRune(lead)
|
||||
lead = ','
|
||||
buffer.WriteString(fmt.Sprintf("%g", val))
|
||||
fmt.Fprintf(buffer, "%g", val)
|
||||
}
|
||||
buffer.WriteRune(']')
|
||||
return buffer.String(), true
|
||||
|
|
Loading…
Reference in New Issue