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

commonMain.app.cash.redwood.layout.testing.ColumnValue.kt Maven / Gradle / Ivy

There is a newer version: 0.14.0
Show newest version
@file:Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")

package app.cash.redwood.layout.testing

import app.cash.redwood.Modifier
import app.cash.redwood.RedwoodCodegenApi
import app.cash.redwood.layout.api.Constraint
import app.cash.redwood.layout.api.CrossAxisAlignment
import app.cash.redwood.layout.api.MainAxisAlignment
import app.cash.redwood.layout.api.Overflow
import app.cash.redwood.layout.widget.RedwoodLayoutWidgetFactoryOwner
import app.cash.redwood.testing.WidgetValue
import app.cash.redwood.testing.toDebugString
import app.cash.redwood.ui.Margin
import app.cash.redwood.ui.Px
import app.cash.redwood.widget.Widget
import app.cash.redwood.widget.WidgetSystem
import kotlin.Any
import kotlin.Boolean
import kotlin.Int
import kotlin.OptIn
import kotlin.String
import kotlin.Suppress
import kotlin.Unit
import kotlin.collections.List
import kotlin.collections.listOf

public class ColumnValue(
  override val modifier: Modifier = Modifier,
  public val width: Constraint = Constraint.Wrap,
  public val height: Constraint = Constraint.Wrap,
  public val margin: Margin = Margin.Zero,
  public val overflow: Overflow = Overflow.Clip,
  public val horizontalAlignment: CrossAxisAlignment = CrossAxisAlignment.Start,
  public val verticalAlignment: MainAxisAlignment = MainAxisAlignment.Start,
  public val onScroll: ((offset: Px) -> Unit)? = null,
  public val children: List = listOf(),
) : WidgetValue {
  override val childrenLists: List>
    get() = listOf(children)

  override fun equals(other: Any?): Boolean = other is ColumnValue &&
  other.modifier == modifier &&
  other.width == width &&
  other.height == height &&
  other.margin == margin &&
  other.overflow == overflow &&
  other.horizontalAlignment == horizontalAlignment &&
  other.verticalAlignment == verticalAlignment &&
  other.children == children

  override fun hashCode(): Int = listOf(modifier, width, height, margin, overflow,
      horizontalAlignment, verticalAlignment, children).hashCode()

  override fun toString(): String =
      """ColumnValue(modifier=$modifier, width=$width, height=$height, margin=$margin, overflow=$overflow, horizontalAlignment=$horizontalAlignment, verticalAlignment=$verticalAlignment, children=$children)"""

  override fun toDebugString(): String = buildString {
    append("Column")
    append("""
        |(
        |  width = $width, 
        |  height = $height, 
        |  margin = $margin, 
        |  overflow = $overflow, 
        |  horizontalAlignment = $horizontalAlignment, 
        |  verticalAlignment = $verticalAlignment
        |""".trimMargin())
    append(")")
    append(" {")
    if (childrenLists[0].isNotEmpty()) {
      appendLine()
      append(childrenLists[0].toDebugString().prependIndent("  "))
      append("\n}")
    }
    else {
      append(" }")
    }
  }

  @OptIn(RedwoodCodegenApi::class)
  override fun  toWidget(widgetSystem: WidgetSystem): Widget {
    @Suppress("UNCHECKED_CAST") // Type parameter shared in generated code.
    val factoryOwner = widgetSystem as RedwoodLayoutWidgetFactoryOwner
    val instance = factoryOwner.RedwoodLayout.Column()

    instance.width(width)
    instance.height(height)
    instance.margin(margin)
    instance.overflow(overflow)
    instance.horizontalAlignment(horizontalAlignment)
    instance.verticalAlignment(verticalAlignment)
    instance.modifier = modifier

    for ((index, child) in children.withIndex()) {
      instance.children.insert(index, child.toWidget(widgetSystem))
    }

    return instance
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy