mirror of https://github.com/anoshenko/rui.git
Fixed "background" property
This commit is contained in:
parent
0740a48346
commit
856b09b04b
|
@ -1,6 +1,9 @@
|
||||||
package rui
|
package rui
|
||||||
|
|
||||||
import "strings"
|
import (
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// NoRepeat is value of the Repeat property of an background image:
|
// NoRepeat is value of the Repeat property of an background image:
|
||||||
|
@ -61,6 +64,8 @@ const (
|
||||||
// BackgroundElement describes the background element.
|
// BackgroundElement describes the background element.
|
||||||
type BackgroundElement interface {
|
type BackgroundElement interface {
|
||||||
Properties
|
Properties
|
||||||
|
fmt.Stringer
|
||||||
|
stringWriter
|
||||||
cssStyle(session Session) string
|
cssStyle(session Session) string
|
||||||
Tag() string
|
Tag() string
|
||||||
Clone() BackgroundElement
|
Clone() BackgroundElement
|
||||||
|
@ -239,3 +244,23 @@ func (image *backgroundImage) cssStyle(session Session) string {
|
||||||
|
|
||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (image *backgroundImage) writeString(buffer *strings.Builder, indent string) {
|
||||||
|
image.writeToBuffer(buffer, indent, image.Tag(), []string{
|
||||||
|
Source,
|
||||||
|
Width,
|
||||||
|
Height,
|
||||||
|
ImageHorizontalAlign,
|
||||||
|
ImageVerticalAlign,
|
||||||
|
backgroundFit,
|
||||||
|
Repeat,
|
||||||
|
Attachment,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (image *backgroundImage) String() string {
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
image.writeString(buffer, "")
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
|
@ -336,3 +336,19 @@ func (gradient *backgroundConicGradient) cssStyle(session Session) string {
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gradient *backgroundConicGradient) writeString(buffer *strings.Builder, indent string) {
|
||||||
|
gradient.writeToBuffer(buffer, indent, gradient.Tag(), []string{
|
||||||
|
Gradient,
|
||||||
|
CenterX,
|
||||||
|
CenterY,
|
||||||
|
Repeating,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gradient *backgroundConicGradient) String() string {
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
gradient.writeString(buffer, "")
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
|
@ -224,6 +224,33 @@ func (point *BackgroundGradientPoint) color(session Session) (Color, bool) {
|
||||||
return 0, false
|
return 0, false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (point *BackgroundGradientPoint) String() string {
|
||||||
|
result := "black"
|
||||||
|
if point.Color != nil {
|
||||||
|
switch color := point.Color.(type) {
|
||||||
|
case string:
|
||||||
|
result = color
|
||||||
|
|
||||||
|
case Color:
|
||||||
|
result = color.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if point.Pos != nil {
|
||||||
|
switch value := point.Pos.(type) {
|
||||||
|
case string:
|
||||||
|
result += " " + value
|
||||||
|
|
||||||
|
case SizeUnit:
|
||||||
|
if value.Type != Auto {
|
||||||
|
result += " " + value.String()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
func (gradient *backgroundGradient) writeGradient(session Session, buffer *strings.Builder) bool {
|
func (gradient *backgroundGradient) writeGradient(session Session, buffer *strings.Builder) bool {
|
||||||
|
|
||||||
value, ok := gradient.properties[Gradient]
|
value, ok := gradient.properties[Gradient]
|
||||||
|
@ -370,6 +397,21 @@ func (gradient *backgroundLinearGradient) cssStyle(session Session) string {
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (gradient *backgroundLinearGradient) writeString(buffer *strings.Builder, indent string) {
|
||||||
|
gradient.writeToBuffer(buffer, indent, gradient.Tag(), []string{
|
||||||
|
Gradient,
|
||||||
|
Repeating,
|
||||||
|
Direction,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gradient *backgroundLinearGradient) String() string {
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
gradient.writeString(buffer, "")
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
||||||
func (gradient *backgroundRadialGradient) Tag() string {
|
func (gradient *backgroundRadialGradient) Tag() string {
|
||||||
return "radial-gradient"
|
return "radial-gradient"
|
||||||
}
|
}
|
||||||
|
@ -610,3 +652,20 @@ func (gradient *backgroundRadialGradient) cssStyle(session Session) string {
|
||||||
|
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
func (gradient *backgroundRadialGradient) writeString(buffer *strings.Builder, indent string) {
|
||||||
|
gradient.writeToBuffer(buffer, indent, gradient.Tag(), []string{
|
||||||
|
Gradient,
|
||||||
|
CenterX,
|
||||||
|
CenterY,
|
||||||
|
Repeating,
|
||||||
|
RadialGradientShape,
|
||||||
|
RadialGradientRadius,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
func (gradient *backgroundRadialGradient) String() string {
|
||||||
|
buffer := allocStringBuilder()
|
||||||
|
defer freeStringBuilder(buffer)
|
||||||
|
gradient.writeString(buffer, "")
|
||||||
|
return buffer.String()
|
||||||
|
}
|
||||||
|
|
|
@ -68,6 +68,28 @@ func (properties *propertyList) AllTags() []string {
|
||||||
return tags
|
return tags
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (properties *propertyList) writeToBuffer(buffer *strings.Builder,
|
||||||
|
indent string, objectTag string, tags []string) {
|
||||||
|
|
||||||
|
buffer.WriteString(objectTag)
|
||||||
|
buffer.WriteString(" {\n")
|
||||||
|
|
||||||
|
indent2 := indent + "\t"
|
||||||
|
|
||||||
|
for _, tag := range tags {
|
||||||
|
if value, ok := properties.properties[tag]; ok {
|
||||||
|
buffer.WriteString(indent2)
|
||||||
|
buffer.WriteString(tag)
|
||||||
|
buffer.WriteString(" = ")
|
||||||
|
writePropertyValue(buffer, tag, value, indent2)
|
||||||
|
buffer.WriteString(",\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.WriteString(indent)
|
||||||
|
buffer.WriteString("}")
|
||||||
|
}
|
||||||
|
|
||||||
func parseProperties(properties Properties, object DataObject) {
|
func parseProperties(properties Properties, object DataObject) {
|
||||||
count := object.PropertyCount()
|
count := object.PropertyCount()
|
||||||
for i := 0; i < count; i++ {
|
for i := 0; i < count; i++ {
|
||||||
|
|
46
viewStyle.go
46
viewStyle.go
|
@ -573,6 +573,9 @@ func supportedPropertyValue(value any) bool {
|
||||||
case []ViewShadow:
|
case []ViewShadow:
|
||||||
case []View:
|
case []View:
|
||||||
case []any:
|
case []any:
|
||||||
|
case []BackgroundElement:
|
||||||
|
case []BackgroundGradientPoint:
|
||||||
|
case []BackgroundGradientAngle:
|
||||||
case map[string]Animation:
|
case map[string]Animation:
|
||||||
default:
|
default:
|
||||||
return false
|
return false
|
||||||
|
@ -701,7 +704,7 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s
|
||||||
case []View:
|
case []View:
|
||||||
switch len(value) {
|
switch len(value) {
|
||||||
case 0:
|
case 0:
|
||||||
buffer.WriteString("[]\n")
|
buffer.WriteString("[]")
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
writeViewStyle(value[0].Tag(), value[0], buffer, indent)
|
writeViewStyle(value[0].Tag(), value[0], buffer, indent)
|
||||||
|
@ -740,6 +743,47 @@ func writePropertyValue(buffer *strings.Builder, tag string, value any, indent s
|
||||||
buffer.WriteString(" ]")
|
buffer.WriteString(" ]")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case []BackgroundElement:
|
||||||
|
switch len(value) {
|
||||||
|
case 0:
|
||||||
|
buffer.WriteString("[]\n")
|
||||||
|
|
||||||
|
case 1:
|
||||||
|
value[0].writeString(buffer, indent)
|
||||||
|
|
||||||
|
default:
|
||||||
|
buffer.WriteString("[\n")
|
||||||
|
indent2 := indent + "\t"
|
||||||
|
for _, element := range value {
|
||||||
|
buffer.WriteString(indent2)
|
||||||
|
element.writeString(buffer, indent2)
|
||||||
|
buffer.WriteString(",\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.WriteString(indent)
|
||||||
|
buffer.WriteRune(']')
|
||||||
|
}
|
||||||
|
|
||||||
|
case []BackgroundGradientPoint:
|
||||||
|
buffer.WriteRune('"')
|
||||||
|
for i, point := range value {
|
||||||
|
if i > 0 {
|
||||||
|
buffer.WriteString(",")
|
||||||
|
}
|
||||||
|
buffer.WriteString(point.String())
|
||||||
|
}
|
||||||
|
buffer.WriteRune('"')
|
||||||
|
|
||||||
|
case []BackgroundGradientAngle:
|
||||||
|
buffer.WriteRune('"')
|
||||||
|
for i, point := range value {
|
||||||
|
if i > 0 {
|
||||||
|
buffer.WriteString(",")
|
||||||
|
}
|
||||||
|
buffer.WriteString(point.String())
|
||||||
|
}
|
||||||
|
buffer.WriteRune('"')
|
||||||
|
|
||||||
case map[string]Animation:
|
case map[string]Animation:
|
||||||
switch count := len(value); count {
|
switch count := len(value); count {
|
||||||
case 0:
|
case 0:
|
||||||
|
|
|
@ -32,42 +32,52 @@ func (style *viewStyle) setRange(tag string, value any) bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (style *viewStyle) setBackground(value any) bool {
|
func (style *viewStyle) setBackground(value any) bool {
|
||||||
|
background := []BackgroundElement{}
|
||||||
|
|
||||||
switch value := value.(type) {
|
switch value := value.(type) {
|
||||||
case BackgroundElement:
|
case BackgroundElement:
|
||||||
style.properties[Background] = []BackgroundElement{value}
|
background = []BackgroundElement{value}
|
||||||
return true
|
|
||||||
|
|
||||||
case []BackgroundElement:
|
case []BackgroundElement:
|
||||||
style.properties[Background] = value
|
background = value
|
||||||
return true
|
|
||||||
|
case []DataValue:
|
||||||
|
for _, el := range value {
|
||||||
|
if el.IsObject() {
|
||||||
|
if element := createBackground(el.Object()); element != nil {
|
||||||
|
background = append(background, element)
|
||||||
|
}
|
||||||
|
} else if obj := ParseDataText(el.Value()); obj != nil {
|
||||||
|
if element := createBackground(obj); element != nil {
|
||||||
|
background = append(background, element)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case DataObject:
|
case DataObject:
|
||||||
if element := createBackground(value); element != nil {
|
if element := createBackground(value); element != nil {
|
||||||
style.properties[Background] = []BackgroundElement{element}
|
background = []BackgroundElement{element}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case []DataObject:
|
case []DataObject:
|
||||||
for _, obj := range value {
|
for _, obj := range value {
|
||||||
background := []BackgroundElement{}
|
|
||||||
if element := createBackground(obj); element != nil {
|
if element := createBackground(obj); element != nil {
|
||||||
background = append(background, element)
|
background = append(background, element)
|
||||||
}
|
}
|
||||||
if len(background) > 0 {
|
|
||||||
style.properties[Background] = background
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
case string:
|
case string:
|
||||||
if obj := ParseDataText(value); obj != nil {
|
if obj := ParseDataText(value); obj != nil {
|
||||||
if element := createBackground(obj); element != nil {
|
if element := createBackground(obj); element != nil {
|
||||||
style.properties[Background] = []BackgroundElement{element}
|
background = []BackgroundElement{element}
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(background) > 0 {
|
||||||
|
style.properties[Background] = background
|
||||||
|
return true
|
||||||
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue