commit d2b40bdcd29d071f93a2006ace687898e50a5062
parent 470b70cf1d7fd61983c6a3912ac7c3e7956e04b1
Author: rhunk <101876869+rhunk@users.noreply.github.com>
Date:   Tue,  3 Oct 2023 00:56:21 +0200

feat(scripting/ib): fill max size attributes

Diffstat:
Mapp/src/main/kotlin/me/rhunk/snapenhance/scripting/impl/ui/components/Node.kt | 10++++++++++
Mapp/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/scripting/ScriptsSection.kt | 14+++++++-------
2 files changed, 17 insertions(+), 7 deletions(-)

diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/scripting/impl/ui/components/Node.kt b/app/src/main/kotlin/me/rhunk/snapenhance/scripting/impl/ui/components/Node.kt @@ -20,6 +20,16 @@ open class Node( attributes[key] = value } + fun fillMaxWidth(): Node { + attributes["fillMaxWidth"] = true + return this + } + + fun fillMaxHeight(): Node { + attributes["fillMaxHeight"] = true + return this + } + fun label(text: String): Node { attributes["label"] = text return this diff --git a/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/scripting/ScriptsSection.kt b/app/src/main/kotlin/me/rhunk/snapenhance/ui/manager/sections/scripting/ScriptsSection.kt @@ -93,11 +93,15 @@ class ScriptsSection : Section() { } } - val padding = cachedAttributes["padding"]?.toString()?.toInt()?.let { abs(it) } ?: 2 val arrangement = cachedAttributes["arrangement"] val alignment = cachedAttributes["alignment"] val spacing = cachedAttributes["spacing"]?.toString()?.toInt()?.let { abs(it) } + val rowColumnModifier = Modifier + .then(if (cachedAttributes["fillMaxWidth"] as? Boolean == true) Modifier.fillMaxWidth() else Modifier) + .then(if (cachedAttributes["fillMaxHeight"] as? Boolean == true) Modifier.fillMaxHeight() else Modifier) + .padding((cachedAttributes["padding"]?.toString()?.toInt()?.let { abs(it) } ?: 2).dp) + fun runCallbackSafe(callback: () -> Unit) { runCatching { callback() @@ -120,9 +124,7 @@ class ScriptsSection : Section() { Column( verticalArrangement = arrangement as? Arrangement.Vertical ?: spacing?.let { Arrangement.spacedBy(it.dp) } ?: Arrangement.Top, horizontalAlignment = alignment as? Alignment.Horizontal ?: Alignment.Start, - modifier = Modifier - .fillMaxWidth() - .padding(padding.dp) + modifier = rowColumnModifier ) { node.children.forEach { child -> DrawNode(child) @@ -133,9 +135,7 @@ class ScriptsSection : Section() { Row( horizontalArrangement = arrangement as? Arrangement.Horizontal ?: spacing?.let { Arrangement.spacedBy(it.dp) } ?: Arrangement.SpaceBetween, verticalAlignment = alignment as? Alignment.Vertical ?: Alignment.CenterVertically, - modifier = Modifier - .fillMaxWidth() - .padding(padding.dp) + modifier = rowColumnModifier ) { node.children.forEach { child -> DrawNode(child)