Bug fixing

This commit is contained in:
Alexei Anoshenko 2024-12-02 15:47:06 +03:00
parent 8a353f765e
commit 5efa2f5ae8
3 changed files with 101 additions and 164 deletions

View File

@ -937,7 +937,7 @@ func GetPushTiming(view View, subviewID ...string) string {
return "easy" return "easy"
} }
// GetTransform returns the start transform (translation, scale and rotation over x, y and z axes as well as a distortion) // GetPushTransform returns the start transform (translation, scale and rotation over x, y and z axes as well as a distortion)
// for an animated pushing of a child view. // for an animated pushing of a child view.
// The default value is nil (no transform). // The default value is nil (no transform).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned. // If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.

View File

@ -397,6 +397,8 @@ type TransformProperty interface {
fmt.Stringer fmt.Stringer
stringWriter stringWriter
transformCSS(session Session) string transformCSS(session Session) string
getSkew(session Session) (AngleUnit, AngleUnit, bool)
getTranslate(session Session) (SizeUnit, SizeUnit, SizeUnit)
} }
type transformPropertyData struct { type transformPropertyData struct {
@ -563,13 +565,6 @@ func setTransformPropertyElement(properties Properties, tag, transformTag Proper
return nil return nil
} }
/*
func getTransform3D(style Properties, session Session) bool {
perspective, ok := sizeProperty(style, Perspective, session)
return ok && perspective.Type != Auto && perspective.Value != 0
}
*/
func getPerspectiveOrigin(style Properties, session Session) (SizeUnit, SizeUnit) { func getPerspectiveOrigin(style Properties, session Session) (SizeUnit, SizeUnit) {
x, _ := sizeProperty(style, PerspectiveOriginX, session) x, _ := sizeProperty(style, PerspectiveOriginX, session)
y, _ := sizeProperty(style, PerspectiveOriginY, session) y, _ := sizeProperty(style, PerspectiveOriginY, session)
@ -766,54 +761,95 @@ func transformOriginCSS(x, y, z SizeUnit, session Session) string {
return buffer.String() return buffer.String()
} }
/* // GetTransform returns a view transform: translation, scale and rotation over x, y and z axes as well as a distortion of a view along x and y axes.
func (view *viewData) updateTransformProperty(tag PropertyName) bool { // The default value is nil (no transform)
htmlID := view.htmlID() // If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
session := view.session func GetTransform(view View, subviewID ...string) TransformProperty {
return transformStyledProperty(view, subviewID, Transform)
switch tag {
case PerspectiveOriginX, PerspectiveOriginY:
if getTransform3D(view, session) {
x, y := GetPerspectiveOrigin(view)
value := ""
if x.Type != Auto || y.Type != Auto {
value = x.cssString("50%", session) + " " + y.cssString("50%", session)
}
session.updateCSSProperty(htmlID, "perspective-origin", value)
} }
case BackfaceVisible: // GetPerspective returns a distance between the z = 0 plane and the user in order to give a 3D-positioned
if getTransform3D(view, session) { // element some perspective. Each 3D element with z > 0 becomes larger; each 3D-element with z < 0 becomes smaller.
if GetBackfaceVisible(view) { // The default value is 0 (no 3D effects).
session.updateCSSProperty(htmlID, string(BackfaceVisible), "visible") // If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
} else { func GetPerspective(view View, subviewID ...string) SizeUnit {
session.updateCSSProperty(htmlID, string(BackfaceVisible), "hidden") return sizeStyledProperty(view, subviewID, Perspective, false)
}
} }
case OriginX, OriginY, OriginZ: // GetPerspectiveOrigin returns a x- and y-coordinate of the position at which the viewer is looking.
x, y, z := getOrigin(view, session) // It is used as the vanishing point by the Perspective property. The default value is (50%, 50%).
value := "" // If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetPerspectiveOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit) {
if z.Type != Auto { view = getSubview(view, subviewID)
value = x.cssString("50%", session) + " " + y.cssString("50%", session) + " " + z.cssString("50%", session) if view == nil {
} else if x.Type != Auto || y.Type != Auto { return AutoSize(), AutoSize()
value = x.cssString("50%", session) + " " + y.cssString("50%", session)
} }
session.updateCSSProperty(htmlID, "transform-origin", value) return getPerspectiveOrigin(view, view.Session())
case TransformTag, SkewX, SkewY, TranslateX, TranslateY, TranslateZ,
ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ:
if transform := getTransformProperty(view); transform != nil {
session.updateCSSProperty(htmlID, "transform", transform.transformCSS(session))
} else {
session.updateCSSProperty(htmlID, "transform", "")
} }
default: // GetBackfaceVisible returns a bool property that sets whether the back face of an element is
return false // visible when turned towards the user. Values:
// true - the back face is visible when turned towards the user (default value).
// false - the back face is hidden, effectively making the element invisible when turned away from the user.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetBackfaceVisible(view View, subviewID ...string) bool {
return boolStyledProperty(view, subviewID, BackfaceVisible, false)
} }
return true // GetTransformOrigin returns a x-, y-, and z-coordinate of the point around which a view transformation is applied.
// The default value is (50%, 50%, 50%).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTransformOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
view = getSubview(view, subviewID)
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
return getTransformOrigin(view, view.Session())
}
// GetTranslate returns a x-, y-, and z-axis translation value of a 2D/3D translation
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTranslate(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
if transform := GetTransform(view, subviewID...); transform != nil {
return transform.getTranslate(view.Session())
}
return AutoSize(), AutoSize(), AutoSize()
}
// GetSkew returns a angles to use to distort the element along the abscissa (x-axis)
// and the ordinate (y-axis). The default value is 0.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetSkew(view View, subviewID ...string) (AngleUnit, AngleUnit) {
if transform := GetTransform(view, subviewID...); transform != nil {
x, y, _ := transform.getSkew(view.Session())
return x, y
}
return AngleUnit{Value: 0, Type: Radian}, AngleUnit{Value: 0, Type: Radian}
}
// GetScale returns a x-, y-, and z-axis scaling value of a 2D/3D scale. The default value is 1.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetScale(view View, subviewID ...string) (float64, float64, float64) {
if transform := GetTransform(view, subviewID...); transform != nil {
session := view.Session()
x, _ := floatProperty(transform, ScaleX, session, 1)
y, _ := floatProperty(transform, ScaleY, session, 1)
z, _ := floatProperty(transform, ScaleZ, session, 1)
return x, y, z
}
return 1, 1, 1
}
// GetRotate returns a x-, y, z-coordinate of the vector denoting the axis of rotation, and the angle of the view rotation
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetRotate(view View, subviewID ...string) (float64, float64, float64, AngleUnit) {
if transform := GetTransform(view, subviewID...); transform != nil {
session := view.Session()
angle, _ := angleProperty(transform, Rotate, view.Session())
rotateX, _ := floatProperty(transform, RotateX, session, 1)
rotateY, _ := floatProperty(transform, RotateY, session, 1)
rotateZ, _ := floatProperty(transform, RotateZ, session, 1)
return rotateX, rotateY, rotateZ, angle
}
return 0, 0, 0, AngleUnit{Value: 0, Type: Radian}
} }
*/

View File

@ -3,6 +3,8 @@ package rui
// Get returns a value of the property with name "tag" of the "rootView" subview with "viewID" id value. // Get returns a value of the property with name "tag" of the "rootView" subview with "viewID" id value.
// The type of return value depends on the property. // The type of return value depends on the property.
// If the subview don't exists or the property is not set then nil is returned. // If the subview don't exists or the property is not set then nil is returned.
//
// If the second argument (subviewID) is "" then a listener for the first argument (view) is get
func Get(rootView View, viewID string, tag PropertyName) any { func Get(rootView View, viewID string, tag PropertyName) any {
var view View var view View
if viewID != "" { if viewID != "" {
@ -17,8 +19,12 @@ func Get(rootView View, viewID string, tag PropertyName) any {
} }
// Set sets the property with name "tag" of the "rootView" subview with "viewID" id by value. Result: // Set sets the property with name "tag" of the "rootView" subview with "viewID" id by value. Result:
//
// true - success, // true - success,
//
// false - error (incompatible type or invalid format of a string value, see AppLog). // false - error (incompatible type or invalid format of a string value, see AppLog).
//
// If the second argument (subviewID) is "" then a listener for the first argument (view) is set
func Set(rootView View, viewID string, tag PropertyName, value any) bool { func Set(rootView View, viewID string, tag PropertyName, value any) bool {
var view View var view View
if viewID != "" { if viewID != "" {
@ -33,7 +39,7 @@ func Set(rootView View, viewID string, tag PropertyName, value any) bool {
} }
// SetChangeListener sets a listener for changing a subview property value. // SetChangeListener sets a listener for changing a subview property value.
// If the second argument (subviewID) is not specified or it is "" then a listener for the first argument (view) is set // If the second argument (subviewID) is "" then a listener for the first argument (view) is set
func SetChangeListener(view View, viewID string, tag PropertyName, listener func(View, PropertyName)) { func SetChangeListener(view View, viewID string, tag PropertyName, listener func(View, PropertyName)) {
if viewID != "" { if viewID != "" {
view = ViewByID(view, viewID) view = ViewByID(view, viewID)
@ -544,111 +550,6 @@ func GetColumn(view View, subviewID ...string) Range {
return Range{} return Range{}
} }
// GetTransform returns a view transform: translation, scale and rotation over x, y and z axes as well as a distortion of a view along x and y axes.
// The default value is nil (no transform)
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTransform(view View, subviewID ...string) TransformProperty {
return transformStyledProperty(view, subviewID, Transform)
}
// GetPerspective returns a distance between the z = 0 plane and the user in order to give a 3D-positioned
// element some perspective. Each 3D element with z > 0 becomes larger; each 3D-element with z < 0 becomes smaller.
// The default value is 0 (no 3D effects).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetPerspective(view View, subviewID ...string) SizeUnit {
return sizeStyledProperty(view, subviewID, Perspective, false)
}
// GetPerspectiveOrigin returns a x- and y-coordinate of the position at which the viewer is looking.
// It is used as the vanishing point by the Perspective property. The default value is (50%, 50%).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetPerspectiveOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit) {
view = getSubview(view, subviewID)
if view == nil {
return AutoSize(), AutoSize()
}
return getPerspectiveOrigin(view, view.Session())
}
// GetBackfaceVisible returns a bool property that sets whether the back face of an element is
// visible when turned towards the user. Values:
// true - the back face is visible when turned towards the user (default value).
// false - the back face is hidden, effectively making the element invisible when turned away from the user.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetBackfaceVisible(view View, subviewID ...string) bool {
return boolStyledProperty(view, subviewID, BackfaceVisible, false)
}
// GetTransformOrigin returns a x-, y-, and z-coordinate of the point around which a view transformation is applied.
// The default value is (50%, 50%, 50%).
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTransformOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
view = getSubview(view, subviewID)
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
return getTransformOrigin(view, view.Session())
}
// GetTranslate returns a x-, y-, and z-axis translation value of a 2D/3D translation
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetTranslate(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
view = getSubview(view, subviewID)
if view == nil {
return AutoSize(), AutoSize(), AutoSize()
}
session := view.Session()
x, _ := sizeProperty(view, TranslateX, session)
y, _ := sizeProperty(view, TranslateY, session)
z, _ := sizeProperty(view, TranslateZ, session)
return x, y, z
}
// GetSkew returns a angles to use to distort the element along the abscissa (x-axis)
// and the ordinate (y-axis). The default value is 0.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetSkew(view View, subviewID ...string) (AngleUnit, AngleUnit) {
view = getSubview(view, subviewID)
if view == nil {
return AngleUnit{Value: 0, Type: Radian}, AngleUnit{Value: 0, Type: Radian}
}
x, _ := angleProperty(view, SkewX, view.Session())
y, _ := angleProperty(view, SkewY, view.Session())
return x, y
}
// GetScale returns a x-, y-, and z-axis scaling value of a 2D/3D scale. The default value is 1.
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetScale(view View, subviewID ...string) (float64, float64, float64) {
view = getSubview(view, subviewID)
if view == nil {
return 1, 1, 1
}
session := view.Session()
x, _ := floatProperty(view, ScaleX, session, 1)
y, _ := floatProperty(view, ScaleY, session, 1)
z, _ := floatProperty(view, ScaleZ, session, 1)
return x, y, z
}
// GetRotate returns a x-, y, z-coordinate of the vector denoting the axis of rotation, and the angle of the view rotation
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
func GetRotate(view View, subviewID ...string) (float64, float64, float64, AngleUnit) {
view = getSubview(view, subviewID)
if view == nil {
return 0, 0, 0, AngleUnit{Value: 0, Type: Radian}
}
session := view.Session()
angle, _ := angleProperty(view, Rotate, view.Session())
rotateX, _ := floatProperty(view, RotateX, session, 1)
rotateY, _ := floatProperty(view, RotateY, session, 1)
rotateZ, _ := floatProperty(view, RotateZ, session, 1)
return rotateX, rotateY, rotateZ, angle
}
// GetAvoidBreak returns "true" if avoids any break from being inserted within the principal box, // GetAvoidBreak returns "true" if avoids any break from being inserted within the principal box,
// and "false" if allows, but does not force, any break to be inserted within the principal box. // and "false" if allows, but does not force, any break to be inserted within the principal box.
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned // If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned