All Downloads are FREE. Search and download functionalities are using the official Maven repository.

divkit.dsl.ImageBackground.kt Maven / Gradle / Ivy

Go to download

DivKit is an open source Server-Driven UI (SDUI) framework. SDUI is a an emerging technique that leverage the server to build the user interfaces of their mobile app.

There is a newer version: 30.19.0
Show newest version
@file:Suppress(
    "unused",
    "UNUSED_PARAMETER",
)

package divkit.dsl

import com.fasterxml.jackson.annotation.JsonAnyGetter
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonValue
import divkit.dsl.annotation.*
import divkit.dsl.core.*
import divkit.dsl.scope.*
import kotlin.Any
import kotlin.String
import kotlin.Suppress
import kotlin.collections.List
import kotlin.collections.Map

/**
 * Background image.
 * 
 * Can be created using the method [imageBackground].
 * 
 * Required parameters: `type, image_url`.
 */
@Generated
class ImageBackground internal constructor(
    @JsonIgnore
    val properties: Properties,
) : Background {
    @JsonAnyGetter
    internal fun getJsonProperties(): Map = properties.mergeWith(
        mapOf("type" to "image")
    )

    operator fun plus(additive: Properties): ImageBackground = ImageBackground(
        Properties(
            alpha = additive.alpha ?: properties.alpha,
            contentAlignmentHorizontal = additive.contentAlignmentHorizontal ?: properties.contentAlignmentHorizontal,
            contentAlignmentVertical = additive.contentAlignmentVertical ?: properties.contentAlignmentVertical,
            filters = additive.filters ?: properties.filters,
            imageUrl = additive.imageUrl ?: properties.imageUrl,
            preloadRequired = additive.preloadRequired ?: properties.preloadRequired,
            scale = additive.scale ?: properties.scale,
        )
    )

    class Properties internal constructor(
        /**
         * Image transparency.
         * Default value: `1.0`.
         */
        val alpha: Property?,
        /**
         * Horizontal image alignment.
         * Default value: `center`.
         */
        val contentAlignmentHorizontal: Property?,
        /**
         * Vertical image alignment.
         * Default value: `center`.
         */
        val contentAlignmentVertical: Property?,
        /**
         * Image filters.
         */
        val filters: Property>?,
        /**
         * Image URL.
         */
        val imageUrl: Property?,
        /**
         * Background image must be loaded before the display.
         * Default value: `false`.
         */
        val preloadRequired: Property?,
        /**
         * Image scaling.
         * Default value: `fill`.
         */
        val scale: Property?,
    ) {
        internal fun mergeWith(properties: Map): Map {
            val result = mutableMapOf()
            result.putAll(properties)
            result.tryPutProperty("alpha", alpha)
            result.tryPutProperty("content_alignment_horizontal", contentAlignmentHorizontal)
            result.tryPutProperty("content_alignment_vertical", contentAlignmentVertical)
            result.tryPutProperty("filters", filters)
            result.tryPutProperty("image_url", imageUrl)
            result.tryPutProperty("preload_required", preloadRequired)
            result.tryPutProperty("scale", scale)
            return result
        }
    }
}

/**
 * @param alpha Image transparency.
 * @param contentAlignmentHorizontal Horizontal image alignment.
 * @param contentAlignmentVertical Vertical image alignment.
 * @param filters Image filters.
 * @param imageUrl Image URL.
 * @param preloadRequired Background image must be loaded before the display.
 * @param scale Image scaling.
 */
@Generated
fun DivScope.imageBackground(
    `use named arguments`: Guard = Guard.instance,
    alpha: Double? = null,
    contentAlignmentHorizontal: AlignmentHorizontal? = null,
    contentAlignmentVertical: AlignmentVertical? = null,
    filters: List? = null,
    imageUrl: Url? = null,
    preloadRequired: Boolean? = null,
    scale: ImageScale? = null,
): ImageBackground = ImageBackground(
    ImageBackground.Properties(
        alpha = valueOrNull(alpha),
        contentAlignmentHorizontal = valueOrNull(contentAlignmentHorizontal),
        contentAlignmentVertical = valueOrNull(contentAlignmentVertical),
        filters = valueOrNull(filters),
        imageUrl = valueOrNull(imageUrl),
        preloadRequired = valueOrNull(preloadRequired),
        scale = valueOrNull(scale),
    )
)

/**
 * @param alpha Image transparency.
 * @param contentAlignmentHorizontal Horizontal image alignment.
 * @param contentAlignmentVertical Vertical image alignment.
 * @param filters Image filters.
 * @param imageUrl Image URL.
 * @param preloadRequired Background image must be loaded before the display.
 * @param scale Image scaling.
 */
@Generated
fun DivScope.imageBackgroundProps(
    `use named arguments`: Guard = Guard.instance,
    alpha: Double? = null,
    contentAlignmentHorizontal: AlignmentHorizontal? = null,
    contentAlignmentVertical: AlignmentVertical? = null,
    filters: List? = null,
    imageUrl: Url? = null,
    preloadRequired: Boolean? = null,
    scale: ImageScale? = null,
) = ImageBackground.Properties(
    alpha = valueOrNull(alpha),
    contentAlignmentHorizontal = valueOrNull(contentAlignmentHorizontal),
    contentAlignmentVertical = valueOrNull(contentAlignmentVertical),
    filters = valueOrNull(filters),
    imageUrl = valueOrNull(imageUrl),
    preloadRequired = valueOrNull(preloadRequired),
    scale = valueOrNull(scale),
)

/**
 * @param alpha Image transparency.
 * @param contentAlignmentHorizontal Horizontal image alignment.
 * @param contentAlignmentVertical Vertical image alignment.
 * @param filters Image filters.
 * @param imageUrl Image URL.
 * @param preloadRequired Background image must be loaded before the display.
 * @param scale Image scaling.
 */
@Generated
fun TemplateScope.imageBackgroundRefs(
    `use named arguments`: Guard = Guard.instance,
    alpha: ReferenceProperty? = null,
    contentAlignmentHorizontal: ReferenceProperty? = null,
    contentAlignmentVertical: ReferenceProperty? = null,
    filters: ReferenceProperty>? = null,
    imageUrl: ReferenceProperty? = null,
    preloadRequired: ReferenceProperty? = null,
    scale: ReferenceProperty? = null,
) = ImageBackground.Properties(
    alpha = alpha,
    contentAlignmentHorizontal = contentAlignmentHorizontal,
    contentAlignmentVertical = contentAlignmentVertical,
    filters = filters,
    imageUrl = imageUrl,
    preloadRequired = preloadRequired,
    scale = scale,
)

/**
 * @param alpha Image transparency.
 * @param contentAlignmentHorizontal Horizontal image alignment.
 * @param contentAlignmentVertical Vertical image alignment.
 * @param filters Image filters.
 * @param imageUrl Image URL.
 * @param preloadRequired Background image must be loaded before the display.
 * @param scale Image scaling.
 */
@Generated
fun ImageBackground.override(
    `use named arguments`: Guard = Guard.instance,
    alpha: Double? = null,
    contentAlignmentHorizontal: AlignmentHorizontal? = null,
    contentAlignmentVertical: AlignmentVertical? = null,
    filters: List? = null,
    imageUrl: Url? = null,
    preloadRequired: Boolean? = null,
    scale: ImageScale? = null,
): ImageBackground = ImageBackground(
    ImageBackground.Properties(
        alpha = valueOrNull(alpha) ?: properties.alpha,
        contentAlignmentHorizontal = valueOrNull(contentAlignmentHorizontal) ?: properties.contentAlignmentHorizontal,
        contentAlignmentVertical = valueOrNull(contentAlignmentVertical) ?: properties.contentAlignmentVertical,
        filters = valueOrNull(filters) ?: properties.filters,
        imageUrl = valueOrNull(imageUrl) ?: properties.imageUrl,
        preloadRequired = valueOrNull(preloadRequired) ?: properties.preloadRequired,
        scale = valueOrNull(scale) ?: properties.scale,
    )
)

/**
 * @param alpha Image transparency.
 * @param contentAlignmentHorizontal Horizontal image alignment.
 * @param contentAlignmentVertical Vertical image alignment.
 * @param filters Image filters.
 * @param imageUrl Image URL.
 * @param preloadRequired Background image must be loaded before the display.
 * @param scale Image scaling.
 */
@Generated
fun ImageBackground.defer(
    `use named arguments`: Guard = Guard.instance,
    alpha: ReferenceProperty? = null,
    contentAlignmentHorizontal: ReferenceProperty? = null,
    contentAlignmentVertical: ReferenceProperty? = null,
    filters: ReferenceProperty>? = null,
    imageUrl: ReferenceProperty? = null,
    preloadRequired: ReferenceProperty? = null,
    scale: ReferenceProperty? = null,
): ImageBackground = ImageBackground(
    ImageBackground.Properties(
        alpha = alpha ?: properties.alpha,
        contentAlignmentHorizontal = contentAlignmentHorizontal ?: properties.contentAlignmentHorizontal,
        contentAlignmentVertical = contentAlignmentVertical ?: properties.contentAlignmentVertical,
        filters = filters ?: properties.filters,
        imageUrl = imageUrl ?: properties.imageUrl,
        preloadRequired = preloadRequired ?: properties.preloadRequired,
        scale = scale ?: properties.scale,
    )
)

/**
 * @param alpha Image transparency.
 * @param contentAlignmentHorizontal Horizontal image alignment.
 * @param contentAlignmentVertical Vertical image alignment.
 * @param imageUrl Image URL.
 * @param preloadRequired Background image must be loaded before the display.
 * @param scale Image scaling.
 */
@Generated
fun ImageBackground.evaluate(
    `use named arguments`: Guard = Guard.instance,
    alpha: ExpressionProperty? = null,
    contentAlignmentHorizontal: ExpressionProperty? = null,
    contentAlignmentVertical: ExpressionProperty? = null,
    imageUrl: ExpressionProperty? = null,
    preloadRequired: ExpressionProperty? = null,
    scale: ExpressionProperty? = null,
): ImageBackground = ImageBackground(
    ImageBackground.Properties(
        alpha = alpha ?: properties.alpha,
        contentAlignmentHorizontal = contentAlignmentHorizontal ?: properties.contentAlignmentHorizontal,
        contentAlignmentVertical = contentAlignmentVertical ?: properties.contentAlignmentVertical,
        filters = properties.filters,
        imageUrl = imageUrl ?: properties.imageUrl,
        preloadRequired = preloadRequired ?: properties.preloadRequired,
        scale = scale ?: properties.scale,
    )
)

@Generated
fun ImageBackground.asList() = listOf(this)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy