mirror of https://github.com/anoshenko/rui.git
Renamed ClipShape -> ClipShapeProperty
This commit is contained in:
parent
a8242c99fe
commit
5039998cf9
|
@ -18,10 +18,17 @@
|
|||
NewInsetViewShadow function -> NewInsetShadow
|
||||
NewShadowWithParams function -> NewShadowProperty
|
||||
NewColumnSeparator function -> NewColumnSeparatorProperty
|
||||
ClipShape interface -> ClipShapeProperty
|
||||
InsetClip function -> NewInsetClip
|
||||
CircleClip function -> NewCircleClip
|
||||
EllipseClip function -> NewEllipseClip
|
||||
PolygonClip function -> NewPolygonClip
|
||||
PolygonPointsClip function -> NewPolygonPointsClip
|
||||
|
||||
* Added functions: NewBounds, NewEllipticRadius, NewRadii, NewLinearGradient, NewCircleRadialGradient,
|
||||
NewEllipseRadialGradient, GetPushTransform, GetPushDuration, GetPushTiming, IsMoveToFrontAnimation,
|
||||
GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin, NewColumnSeparator.
|
||||
GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, GetMaskOrigin, NewColumnSeparator,
|
||||
NewClipShapeProperty.
|
||||
|
||||
* Added SetConicGradientFillStyle and SetConicGradientStrokeStyle methods to Canvas interface.
|
||||
|
||||
|
|
12
README-ru.md
12
README-ru.md
|
@ -1322,14 +1322,14 @@ AngleUnit или string (угловая константа или текстов
|
|||
|
||||
### Свойство "clip"
|
||||
|
||||
Свойство "clip" (константа Clip) типа ClipShape задает задает область образки.
|
||||
Свойство "clip" (константа Clip) типа ClipShapeProperty задает задает область образки.
|
||||
Есть 4 типа областей обрезки
|
||||
|
||||
#### inset
|
||||
|
||||
Прямоугольная область обрезки. Создается с помощью функции:
|
||||
|
||||
func InsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipShape
|
||||
func NewInsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipShapeProperty
|
||||
|
||||
где top, right, bottom, left это расстояние от соответственно верхней, правой, нижней и левой границы
|
||||
View до одноименной границы обрезки; radius - задает радиусы скругления углов области обрезки
|
||||
|
@ -1346,7 +1346,7 @@ radius необходимо передать nil
|
|||
|
||||
Круглая область обрезки. Создается с помощью функции:
|
||||
|
||||
func CircleClip(x, y, radius SizeUnit) ClipShape
|
||||
func NewCircleClip(x, y, radius SizeUnit) ClipShapeProperty
|
||||
|
||||
где x, y - координаты центра окружности; radius - радиус
|
||||
|
||||
|
@ -1358,7 +1358,7 @@ radius необходимо передать nil
|
|||
|
||||
Эллиптическая область обрезки. Создается с помощью функции:
|
||||
|
||||
func EllipseClip(x, y, rx, ry SizeUnit) ClipShape
|
||||
func NewEllipseClip(x, y, rx, ry SizeUnit) ClipShapeProperty
|
||||
|
||||
где x, y - координаты центра эллипса; rх - радиус эллипса по оси X; ry - радиус эллипса по оси Y.
|
||||
|
||||
|
@ -1370,8 +1370,8 @@ radius необходимо передать nil
|
|||
|
||||
Многоугольная область обрезки. Создается с помощью функций:
|
||||
|
||||
func PolygonClip(points []any) ClipShape
|
||||
func PolygonPointsClip(points []SizeUnit) ClipShape
|
||||
func NewPolygonClip(points []any) ClipShapeProperty
|
||||
func NewPolygonPointsClip(points []SizeUnit) ClipShapeProperty
|
||||
|
||||
в качестве аргумента передается массив угловых точек многоугольника в следующем порядке: x1, y1, x2, y2, …
|
||||
В качестве элементов аргумента функции PolygonClip могут быть или текстовые константы, или
|
||||
|
|
12
README.md
12
README.md
|
@ -1301,14 +1301,14 @@ You can get the value of this property using the function
|
|||
|
||||
### "clip" property
|
||||
|
||||
The "clip" property (Clip constant) of the ClipShape type specifies the crop area.
|
||||
The "clip" property (Clip constant) of the ClipShapeProperty type specifies the crop area.
|
||||
There are 4 types of crop areas
|
||||
|
||||
#### inset
|
||||
|
||||
Rectangular cropping area. Created with the function:
|
||||
|
||||
func InsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipShape
|
||||
func InsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipShapeProperty
|
||||
|
||||
where top, right, bottom, left are the distance from respectively the top, right, bottom and left borders of the View
|
||||
to the cropping border of the same name; radius - sets the radii of the corners of the cropping area
|
||||
|
@ -1324,7 +1324,7 @@ The textual description of the rectangular cropping area is in the following for
|
|||
|
||||
Round cropping area. Created with the function:
|
||||
|
||||
func CircleClip(x, y, radius SizeUnit) ClipShape
|
||||
func CircleClip(x, y, radius SizeUnit) ClipShapeProperty
|
||||
|
||||
where x, y - coordinates of the center of the circle; radius - radius
|
||||
|
||||
|
@ -1336,7 +1336,7 @@ The textual description of the circular cropping area is in the following format
|
|||
|
||||
Elliptical cropping area. Created with the function:
|
||||
|
||||
func EllipseClip(x, y, rx, ry SizeUnit) ClipShape
|
||||
func EllipseClip(x, y, rx, ry SizeUnit) ClipShapeProperty
|
||||
|
||||
where x, y - coordinates of the center of the ellipse; rх - radius of the ellipse along the X axis; ry is the radius of the ellipse along the Y axis.
|
||||
|
||||
|
@ -1348,8 +1348,8 @@ The textual description of the elliptical clipping region is in the following fo
|
|||
|
||||
Polygonal cropping area. Created using functions:
|
||||
|
||||
func PolygonClip(points []any) ClipShape
|
||||
func PolygonPointsClip(points []SizeUnit) ClipShape
|
||||
func PolygonClip(points []any) ClipShapeProperty
|
||||
func PolygonPointsClip(points []SizeUnit) ClipShapeProperty
|
||||
|
||||
an array of corner points of the polygon is passed as an argument in the following order: x1, y1, x2, y2, …
|
||||
The elements of the argument to the PolygonClip function can be either text constants,
|
||||
|
|
|
@ -5,39 +5,120 @@ import (
|
|||
"strings"
|
||||
)
|
||||
|
||||
// ClipShape defines a View clipping area
|
||||
type ClipShape interface {
|
||||
type ClipShape string
|
||||
|
||||
const (
|
||||
InsetClip ClipShape = "inset"
|
||||
CircleClip ClipShape = "circle"
|
||||
EllipseClip ClipShape = "ellipse"
|
||||
PolygonClip ClipShape = "polygon"
|
||||
)
|
||||
|
||||
// ClipShapeProperty defines a View clipping area
|
||||
type ClipShapeProperty interface {
|
||||
Properties
|
||||
fmt.Stringer
|
||||
stringWriter
|
||||
|
||||
// Shape returns the clip shape type
|
||||
Shape() ClipShape
|
||||
cssStyle(session Session) string
|
||||
valid(session Session) bool
|
||||
}
|
||||
|
||||
type insetClip struct {
|
||||
type insetClipData struct {
|
||||
dataProperty
|
||||
}
|
||||
|
||||
type ellipseClip struct {
|
||||
type ellipseClipData struct {
|
||||
dataProperty
|
||||
}
|
||||
|
||||
type circleClip struct {
|
||||
type circleClipData struct {
|
||||
dataProperty
|
||||
}
|
||||
|
||||
type polygonClip struct {
|
||||
type polygonClipData struct {
|
||||
dataProperty
|
||||
}
|
||||
|
||||
// InsetClip creates a rectangle View clipping area.
|
||||
// NewClipShapeProperty creates ClipShapeProperty.
|
||||
//
|
||||
// The following properties can be used for shapes:
|
||||
//
|
||||
// InsetClip:
|
||||
// - "top" (Top) - offset (SizeUnit) from the top border of a View;
|
||||
// - "right" (Right) - offset (SizeUnit) from the right border of a View;
|
||||
// - "bottom" (Bottom) - offset (SizeUnit) from the bottom border of a View;
|
||||
// - "left" (Left) - offset (SizeUnit) from the left border of a View;
|
||||
// - "radius" (Radius) - corner radius (RadiusProperty).
|
||||
//
|
||||
// CircleClip:
|
||||
// - "x" (X) - x-axis position (SizeUnit) of the circle clip center;
|
||||
// - "y" (Y) - y-axis position (SizeUnit) of the circle clip center;
|
||||
// - "radius" (Radius) - radius (SizeUnit) of the circle clip center.
|
||||
//
|
||||
// EllipseClip:
|
||||
// - "x" (X) - x-axis position (SizeUnit) of the ellipse clip center;
|
||||
// - "y" (Y) - y-axis position (SizeUnit) of the ellipse clip center;
|
||||
// - "radius-x" (RadiusX) - x-axis radius (SizeUnit) of the ellipse clip center;
|
||||
// - "radius-y" (RadiusY) - y-axis radius (SizeUnit) of the ellipse clip center.
|
||||
//
|
||||
// PolygonClip:
|
||||
// - "points" (Points) - an array ([]SizeUnit) of corner points of the polygon in the following order: x1, y1, x2, y2, ….
|
||||
//
|
||||
// The function will return nil if no properties are specified, unsupported properties are specified, or at least one property has an invalid value.
|
||||
func NewClipShapeProperty(shape ClipShape, params Params) ClipShapeProperty {
|
||||
if len(params) == 0 {
|
||||
ErrorLog("No ClipShapeProperty params")
|
||||
return nil
|
||||
}
|
||||
|
||||
var result ClipShapeProperty
|
||||
|
||||
switch shape {
|
||||
case InsetClip:
|
||||
clip := new(insetClipData)
|
||||
clip.init()
|
||||
result = clip
|
||||
|
||||
case CircleClip:
|
||||
clip := new(circleClipData)
|
||||
clip.init()
|
||||
result = clip
|
||||
|
||||
case EllipseClip:
|
||||
clip := new(ellipseClipData)
|
||||
clip.init()
|
||||
result = clip
|
||||
|
||||
case PolygonClip:
|
||||
clip := new(polygonClipData)
|
||||
clip.init()
|
||||
result = clip
|
||||
|
||||
default:
|
||||
ErrorLog("Unknown ClipShape: " + string(shape))
|
||||
return nil
|
||||
}
|
||||
|
||||
for tag, value := range params {
|
||||
if !result.Set(tag, value) {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
// NewInsetClip creates a rectangle View clipping area.
|
||||
// - top - offset from the top border of a View;
|
||||
// - right - offset from the right border of a View;
|
||||
// - bottom - offset from the bottom border of a View;
|
||||
// - left - offset from the left border of a View;
|
||||
// - radius - corner radius, pass nil if you don't need to round corners
|
||||
func InsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipShape {
|
||||
clip := new(insetClip)
|
||||
func NewInsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipShapeProperty {
|
||||
clip := new(insetClipData)
|
||||
clip.init()
|
||||
clip.setRaw(Top, top)
|
||||
clip.setRaw(Right, right)
|
||||
|
@ -49,9 +130,12 @@ func InsetClip(top, right, bottom, left SizeUnit, radius RadiusProperty) ClipSha
|
|||
return clip
|
||||
}
|
||||
|
||||
// CircleClip creates a circle View clipping area.
|
||||
func CircleClip(x, y, radius SizeUnit) ClipShape {
|
||||
clip := new(circleClip)
|
||||
// NewCircleClip creates a circle View clipping area.
|
||||
// - x - x-axis position of the circle clip center;
|
||||
// - y - y-axis position of the circle clip center;
|
||||
// - radius - radius of the circle clip center.
|
||||
func NewCircleClip(x, y, radius SizeUnit) ClipShapeProperty {
|
||||
clip := new(circleClipData)
|
||||
clip.init()
|
||||
clip.setRaw(X, x)
|
||||
clip.setRaw(Y, y)
|
||||
|
@ -59,9 +143,13 @@ func CircleClip(x, y, radius SizeUnit) ClipShape {
|
|||
return clip
|
||||
}
|
||||
|
||||
// EllipseClip creates a ellipse View clipping area.
|
||||
func EllipseClip(x, y, rx, ry SizeUnit) ClipShape {
|
||||
clip := new(ellipseClip)
|
||||
// NewEllipseClip creates a ellipse View clipping area.
|
||||
// - x - x-axis position of the ellipse clip center;
|
||||
// - y - y-axis position of the ellipse clip center;
|
||||
// - rx - x-axis radius of the ellipse clip center;
|
||||
// - ry - y-axis radius of the ellipse clip center.
|
||||
func NewEllipseClip(x, y, rx, ry SizeUnit) ClipShapeProperty {
|
||||
clip := new(ellipseClipData)
|
||||
clip.init()
|
||||
clip.setRaw(X, x)
|
||||
clip.setRaw(Y, y)
|
||||
|
@ -70,32 +158,34 @@ func EllipseClip(x, y, rx, ry SizeUnit) ClipShape {
|
|||
return clip
|
||||
}
|
||||
|
||||
// PolygonClip creates a polygon View clipping area.
|
||||
// NewPolygonClip creates a polygon View clipping area.
|
||||
// - points - an array of corner points of the polygon in the following order: x1, y1, x2, y2, …
|
||||
//
|
||||
// The elements of the function argument can be or text constants,
|
||||
// or the text representation of SizeUnit, or elements of SizeUnit type.
|
||||
func PolygonClip(points []any) ClipShape {
|
||||
clip := new(polygonClip)
|
||||
func NewPolygonClip(points []any) ClipShapeProperty {
|
||||
clip := new(polygonClipData)
|
||||
clip.init()
|
||||
if polygonClipSet(clip, Points, points) != nil {
|
||||
if polygonClipDataSet(clip, Points, points) != nil {
|
||||
return clip
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// PolygonPointsClip creates a polygon View clipping area.
|
||||
func PolygonPointsClip(points []SizeUnit) ClipShape {
|
||||
clip := new(polygonClip)
|
||||
// NewPolygonPointsClip creates a polygon View clipping area.
|
||||
// - points - an array of corner points of the polygon in the following order: x1, y1, x2, y2, …
|
||||
func NewPolygonPointsClip(points []SizeUnit) ClipShapeProperty {
|
||||
clip := new(polygonClipData)
|
||||
clip.init()
|
||||
if polygonClipSet(clip, Points, points) != nil {
|
||||
if polygonClipDataSet(clip, Points, points) != nil {
|
||||
return clip
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (clip *insetClip) init() {
|
||||
func (clip *insetClipData) init() {
|
||||
clip.dataProperty.init()
|
||||
clip.set = insetClipSet
|
||||
clip.set = insetClipDataSet
|
||||
clip.supportedProperties = []PropertyName{
|
||||
Top, Right, Bottom, Left, Radius,
|
||||
RadiusX, RadiusY, RadiusTopLeft, RadiusTopLeftX, RadiusTopLeftY,
|
||||
|
@ -105,7 +195,11 @@ func (clip *insetClip) init() {
|
|||
}
|
||||
}
|
||||
|
||||
func insetClipSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
func (clip *insetClipData) Shape() ClipShape {
|
||||
return InsetClip
|
||||
}
|
||||
|
||||
func insetClipDataSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
switch tag {
|
||||
case Top, Right, Bottom, Left:
|
||||
return setSizeProperty(properties, tag, value)
|
||||
|
@ -127,11 +221,11 @@ func insetClipSet(properties Properties, tag PropertyName, value any) []Property
|
|||
return nil
|
||||
}
|
||||
|
||||
func (clip *insetClip) String() string {
|
||||
func (clip *insetClipData) String() string {
|
||||
return runStringWriter(clip)
|
||||
}
|
||||
|
||||
func (clip *insetClip) writeString(buffer *strings.Builder, indent string) {
|
||||
func (clip *insetClipData) writeString(buffer *strings.Builder, indent string) {
|
||||
buffer.WriteString("inset { ")
|
||||
comma := false
|
||||
for _, tag := range []PropertyName{Top, Right, Bottom, Left, Radius} {
|
||||
|
@ -149,7 +243,7 @@ func (clip *insetClip) writeString(buffer *strings.Builder, indent string) {
|
|||
buffer.WriteString(" }")
|
||||
}
|
||||
|
||||
func (clip *insetClip) cssStyle(session Session) string {
|
||||
func (clip *insetClipData) cssStyle(session Session) string {
|
||||
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
|
@ -171,7 +265,7 @@ func (clip *insetClip) cssStyle(session Session) string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
func (clip *insetClip) valid(session Session) bool {
|
||||
func (clip *insetClipData) valid(session Session) bool {
|
||||
for _, tag := range []PropertyName{Top, Right, Bottom, Left, Radius, RadiusX, RadiusY} {
|
||||
if value, ok := sizeProperty(clip, tag, session); ok && value.Type != Auto && value.Value != 0 {
|
||||
return true
|
||||
|
@ -180,13 +274,17 @@ func (clip *insetClip) valid(session Session) bool {
|
|||
return false
|
||||
}
|
||||
|
||||
func (clip *circleClip) init() {
|
||||
func (clip *circleClipData) init() {
|
||||
clip.dataProperty.init()
|
||||
clip.set = circleClipSet
|
||||
clip.set = circleClipDataSet
|
||||
clip.supportedProperties = []PropertyName{X, Y, Radius}
|
||||
}
|
||||
|
||||
func circleClipSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
func (clip *circleClipData) Shape() ClipShape {
|
||||
return CircleClip
|
||||
}
|
||||
|
||||
func circleClipDataSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
switch tag {
|
||||
case X, Y, Radius:
|
||||
return setSizeProperty(properties, tag, value)
|
||||
|
@ -196,11 +294,11 @@ func circleClipSet(properties Properties, tag PropertyName, value any) []Propert
|
|||
return nil
|
||||
}
|
||||
|
||||
func (clip *circleClip) String() string {
|
||||
func (clip *circleClipData) String() string {
|
||||
return runStringWriter(clip)
|
||||
}
|
||||
|
||||
func (clip *circleClip) writeString(buffer *strings.Builder, indent string) {
|
||||
func (clip *circleClipData) writeString(buffer *strings.Builder, indent string) {
|
||||
buffer.WriteString("circle { ")
|
||||
comma := false
|
||||
for _, tag := range []PropertyName{Radius, X, Y} {
|
||||
|
@ -218,7 +316,7 @@ func (clip *circleClip) writeString(buffer *strings.Builder, indent string) {
|
|||
buffer.WriteString(" }")
|
||||
}
|
||||
|
||||
func (clip *circleClip) cssStyle(session Session) string {
|
||||
func (clip *circleClipData) cssStyle(session Session) string {
|
||||
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
|
@ -239,20 +337,24 @@ func (clip *circleClip) cssStyle(session Session) string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
func (clip *circleClip) valid(session Session) bool {
|
||||
func (clip *circleClipData) valid(session Session) bool {
|
||||
if value, ok := sizeProperty(clip, Radius, session); ok && value.Value == 0 {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
func (clip *ellipseClip) init() {
|
||||
func (clip *ellipseClipData) init() {
|
||||
clip.dataProperty.init()
|
||||
clip.set = ellipseClipSet
|
||||
clip.set = ellipseClipDataSet
|
||||
clip.supportedProperties = []PropertyName{X, Y, Radius, RadiusX, RadiusY}
|
||||
}
|
||||
|
||||
func ellipseClipSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
func (clip *ellipseClipData) Shape() ClipShape {
|
||||
return EllipseClip
|
||||
}
|
||||
|
||||
func ellipseClipDataSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
switch tag {
|
||||
case X, Y, RadiusX, RadiusY:
|
||||
return setSizeProperty(properties, tag, value)
|
||||
|
@ -269,11 +371,11 @@ func ellipseClipSet(properties Properties, tag PropertyName, value any) []Proper
|
|||
return nil
|
||||
}
|
||||
|
||||
func (clip *ellipseClip) String() string {
|
||||
func (clip *ellipseClipData) String() string {
|
||||
return runStringWriter(clip)
|
||||
}
|
||||
|
||||
func (clip *ellipseClip) writeString(buffer *strings.Builder, indent string) {
|
||||
func (clip *ellipseClipData) writeString(buffer *strings.Builder, indent string) {
|
||||
buffer.WriteString("ellipse { ")
|
||||
comma := false
|
||||
for _, tag := range []PropertyName{RadiusX, RadiusY, X, Y} {
|
||||
|
@ -291,7 +393,7 @@ func (clip *ellipseClip) writeString(buffer *strings.Builder, indent string) {
|
|||
buffer.WriteString(" }")
|
||||
}
|
||||
|
||||
func (clip *ellipseClip) cssStyle(session Session) string {
|
||||
func (clip *ellipseClipData) cssStyle(session Session) string {
|
||||
|
||||
buffer := allocStringBuilder()
|
||||
defer freeStringBuilder(buffer)
|
||||
|
@ -315,19 +417,23 @@ func (clip *ellipseClip) cssStyle(session Session) string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
func (clip *ellipseClip) valid(session Session) bool {
|
||||
func (clip *ellipseClipData) valid(session Session) bool {
|
||||
rx, _ := sizeProperty(clip, RadiusX, session)
|
||||
ry, _ := sizeProperty(clip, RadiusY, session)
|
||||
return rx.Value != 0 && ry.Value != 0
|
||||
}
|
||||
|
||||
func (clip *polygonClip) init() {
|
||||
func (clip *polygonClipData) init() {
|
||||
clip.dataProperty.init()
|
||||
clip.set = polygonClipSet
|
||||
clip.set = polygonClipDataSet
|
||||
clip.supportedProperties = []PropertyName{Points}
|
||||
}
|
||||
|
||||
func polygonClipSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
func (clip *polygonClipData) Shape() ClipShape {
|
||||
return PolygonClip
|
||||
}
|
||||
|
||||
func polygonClipDataSet(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
if Points == tag {
|
||||
switch value := value.(type) {
|
||||
case []any:
|
||||
|
@ -385,11 +491,11 @@ func polygonClipSet(properties Properties, tag PropertyName, value any) []Proper
|
|||
return nil
|
||||
}
|
||||
|
||||
func (clip *polygonClip) String() string {
|
||||
func (clip *polygonClipData) String() string {
|
||||
return runStringWriter(clip)
|
||||
}
|
||||
|
||||
func (clip *polygonClip) points() []any {
|
||||
func (clip *polygonClipData) points() []any {
|
||||
if value := clip.getRaw(Points); value != nil {
|
||||
if points, ok := value.([]any); ok {
|
||||
return points
|
||||
|
@ -398,7 +504,7 @@ func (clip *polygonClip) points() []any {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (clip *polygonClip) writeString(buffer *strings.Builder, indent string) {
|
||||
func (clip *polygonClipData) writeString(buffer *strings.Builder, indent string) {
|
||||
|
||||
buffer.WriteString("inset { ")
|
||||
|
||||
|
@ -417,7 +523,7 @@ func (clip *polygonClip) writeString(buffer *strings.Builder, indent string) {
|
|||
buffer.WriteRune('}')
|
||||
}
|
||||
|
||||
func (clip *polygonClip) cssStyle(session Session) string {
|
||||
func (clip *polygonClipData) cssStyle(session Session) string {
|
||||
|
||||
points := clip.points()
|
||||
count := len(points)
|
||||
|
@ -459,47 +565,47 @@ func (clip *polygonClip) cssStyle(session Session) string {
|
|||
return buffer.String()
|
||||
}
|
||||
|
||||
func (clip *polygonClip) valid(session Session) bool {
|
||||
func (clip *polygonClipData) valid(session Session) bool {
|
||||
return len(clip.points()) > 0
|
||||
}
|
||||
|
||||
func parseClipShape(obj DataObject) ClipShape {
|
||||
func parseClipShapeProperty(obj DataObject) ClipShapeProperty {
|
||||
switch obj.Tag() {
|
||||
case "inset":
|
||||
clip := new(insetClip)
|
||||
clip := new(insetClipData)
|
||||
clip.init()
|
||||
for _, tag := range []PropertyName{Top, Right, Bottom, Left, Radius, RadiusX, RadiusY} {
|
||||
if value, ok := obj.PropertyValue(string(tag)); ok {
|
||||
insetClipSet(clip, tag, value)
|
||||
insetClipDataSet(clip, tag, value)
|
||||
}
|
||||
}
|
||||
return clip
|
||||
|
||||
case "circle":
|
||||
clip := new(ellipseClip)
|
||||
clip := new(circleClipData)
|
||||
clip.init()
|
||||
for _, tag := range []PropertyName{X, Y, Radius} {
|
||||
if value, ok := obj.PropertyValue(string(tag)); ok {
|
||||
circleClipSet(clip, tag, value)
|
||||
circleClipDataSet(clip, tag, value)
|
||||
}
|
||||
}
|
||||
return clip
|
||||
|
||||
case "ellipse":
|
||||
clip := new(ellipseClip)
|
||||
clip := new(ellipseClipData)
|
||||
clip.init()
|
||||
for _, tag := range []PropertyName{X, Y, RadiusX, RadiusY} {
|
||||
if value, ok := obj.PropertyValue(string(tag)); ok {
|
||||
ellipseClipSet(clip, tag, value)
|
||||
ellipseClipDataSet(clip, tag, value)
|
||||
}
|
||||
}
|
||||
return clip
|
||||
|
||||
case "polygon":
|
||||
clip := new(ellipseClip)
|
||||
clip := new(polygonClipData)
|
||||
clip.init()
|
||||
if value, ok := obj.PropertyValue(string(Points)); ok {
|
||||
polygonClipSet(clip, Points, value)
|
||||
polygonClipDataSet(clip, Points, value)
|
||||
}
|
||||
return clip
|
||||
}
|
||||
|
@ -507,9 +613,9 @@ func parseClipShape(obj DataObject) ClipShape {
|
|||
return nil
|
||||
}
|
||||
|
||||
func setClipShapeProperty(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
func setClipShapePropertyProperty(properties Properties, tag PropertyName, value any) []PropertyName {
|
||||
switch value := value.(type) {
|
||||
case ClipShape:
|
||||
case ClipShapeProperty:
|
||||
properties.setRaw(tag, value)
|
||||
return []PropertyName{tag}
|
||||
|
||||
|
@ -520,21 +626,21 @@ func setClipShapeProperty(properties Properties, tag PropertyName, value any) []
|
|||
}
|
||||
|
||||
if obj := NewDataObject(value); obj == nil {
|
||||
if clip := parseClipShape(obj); clip != nil {
|
||||
if clip := parseClipShapeProperty(obj); clip != nil {
|
||||
properties.setRaw(tag, clip)
|
||||
return []PropertyName{tag}
|
||||
}
|
||||
}
|
||||
|
||||
case DataObject:
|
||||
if clip := parseClipShape(value); clip != nil {
|
||||
if clip := parseClipShapeProperty(value); clip != nil {
|
||||
properties.setRaw(tag, clip)
|
||||
return []PropertyName{tag}
|
||||
}
|
||||
|
||||
case DataValue:
|
||||
if value.IsObject() {
|
||||
if clip := parseClipShape(value.Object()); clip != nil {
|
||||
if clip := parseClipShapeProperty(value.Object()); clip != nil {
|
||||
properties.setRaw(tag, clip)
|
||||
return []PropertyName{tag}
|
||||
}
|
||||
|
@ -545,16 +651,16 @@ func setClipShapeProperty(properties Properties, tag PropertyName, value any) []
|
|||
return nil
|
||||
}
|
||||
|
||||
func getClipShape(prop Properties, tag PropertyName, session Session) ClipShape {
|
||||
func getClipShapeProperty(prop Properties, tag PropertyName, session Session) ClipShapeProperty {
|
||||
if value := prop.getRaw(tag); value != nil {
|
||||
switch value := value.(type) {
|
||||
case ClipShape:
|
||||
case ClipShapeProperty:
|
||||
return value
|
||||
|
||||
case string:
|
||||
if text, ok := session.resolveConstants(value); ok {
|
||||
if obj := NewDataObject(text); obj == nil {
|
||||
return parseClipShape(obj)
|
||||
return parseClipShapeProperty(obj)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -565,9 +671,9 @@ func getClipShape(prop Properties, tag PropertyName, session Session) ClipShape
|
|||
|
||||
// GetClip returns a View clipping area.
|
||||
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
|
||||
func GetClip(view View, subviewID ...string) ClipShape {
|
||||
func GetClip(view View, subviewID ...string) ClipShapeProperty {
|
||||
if view = getSubview(view, subviewID); view != nil {
|
||||
return getClipShape(view, Clip, view.Session())
|
||||
return getClipShapeProperty(view, Clip, view.Session())
|
||||
}
|
||||
|
||||
return nil
|
||||
|
@ -575,9 +681,9 @@ func GetClip(view View, subviewID ...string) ClipShape {
|
|||
|
||||
// GetShapeOutside returns a shape around which adjacent inline content.
|
||||
// If the second argument (subviewID) is not specified or it is "" then a top position of the first argument (view) is returned
|
||||
func GetShapeOutside(view View, subviewID ...string) ClipShape {
|
||||
func GetShapeOutside(view View, subviewID ...string) ClipShapeProperty {
|
||||
if view = getSubview(view, subviewID); view != nil {
|
||||
return getClipShape(view, ShapeOutside, view.Session())
|
||||
return getClipShapeProperty(view, ShapeOutside, view.Session())
|
||||
}
|
||||
|
||||
return nil
|
8
popup.go
8
popup.go
|
@ -381,28 +381,28 @@ func (arrow *popupArrow) createView(popupView View) View {
|
|||
case TopArrow:
|
||||
params[Row] = 0
|
||||
params[Column] = 1
|
||||
params[Clip] = PolygonClip([]any{"0%", "100%", "50%", "0%", "100%", "100%"})
|
||||
params[Clip] = NewPolygonClip([]any{"0%", "100%", "50%", "0%", "100%", "100%"})
|
||||
params[Width] = arrow.width
|
||||
params[Height] = arrow.size
|
||||
|
||||
case RightArrow:
|
||||
params[Row] = 1
|
||||
params[Column] = 0
|
||||
params[Clip] = PolygonClip([]any{"0%", "0%", "100%", "50%", "0%", "100%"})
|
||||
params[Clip] = NewPolygonClip([]any{"0%", "0%", "100%", "50%", "0%", "100%"})
|
||||
params[Width] = arrow.size
|
||||
params[Height] = arrow.width
|
||||
|
||||
case BottomArrow:
|
||||
params[Row] = 0
|
||||
params[Column] = 1
|
||||
params[Clip] = PolygonClip([]any{"0%", "0%", "50%", "100%", "100%", "0%"})
|
||||
params[Clip] = NewPolygonClip([]any{"0%", "0%", "50%", "100%", "100%", "0%"})
|
||||
params[Width] = arrow.width
|
||||
params[Height] = arrow.size
|
||||
|
||||
case LeftArrow:
|
||||
params[Row] = 1
|
||||
params[Column] = 0
|
||||
params[Clip] = PolygonClip([]any{"100%", "0%", "0%", "50%", "100%", "100%"})
|
||||
params[Clip] = NewPolygonClip([]any{"100%", "0%", "0%", "50%", "100%", "100%"})
|
||||
params[Width] = arrow.size
|
||||
params[Height] = arrow.width
|
||||
}
|
||||
|
|
|
@ -228,7 +228,7 @@ const (
|
|||
|
||||
// Left is the constant for "left" property tag.
|
||||
//
|
||||
// Used by View, BoundsProperty, ClipShape.
|
||||
// Used by View, BoundsProperty, ClipShapeProperty.
|
||||
//
|
||||
// # Usage in View:
|
||||
//
|
||||
|
@ -248,7 +248,7 @@ const (
|
|||
// Internal type is SizeUnit, other types converted to it during assignment.
|
||||
// See [SizeUnit] description for more details.
|
||||
//
|
||||
// # Usage in ClipShape:
|
||||
// # Usage in ClipShapeProperty:
|
||||
//
|
||||
// Specifies the left border position of inset clip shape.
|
||||
//
|
||||
|
@ -260,7 +260,7 @@ const (
|
|||
|
||||
// Right is the constant for "right" property tag.
|
||||
//
|
||||
// Used by View, BoundsProperty, ClipShape.
|
||||
// Used by View, BoundsProperty, ClipShapeProperty.
|
||||
//
|
||||
// # Usage in View:
|
||||
//
|
||||
|
@ -280,7 +280,7 @@ const (
|
|||
// Internal type is SizeUnit, other types converted to it during assignment.
|
||||
// See [SizeUnit] description for more details.
|
||||
//
|
||||
// # Usage in ClipShape:
|
||||
// # Usage in ClipShapeProperty:
|
||||
//
|
||||
// Specifies the right border position of inset clip shape.
|
||||
//
|
||||
|
@ -292,7 +292,7 @@ const (
|
|||
|
||||
// Top is the constant for "top" property tag.
|
||||
//
|
||||
// Used by View, BoundsProperty, ClipShape.
|
||||
// Used by View, BoundsProperty, ClipShapeProperty.
|
||||
//
|
||||
// # Usage in View:
|
||||
//
|
||||
|
@ -312,7 +312,7 @@ const (
|
|||
// Internal type is SizeUnit, other types converted to it during assignment.
|
||||
// See [SizeUnit] description for more details.
|
||||
//
|
||||
// # Usage in ClipShape:
|
||||
// # Usage in ClipShapeProperty:
|
||||
//
|
||||
// Specifies the top border position of inset clip shape.
|
||||
//
|
||||
|
@ -324,7 +324,7 @@ const (
|
|||
|
||||
// Bottom is the constant for "bottom" property tag.
|
||||
//
|
||||
// Used by View, BoundsProperty, ClipShape.
|
||||
// Used by View, BoundsProperty, ClipShapeProperty.
|
||||
//
|
||||
// # Usage in View:
|
||||
//
|
||||
|
@ -344,7 +344,7 @@ const (
|
|||
// Internal type is SizeUnit, other types converted to it during assignment.
|
||||
// See [SizeUnit] description for more details.
|
||||
//
|
||||
// # Usage in ClipShape:
|
||||
// # Usage in ClipShapeProperty:
|
||||
//
|
||||
// Specifies the bottom border position of inset clip shape.
|
||||
//
|
||||
|
@ -2526,15 +2526,15 @@ const (
|
|||
// Used by View.
|
||||
// Creates a clipping region that sets what part of a view should be shown.
|
||||
//
|
||||
// Supported types: ClipShape, string.
|
||||
// Supported types: ClipShapeProperty, string.
|
||||
//
|
||||
// Internal type is ClipShape, other types converted to it during assignment.
|
||||
// See ClipShape description for more details.
|
||||
// Internal type is ClipShapeProperty, other types converted to it during assignment.
|
||||
// See ClipShapeProperty description for more details.
|
||||
Clip PropertyName = "clip"
|
||||
|
||||
// Points is the constant for "points" property tag.
|
||||
//
|
||||
// Used by ClipShape.
|
||||
// Used by ClipShapeProperty.
|
||||
// Points which describe polygon clip area. Values are in a sequence of pair like: x1, y1, x2, y2 ...
|
||||
//
|
||||
// Supported types: []SizeUnit, string.
|
||||
|
@ -2547,10 +2547,10 @@ const (
|
|||
// inline content should wrap. By default, inline content wraps around its margin box. Property provides a way to
|
||||
// customize this wrapping, making it possible to wrap text around complex objects rather than simple boxes.
|
||||
//
|
||||
// Supported types: ClipShape, string.
|
||||
// Supported types: ClipShapeProperty, string.
|
||||
//
|
||||
// Internal type is ClipShape, other types converted to it during assignment.
|
||||
// See ClipShape description for more details.
|
||||
// Internal type is ClipShapeProperty, other types converted to it during assignment.
|
||||
// See ClipShapeProperty description for more details.
|
||||
ShapeOutside PropertyName = "shape-outside"
|
||||
|
||||
// Float is the constant for "float" property tag.
|
||||
|
|
24
radius.go
24
radius.go
|
@ -9,7 +9,7 @@ import (
|
|||
const (
|
||||
// Radius is the constant for "radius" property tag.
|
||||
//
|
||||
// Used by View, BackgroundElement, ClipShape.
|
||||
// Used by View, BackgroundElement, ClipShapeProperty.
|
||||
//
|
||||
// Usage in View:
|
||||
// Specifies the corners rounding radius of an element's outer border edge.
|
||||
|
@ -30,7 +30,7 @@ const (
|
|||
// Usage in BackgroundElement:
|
||||
// Same as "radial-gradient-radius".
|
||||
//
|
||||
// Usage in ClipShape:
|
||||
// Usage in ClipShapeProperty:
|
||||
// Specifies the radius of the corners or the radius of the cropping area.
|
||||
//
|
||||
// Supported types: SizeUnit, SizeFunc, string, float, int.
|
||||
|
@ -41,7 +41,7 @@ const (
|
|||
|
||||
// RadiusX is the constant for "radius-x" property tag.
|
||||
//
|
||||
// Used by View, ClipShape.
|
||||
// Used by View, ClipShapeProperty.
|
||||
//
|
||||
// Usage in View:
|
||||
// Specifies the x-axis corners elliptic rounding radius of an element's outer border edge.
|
||||
|
@ -51,7 +51,7 @@ const (
|
|||
// Internal type is SizeUnit, other types converted to it during assignment.
|
||||
// See SizeUnit description for more details.
|
||||
//
|
||||
// Usage in ClipShape:
|
||||
// Usage in ClipShapeProperty:
|
||||
// Specifies the x-axis corners elliptic rounding radius of the elliptic clip shape.
|
||||
//
|
||||
// Supported types: SizeUnit, SizeFunc, string, float, int.
|
||||
|
@ -62,7 +62,7 @@ const (
|
|||
|
||||
// RadiusY is the constant for "radius-y" property tag.
|
||||
//
|
||||
// Used by View, ClipShape.
|
||||
// Used by View, ClipShapeProperty.
|
||||
//
|
||||
// Usage in View:
|
||||
// Specifies the y-axis corners elliptic rounding radius of an element's outer border edge.
|
||||
|
@ -72,7 +72,7 @@ const (
|
|||
// Internal type is SizeUnit, other types converted to it during assignment.
|
||||
// See SizeUnit description for more details.
|
||||
//
|
||||
// Usage in ClipShape:
|
||||
// Usage in ClipShapeProperty:
|
||||
// Specifies the y-axis corners elliptic rounding radius of of the elliptic clip shape.
|
||||
//
|
||||
// Supported types: SizeUnit, SizeFunc, string, float, int.
|
||||
|
@ -215,10 +215,10 @@ const (
|
|||
|
||||
// X is the constant for "x" property tag.
|
||||
//
|
||||
// Used by ClipShape, RadiusProperty.
|
||||
// Used by ClipShapeProperty, RadiusProperty.
|
||||
//
|
||||
// Usage in ClipShape:
|
||||
// Specifies x-axis position of the clip shape.
|
||||
// Usage in ClipShapeProperty:
|
||||
// Specifies x-axis position of the clip shape center.
|
||||
//
|
||||
// Supported types: SizeUnit, SizeFunc, string, float, int.
|
||||
//
|
||||
|
@ -236,10 +236,10 @@ const (
|
|||
|
||||
// Y is the constant for "y" property tag.
|
||||
//
|
||||
// Used by ClipShape, RadiusProperty.
|
||||
// Used by ClipShapeProperty, RadiusProperty.
|
||||
//
|
||||
// Usage in ClipShape:
|
||||
// Specifies y-axis position of the clip shape.
|
||||
// Usage in ClipShapeProperty:
|
||||
// Specifies y-axis position of the clip shape center.
|
||||
//
|
||||
// Supported types: SizeUnit, SizeFunc, string, float, int.
|
||||
//
|
||||
|
|
4
view.go
4
view.go
|
@ -560,14 +560,14 @@ func (view *viewData) propertyChanged(tag PropertyName) {
|
|||
}
|
||||
|
||||
case Clip:
|
||||
if clip := getClipShape(view, Clip, session); clip != nil && clip.valid(session) {
|
||||
if clip := getClipShapeProperty(view, Clip, session); clip != nil && clip.valid(session) {
|
||||
session.updateCSSProperty(htmlID, `clip-path`, clip.cssStyle(session))
|
||||
} else {
|
||||
session.updateCSSProperty(htmlID, `clip-path`, "none")
|
||||
}
|
||||
|
||||
case ShapeOutside:
|
||||
if clip := getClipShape(view, ShapeOutside, session); clip != nil && clip.valid(session) {
|
||||
if clip := getClipShapeProperty(view, ShapeOutside, session); clip != nil && clip.valid(session) {
|
||||
session.updateCSSProperty(htmlID, string(ShapeOutside), clip.cssStyle(session))
|
||||
} else {
|
||||
session.updateCSSProperty(htmlID, string(ShapeOutside), "none")
|
||||
|
|
|
@ -382,11 +382,11 @@ func (style *viewStyle) cssViewStyle(builder cssBuilder, session Session) {
|
|||
|
||||
style.writeViewTransformCSS(builder, session)
|
||||
|
||||
if clip := getClipShape(style, Clip, session); clip != nil && clip.valid(session) {
|
||||
if clip := getClipShapeProperty(style, Clip, session); clip != nil && clip.valid(session) {
|
||||
builder.add(`clip-path`, clip.cssStyle(session))
|
||||
}
|
||||
|
||||
if clip := getClipShape(style, ShapeOutside, session); clip != nil && clip.valid(session) {
|
||||
if clip := getClipShapeProperty(style, ShapeOutside, session); clip != nil && clip.valid(session) {
|
||||
builder.add(`shape-outside`, clip.cssStyle(session))
|
||||
}
|
||||
|
||||
|
|
|
@ -412,7 +412,7 @@ func viewStyleSet(style Properties, tag PropertyName, value any) []PropertyName
|
|||
return nil
|
||||
|
||||
case Clip, ShapeOutside:
|
||||
return setClipShapeProperty(style, tag, value)
|
||||
return setClipShapePropertyProperty(style, tag, value)
|
||||
|
||||
case Filter, BackdropFilter:
|
||||
return setFilterProperty(style, tag, value)
|
||||
|
|
Loading…
Reference in New Issue