Added NewRadius functions

This commit is contained in:
Alexei Anoshenko 2024-12-03 11:20:32 +03:00
parent 8e20e80899
commit 5f55d30443
3 changed files with 69 additions and 42 deletions

View File

@ -1,6 +1,7 @@
# v0.18.0 # v0.18.0
* Property name type changed from string to PropertyName. * Property name type changed from string to PropertyName.
* Renamed: * Renamed:
Transform interface -> TransformProperty Transform interface -> TransformProperty
NewTransform function -> NewTransformProperty NewTransform function -> NewTransformProperty
@ -17,7 +18,8 @@
NewInsetViewShadow function -> NewInsetShadow NewInsetViewShadow function -> NewInsetShadow
NewShadowWithParams function -> NewShadowProperty 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. GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin.
* Changed Push, Pop, MoveToFront, and MoveToFrontByID methods of StackLayout interface. * Changed Push, Pop, MoveToFront, and MoveToFrontByID methods of StackLayout interface.

View File

@ -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 { func (bounds *Bounds) allFieldsEqual() bool {
if bounds.Left.Type == bounds.Top.Type && if bounds.Left.Type == bounds.Top.Type &&
bounds.Left.Type == bounds.Right.Type && bounds.Left.Type == bounds.Right.Type &&
@ -181,20 +165,6 @@ func (bounds *Bounds) allFieldsEqual() bool {
return false 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 // String convert Bounds to string
func (bounds *Bounds) String() string { func (bounds *Bounds) String() string {
if bounds.allFieldsEqual() { if bounds.allFieldsEqual() {

View File

@ -226,7 +226,7 @@ const (
// See `SizeUnit` description for more details. // See `SizeUnit` description for more details.
// //
// Usage in `RadiusProperty`: // 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`. // Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
// //
@ -247,7 +247,7 @@ const (
// See `SizeUnit` description for more details. // See `SizeUnit` description for more details.
// //
// Usage in `RadiusProperty`: // 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`. // Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
// //
@ -403,17 +403,38 @@ type radiusPropertyData struct {
} }
// NewRadiusProperty creates the new RadiusProperty // 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 { func NewRadiusProperty(params Params) RadiusProperty {
result := new(radiusPropertyData) result := new(radiusPropertyData)
result.dataProperty.init() result.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,
}
if params != nil { if params != nil {
for _, tag := range result.supportedProperties { for _, tag := range result.supportedProperties {
@ -425,11 +446,45 @@ func NewRadiusProperty(params Params) RadiusProperty {
return result 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 { func radiusPropertyNormalize(tag PropertyName) PropertyName {
name := strings.TrimPrefix(strings.ToLower(string(tag)), "radius-") name := strings.TrimPrefix(strings.ToLower(string(tag)), "radius-")
return PropertyName(name) 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) { func (radius *radiusPropertyData) writeString(buffer *strings.Builder, indent string) {
buffer.WriteString("_{ ") buffer.WriteString("_{ ")
comma := false comma := false