From 5f55d3044340b8a1aaba98d6052f24cecb0ee6ea Mon Sep 17 00:00:00 2001 From: Alexei Anoshenko <2277098+anoshenko@users.noreply.github.com> Date: Tue, 3 Dec 2024 11:20:32 +0300 Subject: [PATCH] Added NewRadius functions --- CHANGELOG.md | 4 ++- bounds.go | 30 -------------------- radius.go | 77 ++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 69 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 23e0f28..6e3c8a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # v0.18.0 * Property name type changed from string to PropertyName. + * Renamed: Transform interface -> TransformProperty NewTransform function -> NewTransformProperty @@ -17,7 +18,8 @@ NewInsetViewShadow function -> NewInsetShadow NewShadowWithParams function -> NewShadowProperty -* Added functions: NewBounds, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation, +* Added functions: NewBounds, NewEllipticRadius, NewRadii, +GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation, GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin. * Changed Push, Pop, MoveToFront, and MoveToFrontByID methods of StackLayout interface. diff --git a/bounds.go b/bounds.go index 5d931d2..1384318 100644 --- a/bounds.go +++ b/bounds.go @@ -152,22 +152,6 @@ func (bounds *Bounds) setFromProperties(tag, topTag, rightTag, bottomTag, leftTa } } -/* -func (bounds *Bounds) allFieldsAuto() bool { - return bounds.Left.Type == Auto && - bounds.Top.Type == Auto && - bounds.Right.Type == Auto && - bounds.Bottom.Type == Auto -} - -func (bounds *Bounds) allFieldsZero() bool { - return (bounds.Left.Type == Auto || bounds.Left.Value == 0) && - (bounds.Top.Type == Auto || bounds.Top.Value == 0) && - (bounds.Right.Type == Auto || bounds.Right.Value == 0) && - (bounds.Bottom.Type == Auto || bounds.Bottom.Value == 0) -} -*/ - func (bounds *Bounds) allFieldsEqual() bool { if bounds.Left.Type == bounds.Top.Type && bounds.Left.Type == bounds.Right.Type && @@ -181,20 +165,6 @@ func (bounds *Bounds) allFieldsEqual() bool { return false } -/* -func (bounds Bounds) writeCSSString(buffer *strings.Builder, textForAuto string) { - buffer.WriteString(bounds.Top.cssString(textForAuto)) - if !bounds.allFieldsEqual() { - buffer.WriteRune(' ') - buffer.WriteString(bounds.Right.cssString(textForAuto)) - buffer.WriteRune(' ') - buffer.WriteString(bounds.Bottom.cssString(textForAuto)) - buffer.WriteRune(' ') - buffer.WriteString(bounds.Left.cssString(textForAuto)) - } -} -*/ - // String convert Bounds to string func (bounds *Bounds) String() string { if bounds.allFieldsEqual() { diff --git a/radius.go b/radius.go index 7352632..7241a53 100644 --- a/radius.go +++ b/radius.go @@ -226,7 +226,7 @@ const ( // See `SizeUnit` description for more details. // // Usage in `RadiusProperty`: - // Determines the x-axis top-right corner elliptic rounding radius of an element's outer border edge. + // Determines the x-axis elliptic rounding radius of an element's outer border edge. // // Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`. // @@ -247,7 +247,7 @@ const ( // See `SizeUnit` description for more details. // // Usage in `RadiusProperty`: - // Determines the y-axis top-right corner elliptic rounding radius of an element's outer border edge. + // Determines the y-axis elliptic rounding radius of an element's outer border edge. // // Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`. // @@ -403,17 +403,38 @@ type radiusPropertyData struct { } // NewRadiusProperty creates the new RadiusProperty +// The following properties can be used: +// +// "x" (X) - Determines the x-axis elliptic rounding radius of an element's outer border edge. +// +// "y" (Y) - Determines the y-axis corner elliptic rounding radius of an element's outer border edge. +// +// "top-left" (TopLeft) - Determines the top-left corner rounding radius of an element's outer border edge. +// +// "top-left-x" (TopLeftX) - Determines the x-axis top-left corner elliptic rounding radius of an element's outer border edge. +// +// "top-left-y" (TopLeftY) - Determines the y-axis top-left corner elliptic rounding radius of an element's outer border edge. +// +// "top-right" (TopRight) - Determines the top-right corner rounding radius of an element's outer border edge. +// +// "top-right-x" (TopRightX) - Determines the x-axis top-right corner elliptic rounding radius of an element's outer border edge. +// +// "top-right-y" (TopRightY) - Determines the y-axis top-right corner elliptic rounding radius of an element's outer border edge. +// +// "bottom-left" (BottomLeft) - Determines the bottom-left corner rounding radius of an element's outer border edge. +// +// "bottom-left-x" (BottomLeftX) - Determines the x-axis bottom-left corner elliptic rounding radius of an element's outer border edge. +// +// "bottom-left-y" (BottomLeftY) - Determines the y-axis bottom-left corner elliptic rounding radius of an element's outer border edge. +// +// "bottom-right" (BottomRight) - Determines the bottom-right corner rounding radius of an element's outer border edge. +// +// "bottom-right-x" (BottomRightX) - Determines the x-axis bottom-right corner elliptic rounding radius of an element's outer border edge. +// +// "bottom-right-y" (BottomRightY) - Determines the y-axis bottom-right corner elliptic rounding radius of an element's outer border edge. func NewRadiusProperty(params Params) RadiusProperty { result := new(radiusPropertyData) - result.dataProperty.init() - result.normalize = radiusPropertyNormalize - result.get = radiusPropertyGet - result.remove = radiusPropertyRemove - result.set = radiusPropertySet - result.supportedProperties = []PropertyName{ - X, Y, TopLeft, TopRight, BottomLeft, BottomRight, TopLeftX, TopLeftY, - TopRightX, TopRightY, BottomLeftX, BottomLeftY, BottomRightX, BottomRightY, - } + result.init() if params != nil { for _, tag := range result.supportedProperties { @@ -425,11 +446,45 @@ func NewRadiusProperty(params Params) RadiusProperty { return result } +// NewRadiusProperty creates the new RadiusProperty which having the same elliptical radii for all angles. +// Arguments determines the x- and y-axis elliptic rounding radius. if an argument is specified as int or float64, the value is considered to be in pixels +func NewEllipticRadius[xType SizeUnit | int | float64, yType SizeUnit | int | float64](x xType, y yType) RadiusProperty { + return NewRadiusProperty(Params{ + X: x, + Y: y, + }) +} + +// NewRadius creates the new RadiusProperty. +// The arguments specify the radii in a clockwise direction: "top-right", "bottom-right", "bottom-left", and "top-left". +// if an argument is specified as int or float64, the value is considered to be in pixels +func NewRadii[topRightType SizeUnit | int | float64, bottomRightType SizeUnit | int | float64, bottomLeftType SizeUnit | int | float64, topLeftType SizeUnit | int | float64]( + topRight topRightType, bottomRight bottomRightType, bottomLeft bottomLeftType, topLeft topLeftType) RadiusProperty { + return NewRadiusProperty(Params{ + TopRight: topRight, + BottomRight: bottomRight, + BottomLeft: bottomLeft, + TopLeft: topLeft, + }) +} + func radiusPropertyNormalize(tag PropertyName) PropertyName { name := strings.TrimPrefix(strings.ToLower(string(tag)), "radius-") return PropertyName(name) } +func (radius *radiusPropertyData) init() { + radius.dataProperty.init() + radius.normalize = radiusPropertyNormalize + radius.get = radiusPropertyGet + radius.remove = radiusPropertyRemove + radius.set = radiusPropertySet + radius.supportedProperties = []PropertyName{ + X, Y, TopLeft, TopRight, BottomLeft, BottomRight, TopLeftX, TopLeftY, + TopRightX, TopRightY, BottomLeftX, BottomLeftY, BottomRightX, BottomRightY, + } +} + func (radius *radiusPropertyData) writeString(buffer *strings.Builder, indent string) { buffer.WriteString("_{ ") comma := false