Rename ViewShadow interface

This commit is contained in:
Alexei Anoshenko 2024-12-03 10:25:55 +03:00
parent 5efa2f5ae8
commit 32141b996a
9 changed files with 139 additions and 117 deletions

View File

@ -1,9 +1,22 @@
# v0.18.0
* Renamed:
Transform interface -> TransformProperty
NewTransform function -> NewTransformProperty
TransformTag constant -> Transform.
"origin-x" property -> "transform-origin-x"
"origin-y" property -> "transform-origin-y"
"origin-z" property -> "transform-origin-z"
GetOrigin function -> GetTransformOrigin.
BorderBoxClip constant -> BorderBox
PaddingBoxClip constant -> PaddingBox
ContentBoxClip constant -> ContentBox.
ViewShadow interface -> ShadowProperty
NewViewShadow function -> NewShadow
NewInsetViewShadow function -> NewInsetShadow
NewShadowWithParams function -> NewShadowProperty
* Property name type changed from string to PropertyName.
* Transform interface renamed to TransformProperty. NewTransform function renamed to NewTransformProperty. TransformTag constant renamed to Transform.
* "origin-x", "origin-y", and "origin-z" properties renamed to "transform-origin-x", "transform-origin-y", and "transform-origin-z".
* GetOrigin function renamed to GetTransformOrigin.
* Changed Push, Pop, MoveToFront, and MoveToFrontByID methods of StackLayout interface.
* Removed DefaultAnimation, StartToEndAnimation, EndToStartAnimation, TopDownAnimation, and BottomUpAnimation constants.
* Added "push-transform", "push-duration", "push-timing", and "move-to-front-animation" StackLayout properties.
@ -13,7 +26,6 @@
* Added GetPushTransform, GetPushDuration, GetPushTiming, and IsMoveToFrontAnimation functions.
* Added "mask", "mask-clip", "mask-origin", and "background-origin" properties.
* Added GetBackground, GetMask, GetBackgroundClip,GetBackgroundOrigin, GetMaskClip, and GetMaskOrigin functions.
* Renamed BorderBoxClip, PaddingBoxClip, and ContentBoxClip constants to BorderBox, PaddingBox, and ContentBox.
* Added LineJoin type. Type of constants MiterJoin, RoundJoin, and BevelJoin changed to LineJoin. Type of Canvas.SetLineJoin function argument changed to LineJoin.
* Added LineCap type. Type of constants ButtCap, RoundCap, and SquareCap changed to LineCap. Type of Canvas.SetLineCap function argument changed to LineCap.

View File

@ -1047,7 +1047,7 @@ RadiusProperty, а не структура BoxRadius. Получить стру
### Свойство "shadow"
Свойство "shadow" позволяет задать тени для View. Теней может быть несколько. Тень описывается
с помощью интерфейса ViewShadow расширяющего интерфейс Properties (см. выше). У тени имеются следующие свойства:
с помощью интерфейса ShadowProperty расширяющего интерфейс Properties (см. выше). У тени имеются следующие свойства:
| Свойство | Константа | Тип | Описание |
|-----------------|---------------|----------|---------------------------------------------------------------|
@ -1058,13 +1058,13 @@ RadiusProperty, а не структура BoxRadius. Получить стру
| "blur" | BlurRadius | float | Радиус размытия тени. Значение должно быть >= 0 |
| "spread-radius" | SpreadRadius | float | Увеличение тени. Значение > 0 увеличивает тень, < 0 уменьшает |
Для создания ViewShadow используются три функции:
Для создания ShadowProperty используются три функции:
func NewViewShadow(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ViewShadow
func NewInsetViewShadow(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ViewShadow
func NewShadowWithParams(params Params) ViewShadow
func NewShadowProperty(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ShadowProperty
func NewInsetShadowProperty(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ShadowProperty
func NewShadowWithParams(params Params) ShadowProperty
Функция NewViewShadow создает внешнюю тень (Inset == false), NewInsetViewShadow - внутреннюю
Функция NewShadowProperty создает внешнюю тень (Inset == false), NewInsetShadowProperty - внутреннюю
(Inset == true).
Функция NewShadowWithParams используется когда в качестве параметров необходимо использовать
константы. Например:
@ -1075,10 +1075,10 @@ RadiusProperty, а не структура BoxRadius. Получить стру
rui.Dilation : 16.0,
})
В качестве значения свойству "shadow" может быть присвоено ViewShadow, массив ViewShadow,
текстовое представление ViewShadow.
В качестве значения свойству "shadow" может быть присвоено ShadowProperty, массив ShadowProperty,
текстовое представление ShadowProperty.
Текстовое представление ViewShadow имеет следующий формат:
Текстовое представление ShadowProperty имеет следующий формат:
_{ color = <цвет> [, x-offset = <смещение>] [, y-offset = <смещение>] [, blur = <радиус>]
[, spread-radius = <увеличение>] [, inset = <тип>] }
@ -1086,7 +1086,7 @@ RadiusProperty, а не структура BoxRadius. Получить стру
Получить значение данного свойства можно с помощью функции
func GetViewShadows(view View, subviewID ...string) []ViewShadow
func GetShadowPropertys(view View, subviewID ...string) []ShadowProperty
Если тень не задана, то данная функция вернет пустой массив
@ -1447,7 +1447,7 @@ radius необходимо передать nil
| "blur" | Blur | float64 0…10000px | Размытие по Гауссу |
| "brightness" | Brightness | float64 0…10000% | Изменение яркости |
| "contrast" | Contrast | float64 0…10000% | Изменение контрастности |
| "drop-shadow" | DropShadow | []ViewShadow | Добавление тени |
| "drop-shadow" | DropShadow | []ShadowProperty | Добавление тени |
| "grayscale" | Grayscale | float64 0…100% | Преобразование к оттенкам серого |
| "hue-rotate" | HueRotate | AngleUnit | Вращение оттенка |
| "invert" | Invert | float64 0…100% | Инвертирование цветов |
@ -1704,14 +1704,14 @@ radius необходимо передать nil
#### Свойство "text-shadow"
Свойство "text-shadow" позволяет задать тени для текста. Теней может быть несколько. Тень описывается
с помощью интерфейса ViewShadow (см. выше, раздел "Свойство 'shadow'"). Для тени текста используются только
с помощью интерфейса ShadowProperty (см. выше, раздел "Свойство 'shadow'"). Для тени текста используются только
Свойства "color", "x-offset", "y-offset" и "blur". Свойства "inset" и "spread-radius" игнорируются (т.е. их
задание не является ошибкой, просто никакого влияния на тень текста они не имеют).
Для создания ViewShadow для тени текста используются функции:
Для создания ShadowProperty для тени текста используются функции:
func NewTextShadow(offsetX, offsetY, blurRadius SizeUnit, color Color) ViewShadow
func NewShadowWithParams(params Params) ViewShadow
func NewTextShadow(offsetX, offsetY, blurRadius SizeUnit, color Color) ShadowProperty
func NewShadowWithParams(params Params) ShadowProperty
Функция NewShadowWithParams используется когда в качестве параметров необходимо использовать
константы. Например:
@ -1721,12 +1721,12 @@ radius необходимо передать nil
rui.BlurRadius : 8.0,
})
В качестве значения свойству "text-shadow" может быть присвоено ViewShadow, массив ViewShadow,
текстовое представление ViewShadow (см. выше, раздел "Свойство 'shadow'").
В качестве значения свойству "text-shadow" может быть присвоено ShadowProperty, массив ShadowProperty,
текстовое представление ShadowProperty (см. выше, раздел "Свойство 'shadow'").
Получить значение данного свойства можно с помощью функции
func GetTextShadows(view View, subviewID ...string) []ViewShadow
func GetTextShadows(view View, subviewID ...string) []ShadowProperty
Если тень не задана, то данная функция вернет пустой массив

