From ed4d2b6ffa8840f7be78cccdad313d9f5ba3ad14 Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko Date: Wed, 7 Sep 2022 15:05:53 +0300 Subject: [PATCH] Added Name and Args function to SizeFunc interface --- sizeFunc.go | 14 ++++++++++++++ viewStyle.go | 5 +++-- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/sizeFunc.go b/sizeFunc.go index cd76fd5..d56b101 100644 --- a/sizeFunc.go +++ b/sizeFunc.go @@ -11,6 +11,10 @@ import ( // "min", "max", "clamp", "sum", "sub", "mul", and "div" functions are available. type SizeFunc interface { fmt.Stringer + // Name() returns the function name: "min", "max", "clamp", "sum", "sub", "mul", or "div" + Name() string + // Args() returns a list of function arguments + Args() []any cssString(session Session) string writeCSS(topFunc string, buffer *strings.Builder, session Session) writeString(topFunc string, buffer *strings.Builder) @@ -159,6 +163,16 @@ func (data *sizeFuncData) String() string { return buffer.String() } +func (data *sizeFuncData) Name() string { + return data.tag +} + +func (data *sizeFuncData) Args() []any { + args := make([]any, len(data.args)) + copy(args, data.args) + return args +} + func (data *sizeFuncData) writeString(topFunc string, buffer *strings.Builder) { buffer.WriteString(data.tag) buffer.WriteRune('(') diff --git a/viewStyle.go b/viewStyle.go index 4adecdc..1abd273 100644 --- a/viewStyle.go +++ b/viewStyle.go @@ -582,7 +582,8 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s } else { for _, ch := range text { if (ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'Z') || (ch >= 'a' && ch <= 'z') || - ch == '+' || ch == '-' || ch == '@' || ch == '/' || ch == '_' || ch == ':' { + ch == '+' || ch == '-' || ch == '@' || ch == '/' || ch == '_' || ch == ':' || + ch == '#' || ch == '%' || ch == 'π' || ch == '°' { } else { simple = false break @@ -667,7 +668,7 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s value.writeString(buffer, indent+"\t") case fmt.Stringer: - buffer.WriteString(value.String()) + writeString(value.String()) case []ViewShadow: switch len(value) {