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

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

/**
 * Element dimension value.
 * 
 * Can be created using the method [dimension].
 * 
 * Required parameters: `value`.
 */
@Generated
class Dimension internal constructor(
    @JsonIgnore
    val properties: Properties,
) {
    @JsonAnyGetter
    internal fun getJsonProperties(): Map = properties.mergeWith(emptyMap())

    operator fun plus(additive: Properties): Dimension = Dimension(
        Properties(
            value = additive.value ?: properties.value,
            unit = additive.unit ?: properties.unit,
        )
    )

    class Properties internal constructor(
        /**
         * Value.
         */
        val value: Property?,
        /**
         * Default value: `dp`.
         */
        val unit: Property?,
    ) {
        internal fun mergeWith(properties: Map): Map {
            val result = mutableMapOf()
            result.putAll(properties)
            result.tryPutProperty("value", value)
            result.tryPutProperty("unit", unit)
            return result
        }
    }
}

/**
 * @param value Value.
 */
@Generated
fun DivScope.dimension(
    value: Double? = null,
    `use named arguments`: Guard = Guard.instance,
    unit: SizeUnit? = null,
): Dimension = Dimension(
    Dimension.Properties(
        value = valueOrNull(value),
        unit = valueOrNull(unit),
    )
)

/**
 * @param value Value.
 */
@Generated
fun DivScope.dimensionProps(
    `use named arguments`: Guard = Guard.instance,
    value: Double? = null,
    unit: SizeUnit? = null,
) = Dimension.Properties(
    value = valueOrNull(value),
    unit = valueOrNull(unit),
)

/**
 * @param value Value.
 */
@Generated
fun TemplateScope.dimensionRefs(
    `use named arguments`: Guard = Guard.instance,
    value: ReferenceProperty? = null,
    unit: ReferenceProperty? = null,
) = Dimension.Properties(
    value = value,
    unit = unit,
)

/**
 * @param value Value.
 */
@Generated
fun Dimension.override(
    `use named arguments`: Guard = Guard.instance,
    value: Double? = null,
    unit: SizeUnit? = null,
): Dimension = Dimension(
    Dimension.Properties(
        value = valueOrNull(value) ?: properties.value,
        unit = valueOrNull(unit) ?: properties.unit,
    )
)

/**
 * @param value Value.
 */
@Generated
fun Dimension.defer(
    `use named arguments`: Guard = Guard.instance,
    value: ReferenceProperty? = null,
    unit: ReferenceProperty? = null,
): Dimension = Dimension(
    Dimension.Properties(
        value = value ?: properties.value,
        unit = unit ?: properties.unit,
    )
)

/**
 * @param value Value.
 */
@Generated
fun Dimension.evaluate(
    `use named arguments`: Guard = Guard.instance,
    value: ExpressionProperty? = null,
    unit: ExpressionProperty? = null,
): Dimension = Dimension(
    Dimension.Properties(
        value = value ?: properties.value,
        unit = unit ?: properties.unit,
    )
)

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




© 2015 - 2024 Weber Informatics LLC | Privacy Policy