33 lines
917 B
Kotlin
33 lines
917 B
Kotlin
package net.shadowfacts.cacao
|
|
|
|
import net.shadowfacts.cacao.util.LayoutGuide
|
|
import net.shadowfacts.cacao.view.View
|
|
import no.birkett.kiwi.Variable
|
|
|
|
/**
|
|
* A Kiwi variable that belongs to a Cacao view.
|
|
* This class generally isn't used directly, but via the anchor *Anchor properties on [View].
|
|
*
|
|
* @author shadowfacts
|
|
*/
|
|
class LayoutVariable(
|
|
val view: View?,
|
|
val layoutGuide: LayoutGuide?,
|
|
val property: String,
|
|
): Variable("LayoutVariable") {
|
|
|
|
constructor(view: View, property: String): this(view, null, property)
|
|
constructor(layoutGuide: LayoutGuide, property: String): this(null, layoutGuide, property)
|
|
|
|
init {
|
|
if ((view == null) == (layoutGuide == null)) {
|
|
throw RuntimeException("LayoutVariable must be constructed with either a view or layout guide")
|
|
}
|
|
}
|
|
|
|
override fun getName() = "${view ?: layoutGuide}.$property"
|
|
|
|
override fun toString() = "LayoutVariable(name=$name, value=$value)"
|
|
|
|
}
|