View File

@ -1024,7 +1024,7 @@ equivalent to
### "shadow" property
The "shadow" property allows you to set shadows for the View. There may be several shadows.
The shadow is described using the ViewShadow interface extending the Properties interface (see above).
The shadow is described using the ShadowProperty interface extending the Properties interface (see above).
The shadow has the following properties:
| Property | Constant | Type | Description |
@ -1036,14 +1036,14 @@ The shadow has the following properties:
| "blur" | BlurRadius | float | Shadow blur radius. The value must be >= 0 |
| "spread-radius" | SpreadRadius | float | Increase the shadow. Value > 0 increases shadow, < 0 decreases shadow |
Three functions are used to create a ViewShadow:
Three functions are used to create a ShadowProperty:
func NewViewShadow(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ViewShadow
func NewInsetViewShadow(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ViewShadow
func NewShadowWithParams(params Params) ViewShadow
func NewShadowProperty(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ShadowProperty
func NewInsetShadowProperty(offsetX, offsetY, blurRadius, spread-radius SizeUnit, color Color) ShadowProperty
func NewShadowWithParams(params Params) ShadowProperty
The NewViewShadow function creates an outer shadow (Inset == false),
NewInsetViewShadow - an inner one (Inset == true).
The NewShadowProperty function creates an outer shadow (Inset == false),
NewInsetShadowProperty - an inner one (Inset == true).
The NewShadowWithParams function is used when constants must be used as parameters.
For example:
@ -1053,16 +1053,16 @@ For example:
rui.Dilation : 16.0,
})
ViewShadow, ViewShadow array, and ViewShadow textual representation can be assigned as a value to the "shadow" property.
ShadowProperty, ShadowProperty array, and ShadowProperty textual representation can be assigned as a value to the "shadow" property.
The ViewShadow text representation has the following format:
The ShadowProperty text representation has the following format:
_{ color = <color> [, x-offset = <offset>] [, y-offset = <offset>] [, blur = <radius>]
[, spread-radius = <increase>] [, inset = <type>] }
You can get the value of "shadow" property using the function
func GetViewShadows(view View, subviewID ...string) []ViewShadow
func GetShadowPropertys(view View, subviewID ...string) []ShadowProperty
If no shadow is specified, then this function will return an empty array
@ -1425,7 +1425,7 @@ The argument lists the effects to apply. The following effects are possible:
| "blur" | Blur | float64 0…10000px | Gaussian blur |
| "brightness" | Brightness | float64 0…10000% | Brightness change |
| "contrast" | Contrast | float64 0…10000% | Contrast change |
| "drop-shadow" | DropShadow | []ViewShadow | Adding shadow |
| "drop-shadow" | DropShadow | []ShadowProperty | Adding shadow |
| "grayscale" | Grayscale | float64 0…100% | Converting to grayscale |
| "hue-rotate" | HueRotate | AngleUnit | Hue rotation |
| "invert" | Invert | float64 0…100% | Invert colors |
@ -1686,14 +1686,14 @@ You can get the value of this property using the function
#### "text-shadow" property
The "text-shadow" property allows you to set shadows for the text. There may be several shadows.
The shadow is described using the ViewShadow interface (see above, section "The 'shadow' property").
The shadow is described using the ShadowProperty interface (see above, section "The 'shadow' property").
For text shadow, only the "color", "x-offset", "y-offset" and "blur" properties are used.
The "inset" and "spread-radius" properties are ignored (i.e. setting them is not an error, they just have no effect on the text shadow).
To create a ViewShadow for the text shadow, the following functions are used:
To create a ShadowProperty for the text shadow, the following functions are used:
func NewTextShadow(offsetX, offsetY, blurRadius SizeUnit, color Color) ViewShadow
func NewShadowWithParams(params Params) ViewShadow
func NewTextShadow(offsetX, offsetY, blurRadius SizeUnit, color Color) ShadowProperty
func NewShadowWithParams(params Params) ShadowProperty
The NewShadowWithParams function is used when constants must be used as parameters. For example:
@ -1702,11 +1702,11 @@ The NewShadowWithParams function is used when constants must be used as paramete
rui.BlurRadius: 8.0,
})
ViewShadow, ViewShadow array, ViewShadow textual representation can be assigned as a value to the "text-shadow" property (see above, section "The 'shadow' property").
ShadowProperty, ShadowProperty array, ShadowProperty textual representation can be assigned as a value to the "text-shadow" property (see above, section "The 'shadow' property").
You can get the value of this property using the function
func GetTextShadows(view View, subviewID ...string) []ViewShadow
func GetTextShadows(view View, subviewID ...string) []ShadowProperty
If no shadow is specified, then this function will return an empty array

View File

@ -363,7 +363,7 @@ func (arrow *popupArrow) createView(popupView View) View {
params := Params{BackgroundColor: GetBackgroundColor(popupView)}
if shadow := GetViewShadows(popupView); shadow != nil {
if shadow := GetShadowPropertys(popupView); shadow != nil {
params[Shadow] = shadow
}
@ -554,7 +554,7 @@ func (popup *popupData) init(view View, popupParams Params) {
CellVerticalAlign: StretchAlign,
CellHorizontalAlign: StretchAlign,
ClickEvent: func(View) {},
Shadow: NewShadowWithParams(Params{
Shadow: NewShadowProperty(Params{
SpreadRadius: Px(4),
Blur: Px(16),
ColorTag: "@ruiPopupShadow",

View File

@ -964,15 +964,15 @@ const (
// Adds shadow effects around a view's frame. A shadow is described by X and Y offsets relative to the element, blur,
// spread radius and color.
//
// Supported types: `ViewShadow`, `[]ViewShadow`, `string`.
// Supported types: `ShadowProperty`, `[]ShadowProperty`, `string`.
//
// Internal type is `[]ViewShadow`, other types converted to it during assignment.
// See `ViewShadow` description for more details.
// Internal type is `[]ShadowProperty`, other types converted to it during assignment.
// See `ShadowProperty` description for more details.
//
// Conversion rules:
// `[]ViewShadow` - stored as is. no conversion performed.
// `ViewShadow` - converted to `[]ViewShadow` during assignment.
// `string` - must contain a string representation of `ViewShadow`
// `[]ShadowProperty` - stored as is. no conversion performed.
// `ShadowProperty` - converted to `[]ShadowProperty` during assignment.
// `string` - must contain a string representation of `ShadowProperty`
Shadow PropertyName = "shadow"
// FontName is the constant for "font-name" property tag.
@ -1178,15 +1178,15 @@ const (
// Used by `View`.
// Specify shadow for the text.
//
// Supported types: `ViewShadow`, `[]ViewShadow`, `string`.
// Supported types: `ShadowProperty`, `[]ShadowProperty`, `string`.
//
// Internal type is `[]ViewShadow`, other types converted to it during assignment.
// See `ViewShadow` description for more details.
// Internal type is `[]ShadowProperty`, other types converted to it during assignment.
// See `ShadowProperty` description for more details.
//
// Conversion rules:
// `[]ViewShadow` - stored as is. no conversion performed.
// `ViewShadow` - converted to `[]ViewShadow` during assignment.
// `string` - must contain a string representation of `ViewShadow`
// `[]ShadowProperty` - stored as is. no conversion performed.
// `ShadowProperty` - converted to `[]ShadowProperty` during assignment.
// `string` - must contain a string representation of `ShadowProperty`
TextShadow PropertyName = "text-shadow"
// TextWrap is the constant for "text-wrap" property tag.

103
shadow.go
View File

@ -5,11 +5,11 @@ import (
"strings"
)
// Constants for [ViewShadow] specific properties
// Constants for [ShadowProperty] specific properties
const (
// ColorTag is the constant for "color" property tag.
//
// Used by `ColumnSeparatorProperty`, `BorderProperty`, `OutlineProperty`, `ViewShadow`.
// Used by `ColumnSeparatorProperty`, `BorderProperty`, `OutlineProperty`, `ShadowProperty`.
//
// Usage in `ColumnSeparatorProperty`:
// Line color.
@ -35,7 +35,7 @@ const (
// Internal type is `Color`, other types converted to it during assignment.
// See `Color` description for more details.
//
// Usage in `ViewShadow`:
// Usage in `ShadowProperty`:
// Color property of the shadow.
//
// Supported types: `Color`, `string`.
@ -46,7 +46,7 @@ const (
// Inset is the constant for "inset" property tag.
//
// Used by `ViewShadow`.
// Used by `ShadowProperty`.
// Controls whether to draw shadow inside the frame or outside. Inset shadows are drawn inside the border(even transparent
// ones), above the background, but below content.
//
@ -59,7 +59,7 @@ const (
// XOffset is the constant for "x-offset" property tag.
//
// Used by `ViewShadow`.
// Used by `ShadowProperty`.
// Determines the shadow horizontal offset. Negative values place the shadow to the left of the element.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
@ -70,7 +70,7 @@ const (
// YOffset is the constant for "y-offset" property tag.
//
// Used by `ViewShadow`.
// Used by `ShadowProperty`.
// Determines the shadow vertical offset. Negative values place the shadow above the element.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
@ -81,7 +81,7 @@ const (
// BlurRadius is the constant for "blur" property tag.
//
// Used by `ViewShadow`.
// Used by `ShadowProperty`.
// Determines the radius of the blur effect. The larger this value, the bigger the blur, so the shadow becomes bigger and
// lighter. Negative values are not allowed.
//
@ -93,7 +93,7 @@ const (
// SpreadRadius is the constant for "spread-radius" property tag.
//
// Used by `ViewShadow`.
// Used by `ShadowProperty`.
// Positive values will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink.
//
// Supported types: `SizeUnit`, `SizeFunc`, `string`, `float`, `int`.
@ -103,8 +103,8 @@ const (
SpreadRadius PropertyName = "spread-radius"
)
// ViewShadow contains attributes of the view shadow
type ViewShadow interface {
// ShadowProperty contains attributes of the view shadow
type ShadowProperty interface {
Properties
fmt.Stringer
stringWriter
@ -113,11 +113,11 @@ type ViewShadow interface {
visible(session Session) bool
}
type viewShadowData struct {
type shadowPropertyData struct {
dataProperty
}
// NewViewShadow create the new shadow for a view. Arguments:
// NewShadow create the new shadow property for a view. Arguments:
//
// offsetX, offsetY is x and y offset of the shadow;
//
@ -126,17 +126,18 @@ type viewShadowData struct {
// spreadRadius is the spread radius of the shadow;
//
// color is the color of the shadow.
func NewViewShadow(offsetX, offsetY, blurRadius, spreadRadius SizeUnit, color Color) ViewShadow {
return NewShadowWithParams(Params{
XOffset: offsetX,
YOffset: offsetY,
func NewShadow[xOffsetType SizeUnit | int | float64, yOffsetType SizeUnit | int | float64, blurType SizeUnit | int | float64, spreadType SizeUnit | int | float64](
xOffset xOffsetType, yOffset yOffsetType, blurRadius blurType, spreadRadius spreadType, color Color) ShadowProperty {
return NewShadowProperty(Params{
XOffset: xOffset,
YOffset: yOffset,
BlurRadius: blurRadius,
SpreadRadius: spreadRadius,
ColorTag: color,
})
}
// NewInsetViewShadow create the new inset shadow for a view. Arguments:
// NewInsetShadow create the new inset shadow property for a view. Arguments:
//
// offsetX, offsetY is x and y offset of the shadow;
//
@ -145,10 +146,11 @@ func NewViewShadow(offsetX, offsetY, blurRadius, spreadRadius SizeUnit, color Co
// spreadRadius is the spread radius of the shadow;
//
// color is the color of the shadow.
func NewInsetViewShadow(offsetX, offsetY, blurRadius, spreadRadius SizeUnit, color Color) ViewShadow {
return NewShadowWithParams(Params{
XOffset: offsetX,
YOffset: offsetY,
func NewInsetShadow[xOffsetType SizeUnit | int | float64, yOffsetType SizeUnit | int | float64, blurType SizeUnit | int | float64, spreadType SizeUnit | int | float64](
xOffset xOffsetType, yOffset yOffsetType, blurRadius blurType, spreadRadius spreadType, color Color) ShadowProperty {
return NewShadowProperty(Params{
XOffset: xOffset,
YOffset: yOffset,
BlurRadius: blurRadius,
SpreadRadius: spreadRadius,
ColorTag: color,
@ -156,23 +158,24 @@ func NewInsetViewShadow(offsetX, offsetY, blurRadius, spreadRadius SizeUnit, col
})
}
// NewTextShadow create the new text shadow. Arguments:
// NewTextShadow create the new text shadow property. Arguments:
//
// offsetX, offsetY is the x- and y-offset of the shadow;
//
// blurRadius is the blur radius of the shadow;
//
// color is the color of the shadow.
func NewTextShadow(offsetX, offsetY, blurRadius SizeUnit, color Color) ViewShadow {
return NewShadowWithParams(Params{
XOffset: offsetX,
YOffset: offsetY,
func NewTextShadow[xOffsetType SizeUnit | int | float64, yOffsetType SizeUnit | int | float64, blurType SizeUnit | int | float64](
xOffset xOffsetType, yOffset yOffsetType, blurRadius blurType, color Color) ShadowProperty {
return NewShadowProperty(Params{
XOffset: xOffset,
YOffset: yOffset,
BlurRadius: blurRadius,
ColorTag: color,
})
}
// NewShadowWithParams create the new shadow for a view.
// NewShadowProperty create the new shadow property for a view.
// The following properties can be used:
//
// "color" (ColorTag). Determines the color of the shadow (Color);
@ -186,8 +189,8 @@ func NewTextShadow(offsetX, offsetY, blurRadius SizeUnit, color Color) ViewShado
// "spread-radius" (SpreadRadius). Positive values (SizeUnit) will cause the shadow to expand and grow bigger, negative values will cause the shadow to shrink;
//
// "inset" (Inset). Controls (bool) whether to draw shadow inside the frame or outside.
func NewShadowWithParams(params Params) ViewShadow {
shadow := new(viewShadowData)
func NewShadowProperty(params Params) ShadowProperty {
shadow := new(shadowPropertyData)
shadow.init()
if params != nil {
@ -200,20 +203,20 @@ func NewShadowWithParams(params Params) ViewShadow {
return shadow
}
// parseViewShadow parse DataObject and create ViewShadow object
func parseViewShadow(object DataObject) ViewShadow {
shadow := new(viewShadowData)
// parseShadowProperty parse DataObject and create ShadowProperty object
func parseShadowProperty(object DataObject) ShadowProperty {
shadow := new(shadowPropertyData)
shadow.init()
parseProperties(shadow, object)
return shadow
}
func (shadow *viewShadowData) init() {
func (shadow *shadowPropertyData) init() {
shadow.dataProperty.init()
shadow.supportedProperties = []PropertyName{ColorTag, Inset, XOffset, YOffset, BlurRadius, SpreadRadius}
}
func (shadow *viewShadowData) cssStyle(buffer *strings.Builder, session Session, lead string) bool {
func (shadow *shadowPropertyData) cssStyle(buffer *strings.Builder, session Session, lead string) bool {
color, _ := colorProperty(shadow, ColorTag, session)
offsetX, _ := sizeProperty(shadow, XOffset, session)
offsetY, _ := sizeProperty(shadow, YOffset, session)
@ -245,7 +248,7 @@ func (shadow *viewShadowData) cssStyle(buffer *strings.Builder, session Session,
return true
}
func (shadow *viewShadowData) cssTextStyle(buffer *strings.Builder, session Session, lead string) bool {
func (shadow *shadowPropertyData) cssTextStyle(buffer *strings.Builder, session Session, lead string) bool {
color, _ := colorProperty(shadow, ColorTag, session)
offsetX, _ := sizeProperty(shadow, XOffset, session)
offsetY, _ := sizeProperty(shadow, YOffset, session)
@ -269,7 +272,7 @@ func (shadow *viewShadowData) cssTextStyle(buffer *strings.Builder, session Sess
return true
}
func (shadow *viewShadowData) visible(session Session) bool {
func (shadow *shadowPropertyData) visible(session Session) bool {
color, _ := colorProperty(shadow, ColorTag, session)
offsetX, _ := sizeProperty(shadow, XOffset, session)
offsetY, _ := sizeProperty(shadow, YOffset, session)
@ -286,11 +289,11 @@ func (shadow *viewShadowData) visible(session Session) bool {
return true
}
func (shadow *viewShadowData) String() string {
func (shadow *shadowPropertyData) String() string {
return runStringWriter(shadow)
}
func (shadow *viewShadowData) writeString(buffer *strings.Builder, indent string) {
func (shadow *shadowPropertyData) writeString(buffer *strings.Builder, indent string) {
buffer.WriteString("_{ ")
comma := false
for _, tag := range shadow.AllTags() {
@ -315,10 +318,10 @@ func setShadowProperty(properties Properties, tag PropertyName, value any) bool
}
switch value := value.(type) {
case ViewShadow:
properties.setRaw(tag, []ViewShadow{value})
case ShadowProperty:
properties.setRaw(tag, []ShadowProperty{value})
case []ViewShadow:
case []ShadowProperty:
if len(value) == 0 {
properties.setRaw(tag, nil)
} else {
@ -329,13 +332,13 @@ func setShadowProperty(properties Properties, tag PropertyName, value any) bool
if !value.IsObject() {
return false
}
properties.setRaw(tag, []ViewShadow{parseViewShadow(value.Object())})
properties.setRaw(tag, []ShadowProperty{parseShadowProperty(value.Object())})
case []DataValue:
shadows := []ViewShadow{}
shadows := []ShadowProperty{}
for _, data := range value {
if data.IsObject() {
shadows = append(shadows, parseViewShadow(data.Object()))
shadows = append(shadows, parseShadowProperty(data.Object()))
}
}
if len(shadows) == 0 {
@ -349,7 +352,7 @@ func setShadowProperty(properties Properties, tag PropertyName, value any) bool
notCompatibleType(tag, value)
return false
}
properties.setRaw(tag, []ViewShadow{parseViewShadow(obj)})
properties.setRaw(tag, []ShadowProperty{parseShadowProperty(obj)})
default:
notCompatibleType(tag, value)
@ -359,17 +362,17 @@ func setShadowProperty(properties Properties, tag PropertyName, value any) bool
return true
}
func getShadows(properties Properties, tag PropertyName) []ViewShadow {
func getShadows(properties Properties, tag PropertyName) []ShadowProperty {
if value := properties.Get(tag); value != nil {
switch value := value.(type) {
case []ViewShadow:
case []ShadowProperty:
return value
case ViewShadow:
return []ViewShadow{value}
case ShadowProperty:
return []ShadowProperty{value}
}
}
return []ViewShadow{}
return []ShadowProperty{}
}
func shadowCSS(properties Properties, tag PropertyName, session Session) string {

View File

@ -47,17 +47,17 @@ const (
// Used by `ViewFilter`.
// Applies a drop shadow effect to the input image. A drop shadow is effectively a blurred, offset version of the input
// image's alpha mask drawn in a particular color, composited below the image. Shadow parameters are set using the
// `ViewShadow` interface.
// `ShadowProperty` interface.
//
// Supported types: `[]ViewShadow`, `ViewShadow`, `string`.
// Supported types: `[]ShadowProperty`, `ShadowProperty`, `string`.
//
// Internal type is `[]ViewShadow`, other types converted to it during assignment.
// See `ViewShadow` description for more details.
// Internal type is `[]ShadowProperty`, other types converted to it during assignment.
// See `ShadowProperty` description for more details.
//
// Conversion rules:
// `[]ViewShadow` - stored as is, no conversion performed.
// `ViewShadow` - converted to `[]ViewShadow`.
// `string` - string representation of `ViewShadow`. Example: "_{blur = 1em, color = black, spread-radius = 0.5em}".
// `[]ShadowProperty` - stored as is, no conversion performed.
// `ShadowProperty` - converted to `[]ShadowProperty`.
// `string` - string representation of `ShadowProperty`. Example: "_{blur = 1em, color = black, spread-radius = 0.5em}".
DropShadow PropertyName = "drop-shadow"
// Grayscale is the constant for "grayscale" property tag.

View File

@ -560,7 +560,7 @@ func supportedPropertyValue(value any) bool {
case int:
case stringWriter:
case fmt.Stringer:
case []ViewShadow:
case []ShadowProperty:
case []View:
case []any:
case []BackgroundElement:
@ -671,7 +671,7 @@ func writePropertyValue(buffer *strings.Builder, tag PropertyName, value any, in
case fmt.Stringer:
writeString(value.String())
case []ViewShadow:
case []ShadowProperty:
switch len(value) {
case 0:
// do nothing

View File

@ -203,6 +203,13 @@ func GetWidth(view View, subviewID ...string) SizeUnit {
return sizeStyledProperty(view, subviewID, Width, false)
}
func SetWidth[T SizeUnit | float64 | float32 | int | int8 | int16 | int32 | int64 | uint | uint8 | uint16 | uint32 | uint64](size T, view View, subviewID ...string) bool {
if view = getSubview(view, subviewID); view != nil {
return view.Set(Width, size)
}
return false
}
// GetHeight returns the subview height.
// If the second argument (subviewID) is not specified or it is "" then a height of the first argument (view) is returned
func GetHeight(view View, subviewID ...string) SizeUnit {
@ -326,22 +333,22 @@ func GetOutlineOffset(view View, subviewID ...string) SizeUnit {
return sizeStyledProperty(view, subviewID, OutlineOffset, false)
}
// GetViewShadows returns shadows of the subview.
// GetShadowPropertys returns shadows of the subview.
// If the second argument (subviewID) is not specified or it is "" then shadows of the first argument (view) is returned.
func GetViewShadows(view View, subviewID ...string) []ViewShadow {
func GetShadowPropertys(view View, subviewID ...string) []ShadowProperty {
view = getSubview(view, subviewID)
if view == nil {
return []ViewShadow{}
return []ShadowProperty{}
}
return getShadows(view, Shadow)
}
// GetTextShadows returns text shadows of the subview.
// If the second argument (subviewID) is not specified or it is "" then shadows of the first argument (view) is returned.
func GetTextShadows(view View, subviewID ...string) []ViewShadow {
func GetTextShadows(view View, subviewID ...string) []ShadowProperty {
view = getSubview(view, subviewID)
if view == nil {
return []ViewShadow{}
return []ShadowProperty{}
}
return getShadows(view, TextShadow)
}