mirror of https://github.com/anoshenko/rui.git
Bug fixing
This commit is contained in:
parent
8a353f765e
commit
5efa2f5ae8
|
@ -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.
|
||||||
|
|
150
transform.go
150
transform.go
|
@ -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) {
|
// GetPerspective returns a distance between the z = 0 plane and the user in order to give a 3D-positioned
|
||||||
x, y := GetPerspectiveOrigin(view)
|
// element some perspective. Each 3D element with z > 0 becomes larger; each 3D-element with z < 0 becomes smaller.
|
||||||
value := ""
|
// The default value is 0 (no 3D effects).
|
||||||
if x.Type != Auto || y.Type != Auto {
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
||||||
value = x.cssString("50%", session) + " " + y.cssString("50%", session)
|
func GetPerspective(view View, subviewID ...string) SizeUnit {
|
||||||
}
|
return sizeStyledProperty(view, subviewID, Perspective, false)
|
||||||
session.updateCSSProperty(htmlID, "perspective-origin", value)
|
}
|
||||||
}
|
|
||||||
|
// GetPerspectiveOrigin returns a x- and y-coordinate of the position at which the viewer is looking.
|
||||||
case BackfaceVisible:
|
// It is used as the vanishing point by the Perspective property. The default value is (50%, 50%).
|
||||||
if getTransform3D(view, session) {
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
||||||
if GetBackfaceVisible(view) {
|
func GetPerspectiveOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit) {
|
||||||
session.updateCSSProperty(htmlID, string(BackfaceVisible), "visible")
|
view = getSubview(view, subviewID)
|
||||||
} else {
|
if view == nil {
|
||||||
session.updateCSSProperty(htmlID, string(BackfaceVisible), "hidden")
|
return AutoSize(), AutoSize()
|
||||||
}
|
}
|
||||||
}
|
return getPerspectiveOrigin(view, view.Session())
|
||||||
|
}
|
||||||
case OriginX, OriginY, OriginZ:
|
|
||||||
x, y, z := getOrigin(view, session)
|
// GetBackfaceVisible returns a bool property that sets whether the back face of an element is
|
||||||
value := ""
|
// visible when turned towards the user. Values:
|
||||||
|
// true - the back face is visible when turned towards the user (default value).
|
||||||
if z.Type != Auto {
|
// false - the back face is hidden, effectively making the element invisible when turned away from the user.
|
||||||
value = x.cssString("50%", session) + " " + y.cssString("50%", session) + " " + z.cssString("50%", session)
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
||||||
} else if x.Type != Auto || y.Type != Auto {
|
func GetBackfaceVisible(view View, subviewID ...string) bool {
|
||||||
value = x.cssString("50%", session) + " " + y.cssString("50%", session)
|
return boolStyledProperty(view, subviewID, BackfaceVisible, false)
|
||||||
}
|
}
|
||||||
session.updateCSSProperty(htmlID, "transform-origin", value)
|
|
||||||
|
// GetTransformOrigin returns a x-, y-, and z-coordinate of the point around which a view transformation is applied.
|
||||||
case TransformTag, SkewX, SkewY, TranslateX, TranslateY, TranslateZ,
|
// The default value is (50%, 50%, 50%).
|
||||||
ScaleX, ScaleY, ScaleZ, Rotate, RotateX, RotateY, RotateZ:
|
// If the second argument (subviewID) is not specified or it is "" then a value from the first argument (view) is returned.
|
||||||
if transform := getTransformProperty(view); transform != nil {
|
func GetTransformOrigin(view View, subviewID ...string) (SizeUnit, SizeUnit, SizeUnit) {
|
||||||
session.updateCSSProperty(htmlID, "transform", transform.transformCSS(session))
|
view = getSubview(view, subviewID)
|
||||||
} else {
|
if view == nil {
|
||||||
session.updateCSSProperty(htmlID, "transform", "")
|
return AutoSize(), AutoSize(), AutoSize()
|
||||||
}
|
}
|
||||||
|
return getTransformOrigin(view, view.Session())
|
||||||
default:
|
}
|
||||||
return false
|
|
||||||
}
|
// 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.
|
||||||
return true
|
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}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
113
viewUtils.go
113
viewUtils.go
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue