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

divkit.dsl.LayoutProvider.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

/**
 * Can be created using the method [layoutProvider].
 */
@Generated
class LayoutProvider internal constructor(
    @JsonIgnore
    val properties: Properties,
) {
    @JsonAnyGetter
    internal fun getJsonProperties(): Map = properties.mergeWith(emptyMap())

    operator fun plus(additive: Properties): LayoutProvider = LayoutProvider(
        Properties(
            heightVariableName = additive.heightVariableName ?: properties.heightVariableName,
            widthVariableName = additive.widthVariableName ?: properties.widthVariableName,
        )
    )

    class Properties internal constructor(
        /**
         * Variable name to store element height.
         */
        val heightVariableName: Property?,
        /**
         * Variable name to store element width.
         */
        val widthVariableName: Property?,
    ) {
        internal fun mergeWith(properties: Map): Map {
            val result = mutableMapOf()
            result.putAll(properties)
            result.tryPutProperty("height_variable_name", heightVariableName)
            result.tryPutProperty("width_variable_name", widthVariableName)
            return result
        }
    }
}

/**
 * @param heightVariableName Variable name to store element height.
 * @param widthVariableName Variable name to store element width.
 */
@Generated
fun DivScope.layoutProvider(
    `use named arguments`: Guard = Guard.instance,
    heightVariableName: String? = null,
    widthVariableName: String? = null,
): LayoutProvider = LayoutProvider(
    LayoutProvider.Properties(
        heightVariableName = valueOrNull(heightVariableName),
        widthVariableName = valueOrNull(widthVariableName),
    )
)

/**
 * @param heightVariableName Variable name to store element height.
 * @param widthVariableName Variable name to store element width.
 */
@Generated
fun DivScope.layoutProviderProps(
    `use named arguments`: Guard = Guard.instance,
    heightVariableName: String? = null,
    widthVariableName: String? = null,
) = LayoutProvider.Properties(
    heightVariableName = valueOrNull(heightVariableName),
    widthVariableName = valueOrNull(widthVariableName),
)

/**
 * @param heightVariableName Variable name to store element height.
 * @param widthVariableName Variable name to store element width.
 */
@Generated
fun TemplateScope.layoutProviderRefs(
    `use named arguments`: Guard = Guard.instance,
    heightVariableName: ReferenceProperty? = null,
    widthVariableName: ReferenceProperty? = null,
) = LayoutProvider.Properties(
    heightVariableName = heightVariableName,
    widthVariableName = widthVariableName,
)

/**
 * @param heightVariableName Variable name to store element height.
 * @param widthVariableName Variable name to store element width.
 */
@Generated
fun LayoutProvider.override(
    `use named arguments`: Guard = Guard.instance,
    heightVariableName: String? = null,
    widthVariableName: String? = null,
): LayoutProvider = LayoutProvider(
    LayoutProvider.Properties(
        heightVariableName = valueOrNull(heightVariableName) ?: properties.heightVariableName,
        widthVariableName = valueOrNull(widthVariableName) ?: properties.widthVariableName,
    )
)

/**
 * @param heightVariableName Variable name to store element height.
 * @param widthVariableName Variable name to store element width.
 */
@Generated
fun LayoutProvider.defer(
    `use named arguments`: Guard = Guard.instance,
    heightVariableName: ReferenceProperty? = null,
    widthVariableName: ReferenceProperty? = null,
): LayoutProvider = LayoutProvider(
    LayoutProvider.Properties(
        heightVariableName = heightVariableName ?: properties.heightVariableName,
        widthVariableName = widthVariableName ?: properties.widthVariableName,
    )
)

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy