mirror of https://github.com/anoshenko/rui.git
Transform interface renamed to TransformProperty. TransformTag constant renamed to Transform.
This commit is contained in:
parent
0f2e7e55ea
commit
857ad69260
|
@ -1,5 +1,7 @@
|
||||||
# v0.18.0
|
# v0.18.0
|
||||||
|
|
||||||
|
* Property name type changed to PropertyName.
|
||||||
|
* Transform interface renamed to TransformProperty. TransformTag constant renamed to Transform.
|
||||||
* OriginX, OriginY, and OriginZ properties renamed to TransformOriginX, TransformOriginY, and TransformOriginZ
|
* OriginX, OriginY, and OriginZ properties renamed to TransformOriginX, TransformOriginY, and TransformOriginZ
|
||||||
* GetOrigin function renamed to GetTransformOrigin
|
* GetOrigin function renamed to GetTransformOrigin
|
||||||
* Added LineJoin type. Type of constants MiterJoin, RoundJoin, and BevelJoin changed to LineJoin. Type of Canvas.SetLineJoin function argument changed to LineJoin.
|
* Added LineJoin type. Type of constants MiterJoin, RoundJoin, and BevelJoin changed to LineJoin. Type of Canvas.SetLineJoin function argument changed to LineJoin.
|
||||||
|
|
2
view.go
2
view.go
|
@ -705,7 +705,7 @@ func (view *viewData) propertyChanged(tag PropertyName) {
|
||||||
x, y, z := getTransformOrigin(view, session)
|
x, y, z := getTransformOrigin(view, session)
|
||||||
session.updateCSSProperty(htmlID, "transform-origin", transformOriginCSS(x, y, z, view.Session()))
|
session.updateCSSProperty(htmlID, "transform-origin", transformOriginCSS(x, y, z, view.Session()))
|
||||||
|
|
||||||
case TransformTag, Perspective, SkewX, SkewY, TranslateX, TranslateY, TranslateZ,
|
case Transform, Perspective, SkewX, SkewY, TranslateX, TranslateY, TranslateZ,
|
||||||
ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ:
|
ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ:
|
||||||
css := ""
|
css := ""
|
||||||
if transform := getTransformProperty(view); transform != nil {
|
if transform := getTransformProperty(view); transform != nil {
|
||||||
|
|
|
@ -880,7 +880,7 @@ func writeViewStyle(name string, view Properties, buffer *strings.Builder, inden
|
||||||
finalTags := []PropertyName{
|
finalTags := []PropertyName{
|
||||||
PerspectiveOriginX, PerspectiveOriginY, BackfaceVisible,
|
PerspectiveOriginX, PerspectiveOriginY, BackfaceVisible,
|
||||||
TransformOriginX, TransformOriginY, TransformOriginZ,
|
TransformOriginX, TransformOriginY, TransformOriginZ,
|
||||||
TransformTag, Clip, Filter, BackdropFilter, Summary, Content, Transition}
|
Transform, Clip, Filter, BackdropFilter, Summary, Content, Transition}
|
||||||
for _, tag := range finalTags {
|
for _, tag := range finalTags {
|
||||||
removeTag(tag)
|
removeTag(tag)
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,9 +345,9 @@ func viewStyleSet(style Properties, tag PropertyName, value any) []PropertyName
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case TransformTag:
|
case Transform:
|
||||||
if setTransformProperty(style, value) {
|
if setTransformProperty(style, value) {
|
||||||
return []PropertyName{TransformTag}
|
return []PropertyName{Transform}
|
||||||
} else {
|
} else {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,21 +6,21 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Constants for [Transform] specific properties
|
// Constants for [TransformProperty] specific properties
|
||||||
const (
|
const (
|
||||||
// TransformTag is the constant for "transform" property tag.
|
// Transform is the constant for "transform" property tag.
|
||||||
//
|
//
|
||||||
// Used by `View`.
|
// Used by `View`.
|
||||||
// Specify translation, scale and rotation over x, y and z axes as well as a distorsion of a view along x and y axes.
|
// Specify translation, scale and rotation over x, y and z axes as well as a distorsion of a view along x and y axes.
|
||||||
//
|
//
|
||||||
// Supported types: `Transform`, `string`.
|
// Supported types: `TransformProperty`, `string`.
|
||||||
//
|
//
|
||||||
// See `Transform` description for more details.
|
// See `Transform` description for more details.
|
||||||
//
|
//
|
||||||
// Conversion rules:
|
// Conversion rules:
|
||||||
// `Transform` - stored as is, no conversion performed.
|
// `Transform` - stored as is, no conversion performed.
|
||||||
// `string` - string representation of `Transform` interface. Example: "_{translate-x = 10px, scale-y = 1.1}".
|
// `string` - string representation of `Transform` interface. Example: "_{translate-x = 10px, scale-y = 1.1}".
|
||||||
TransformTag PropertyName = "transform"
|
Transform PropertyName = "transform"
|
||||||
|
|
||||||
// Perspective is the constant for "perspective" property tag.
|
// Perspective is the constant for "perspective" property tag.
|
||||||
//
|
//
|
||||||
|
@ -386,26 +386,26 @@ const (
|
||||||
SkewY PropertyName = "skew-y"
|
SkewY PropertyName = "skew-y"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Transform interface specifies view transformation parameters: the x-, y-, and z-axis translation values,
|
// TransformProperty interface specifies view transformation parameters: the x-, y-, and z-axis translation values,
|
||||||
// the x-, y-, and z-axis scaling values, the angle to use to distort the element along the abscissa and ordinate,
|
// the x-, y-, and z-axis scaling values, the angle to use to distort the element along the abscissa and ordinate,
|
||||||
// the angle of the view rotation.
|
// the angle of the view rotation.
|
||||||
// Valid property tags: Perspective ("perspective"), TranslateX ("translate-x"), TranslateY ("translate-y"), TranslateZ ("translate-z"),
|
// Valid property tags: Perspective ("perspective"), TranslateX ("translate-x"), TranslateY ("translate-y"), TranslateZ ("translate-z"),
|
||||||
// ScaleX ("scale-x"), ScaleY ("scale-y"), ScaleZ ("scale-z"), Rotate ("rotate"), RotateX ("rotate-x"),
|
// ScaleX ("scale-x"), ScaleY ("scale-y"), ScaleZ ("scale-z"), Rotate ("rotate"), RotateX ("rotate-x"),
|
||||||
// RotateY ("rotate-y"), RotateZ ("rotate-z"), SkewX ("skew-x"), and SkewY ("skew-y")
|
// RotateY ("rotate-y"), RotateZ ("rotate-z"), SkewX ("skew-x"), and SkewY ("skew-y")
|
||||||
type Transform interface {
|
type TransformProperty interface {
|
||||||
Properties
|
Properties
|
||||||
fmt.Stringer
|
fmt.Stringer
|
||||||
stringWriter
|
stringWriter
|
||||||
transformCSS(session Session) string
|
transformCSS(session Session) string
|
||||||
}
|
}
|
||||||
|
|
||||||
type transformData struct {
|
type transformPropertyData struct {
|
||||||
dataProperty
|
dataProperty
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTransform creates a new transform property data and return its interface
|
// NewTransform creates a new transform property data and return its interface
|
||||||
func NewTransform(params Params) Transform {
|
func NewTransformProperty(params Params) TransformProperty {
|
||||||
transform := new(transformData)
|
transform := new(transformPropertyData)
|
||||||
transform.init()
|
transform.init()
|
||||||
|
|
||||||
for tag, value := range params {
|
for tag, value := range params {
|
||||||
|
@ -414,7 +414,7 @@ func NewTransform(params Params) Transform {
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transform *transformData) init() {
|
func (transform *transformPropertyData) init() {
|
||||||
transform.dataProperty.init()
|
transform.dataProperty.init()
|
||||||
transform.set = transformSet
|
transform.set = transformSet
|
||||||
transform.supportedProperties = []PropertyName{
|
transform.supportedProperties = []PropertyName{
|
||||||
|
@ -423,14 +423,14 @@ func (transform *transformData) init() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transform *transformData) String() string {
|
func (transform *transformPropertyData) String() string {
|
||||||
buffer := allocStringBuilder()
|
buffer := allocStringBuilder()
|
||||||
defer freeStringBuilder(buffer)
|
defer freeStringBuilder(buffer)
|
||||||
transform.writeString(buffer, "")
|
transform.writeString(buffer, "")
|
||||||
return buffer.String()
|
return buffer.String()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transform *transformData) writeString(buffer *strings.Builder, indent string) {
|
func (transform *transformPropertyData) writeString(buffer *strings.Builder, indent string) {
|
||||||
buffer.WriteString("_{ ")
|
buffer.WriteString("_{ ")
|
||||||
comma := false
|
comma := false
|
||||||
for _, tag := range transform.supportedProperties {
|
for _, tag := range transform.supportedProperties {
|
||||||
|
@ -469,7 +469,7 @@ func transformSet(properties Properties, tag PropertyName, value any) []Property
|
||||||
func setTransformProperty(properties Properties, value any) bool {
|
func setTransformProperty(properties Properties, value any) bool {
|
||||||
|
|
||||||
setObject := func(obj DataObject) bool {
|
setObject := func(obj DataObject) bool {
|
||||||
transform := NewTransform(nil)
|
transform := NewTransformProperty(nil)
|
||||||
ok := true
|
ok := true
|
||||||
for i := 0; i < obj.PropertyCount(); i++ {
|
for i := 0; i < obj.PropertyCount(); i++ {
|
||||||
if prop := obj.Property(i); prop.Type() == TextNode {
|
if prop := obj.Property(i); prop.Type() == TextNode {
|
||||||
|
@ -485,13 +485,13 @@ func setTransformProperty(properties Properties, value any) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
properties.setRaw(TransformTag, transform)
|
properties.setRaw(Transform, transform)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
switch value := value.(type) {
|
switch value := value.(type) {
|
||||||
case Transform:
|
case TransformProperty:
|
||||||
properties.setRaw(TransformTag, value)
|
properties.setRaw(Transform, value)
|
||||||
return true
|
return true
|
||||||
|
|
||||||
case DataObject:
|
case DataObject:
|
||||||
|
@ -501,23 +501,23 @@ func setTransformProperty(properties Properties, value any) bool {
|
||||||
if obj := value.Object(); obj != nil {
|
if obj := value.Object(); obj != nil {
|
||||||
return setObject(obj)
|
return setObject(obj)
|
||||||
}
|
}
|
||||||
notCompatibleType(TransformTag, value)
|
notCompatibleType(Transform, value)
|
||||||
return false
|
return false
|
||||||
|
|
||||||
case string:
|
case string:
|
||||||
if obj := ParseDataText(value); obj != nil {
|
if obj := ParseDataText(value); obj != nil {
|
||||||
return setObject(obj)
|
return setObject(obj)
|
||||||
}
|
}
|
||||||
notCompatibleType(TransformTag, value)
|
notCompatibleType(Transform, value)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTransformProperty(properties Properties) Transform {
|
func getTransformProperty(properties Properties) TransformProperty {
|
||||||
if val := properties.getRaw(TransformTag); val != nil {
|
if val := properties.getRaw(Transform); val != nil {
|
||||||
if transform, ok := val.(Transform); ok {
|
if transform, ok := val.(TransformProperty); ok {
|
||||||
return transform
|
return transform
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -530,13 +530,13 @@ func setTransformPropertyElement(properties Properties, tag PropertyName, value
|
||||||
var result []PropertyName = nil
|
var result []PropertyName = nil
|
||||||
if transform := getTransformProperty(properties); transform != nil {
|
if transform := getTransformProperty(properties); transform != nil {
|
||||||
if result = transformSet(transform, tag, value); result != nil {
|
if result = transformSet(transform, tag, value); result != nil {
|
||||||
result = append(result, TransformTag)
|
result = append(result, Transform)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
transform := NewTransform(nil)
|
transform := NewTransformProperty(nil)
|
||||||
if result = transformSet(transform, tag, value); result != nil {
|
if result = transformSet(transform, tag, value); result != nil {
|
||||||
properties.setRaw(TransformTag, transform)
|
properties.setRaw(Transform, transform)
|
||||||
result = append(result, TransformTag)
|
result = append(result, Transform)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
@ -566,20 +566,20 @@ func getTransformOrigin(style Properties, session Session) (SizeUnit, SizeUnit,
|
||||||
return x, y, z
|
return x, y, z
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transform *transformData) getSkew(session Session) (AngleUnit, AngleUnit, bool) {
|
func (transform *transformPropertyData) getSkew(session Session) (AngleUnit, AngleUnit, bool) {
|
||||||
skewX, okX := angleProperty(transform, SkewX, session)
|
skewX, okX := angleProperty(transform, SkewX, session)
|
||||||
skewY, okY := angleProperty(transform, SkewY, session)
|
skewY, okY := angleProperty(transform, SkewY, session)
|
||||||
return skewX, skewY, okX || okY
|
return skewX, skewY, okX || okY
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transform *transformData) getTranslate(session Session) (SizeUnit, SizeUnit, SizeUnit) {
|
func (transform *transformPropertyData) getTranslate(session Session) (SizeUnit, SizeUnit, SizeUnit) {
|
||||||
x, _ := sizeProperty(transform, TranslateX, session)
|
x, _ := sizeProperty(transform, TranslateX, session)
|
||||||
y, _ := sizeProperty(transform, TranslateY, session)
|
y, _ := sizeProperty(transform, TranslateY, session)
|
||||||
z, _ := sizeProperty(transform, TranslateZ, session)
|
z, _ := sizeProperty(transform, TranslateZ, session)
|
||||||
return x, y, z
|
return x, y, z
|
||||||
}
|
}
|
||||||
|
|
||||||
func (transform *transformData) transformCSS(session Session) string {
|
func (transform *transformPropertyData) transformCSS(session Session) string {
|
||||||
|
|
||||||
buffer := allocStringBuilder()
|
buffer := allocStringBuilder()
|
||||||
defer freeStringBuilder(buffer)
|
defer freeStringBuilder(buffer)
|
||||||
|
|
Loading…
Reference in New Issue