2021-09-07 17:36:50 +03:00
|
|
|
package rui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
// ColumnSeparatorProperty is the interface of a view separator data
|
|
|
|
type ColumnSeparatorProperty interface {
|
|
|
|
Properties
|
|
|
|
fmt.Stringer
|
2022-05-22 12:54:02 +03:00
|
|
|
stringWriter
|
2021-09-07 17:36:50 +03:00
|
|
|
ViewBorder(session Session) ViewBorder
|
|
|
|
cssValue(session Session) string
|
|
|
|
}
|
|
|
|
|
|
|
|
type columnSeparatorProperty struct {
|
|
|
|
propertyList
|
|
|
|
}
|
|
|
|
|
|
|
|
func newColumnSeparatorProperty(value interface{}) ColumnSeparatorProperty {
|
|
|
|
|
|
|
|
if value == nil {
|
|
|
|
separator := new(columnSeparatorProperty)
|
|
|
|
separator.properties = map[string]interface{}{}
|
|
|
|
return separator
|
|
|
|
}
|
|
|
|
|
|
|
|
switch value := value.(type) {
|
|
|
|
case ColumnSeparatorProperty:
|
|
|
|
return value
|
|
|
|
|
|
|
|
case DataObject:
|
|
|
|
separator := new(columnSeparatorProperty)
|
|
|
|
separator.properties = map[string]interface{}{}
|
2021-10-04 18:05:57 +03:00
|
|
|
for _, tag := range []string{Style, Width, ColorTag} {
|
2021-09-07 17:36:50 +03:00
|
|
|
if val, ok := value.PropertyValue(tag); ok && val != "" {
|
|
|
|
separator.set(tag, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return separator
|
|
|
|
|
|
|
|
case ViewBorder:
|
|
|
|
separator := new(columnSeparatorProperty)
|
|
|
|
separator.properties = map[string]interface{}{
|
2021-10-04 18:05:57 +03:00
|
|
|
Style: value.Style,
|
|
|
|
Width: value.Width,
|
|
|
|
ColorTag: value.Color,
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
return separator
|
|
|
|
}
|
|
|
|
|
|
|
|
invalidPropertyValue(Border, value)
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewColumnSeparator creates the new ColumnSeparatorProperty
|
|
|
|
func NewColumnSeparator(params Params) ColumnSeparatorProperty {
|
|
|
|
separator := new(columnSeparatorProperty)
|
|
|
|
separator.properties = map[string]interface{}{}
|
|
|
|
if params != nil {
|
2021-10-04 18:05:57 +03:00
|
|
|
for _, tag := range []string{Style, Width, ColorTag} {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value, ok := params[tag]; ok && value != nil {
|
|
|
|
separator.Set(tag, value)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return separator
|
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) normalizeTag(tag string) string {
|
|
|
|
tag = strings.ToLower(tag)
|
|
|
|
switch tag {
|
|
|
|
case ColumnSeparatorStyle, "separator-style":
|
|
|
|
return Style
|
|
|
|
|
|
|
|
case ColumnSeparatorWidth, "separator-width":
|
|
|
|
return Width
|
|
|
|
|
|
|
|
case ColumnSeparatorColor, "separator-color":
|
2021-10-04 18:05:57 +03:00
|
|
|
return ColorTag
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
return tag
|
|
|
|
}
|
|
|
|
|
2022-05-22 12:54:02 +03:00
|
|
|
func (separator *columnSeparatorProperty) writeString(buffer *strings.Builder, indent string) {
|
|
|
|
buffer.WriteString("_{ ")
|
|
|
|
comma := false
|
2021-10-04 18:05:57 +03:00
|
|
|
for _, tag := range []string{Style, Width, ColorTag} {
|
2021-09-07 17:36:50 +03:00
|
|
|
if value, ok := separator.properties[tag]; ok {
|
2022-05-22 12:54:02 +03:00
|
|
|
if comma {
|
|
|
|
buffer.WriteString(", ")
|
|
|
|
}
|
|
|
|
buffer.WriteString(tag)
|
|
|
|
buffer.WriteString(" = ")
|
|
|
|
writePropertyValue(buffer, BorderStyle, value, indent)
|
|
|
|
comma = true
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
}
|
2022-05-22 12:54:02 +03:00
|
|
|
|
|
|
|
buffer.WriteString(" }")
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) String() string {
|
2022-05-22 12:54:02 +03:00
|
|
|
return runStringWriter(separator)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) Remove(tag string) {
|
|
|
|
|
|
|
|
switch tag = separator.normalizeTag(tag); tag {
|
2021-10-04 18:05:57 +03:00
|
|
|
case Style, Width, ColorTag:
|
2021-09-07 17:36:50 +03:00
|
|
|
delete(separator.properties, tag)
|
|
|
|
|
|
|
|
default:
|
|
|
|
ErrorLogF(`"%s" property is not compatible with the ColumnSeparatorProperty`, tag)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) Set(tag string, value interface{}) bool {
|
|
|
|
tag = separator.normalizeTag(tag)
|
|
|
|
|
|
|
|
if value == nil {
|
|
|
|
separator.remove(tag)
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
switch tag {
|
|
|
|
case Style:
|
|
|
|
return separator.setEnumProperty(Style, value, enumProperties[BorderStyle].values)
|
|
|
|
|
|
|
|
case Width:
|
|
|
|
return separator.setSizeProperty(Width, value)
|
|
|
|
|
2021-10-04 18:05:57 +03:00
|
|
|
case ColorTag:
|
|
|
|
return separator.setColorProperty(ColorTag, value)
|
2021-09-07 17:36:50 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
ErrorLogF(`"%s" property is not compatible with the ColumnSeparatorProperty`, tag)
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) Get(tag string) interface{} {
|
|
|
|
tag = separator.normalizeTag(tag)
|
|
|
|
|
|
|
|
if result, ok := separator.properties[tag]; ok {
|
|
|
|
return result
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) ViewBorder(session Session) ViewBorder {
|
|
|
|
style, _ := valueToEnum(separator.getRaw(Style), BorderStyle, session, NoneLine)
|
|
|
|
width, _ := sizeProperty(separator, Width, session)
|
2021-10-04 18:05:57 +03:00
|
|
|
color, _ := colorProperty(separator, ColorTag, session)
|
2021-09-07 17:36:50 +03:00
|
|
|
|
|
|
|
return ViewBorder{
|
|
|
|
Style: style,
|
|
|
|
Width: width,
|
|
|
|
Color: color,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (separator *columnSeparatorProperty) cssValue(session Session) string {
|
|
|
|
value := separator.ViewBorder(session)
|
|
|
|
buffer := allocStringBuilder()
|
|
|
|
defer freeStringBuilder(buffer)
|
|
|
|
|
|
|
|
if value.Width.Type != Auto && value.Width.Type != SizeInFraction && value.Width.Value > 0 {
|
|
|
|
buffer.WriteString(value.Width.cssString(""))
|
|
|
|
}
|
|
|
|
|
|
|
|
styles := enumProperties[BorderStyle].cssValues
|
|
|
|
if value.Style > 0 && value.Style < len(styles) {
|
|
|
|
if buffer.Len() > 0 {
|
|
|
|
buffer.WriteRune(' ')
|
|
|
|
}
|
|
|
|
buffer.WriteString(styles[value.Style])
|
|
|
|
}
|
|
|
|
|
|
|
|
if value.Color != 0 {
|
|
|
|
if buffer.Len() > 0 {
|
|
|
|
buffer.WriteRune(' ')
|
|
|
|
}
|
|
|
|
buffer.WriteString(value.Color.cssString())
|
|
|
|
}
|
|
|
|
|
|
|
|
return buffer.String()
|
|
|
|
}
|