RowColumnNode.kt (1644B) - raw
1 package me.rhunk.snapenhance.common.scripting.ui.components.impl 2 3 import androidx.compose.foundation.layout.Arrangement 4 import androidx.compose.ui.Alignment 5 import me.rhunk.snapenhance.common.scripting.ui.components.Node 6 import me.rhunk.snapenhance.common.scripting.ui.components.NodeType 7 8 9 class RowColumnNode( 10 type: NodeType, 11 ) : Node(type) { 12 companion object { 13 private val arrangements = mapOf( 14 "start" to Arrangement.Start, 15 "end" to Arrangement.End, 16 "top" to Arrangement.Top, 17 "bottom" to Arrangement.Bottom, 18 "center" to Arrangement.Center, 19 "spaceBetween" to Arrangement.SpaceBetween, 20 "spaceAround" to Arrangement.SpaceAround, 21 "spaceEvenly" to Arrangement.SpaceEvenly, 22 ) 23 private val alignments = mapOf( 24 "start" to Alignment.Start, 25 "end" to Alignment.End, 26 "top" to Alignment.Top, 27 "bottom" to Alignment.Bottom, 28 "centerVertically" to Alignment.CenterVertically, 29 "centerHorizontally" to Alignment.CenterHorizontally, 30 ) 31 } 32 33 fun arrangement(arrangement: String): RowColumnNode { 34 attributes["arrangement"] = arrangements[arrangement] ?: throw IllegalArgumentException("Invalid arrangement") 35 return this 36 } 37 38 fun alignment(alignment: String): RowColumnNode { 39 attributes["alignment"] = alignments[alignment] ?: throw IllegalArgumentException("Invalid alignment") 40 return this 41 } 42 43 fun spacedBy(spacing: Int): RowColumnNode { 44 attributes["spacing"] = spacing 45 return this 46 } 47 }