From ba36650c61046243d82169c8a42fc54fcf22d561 Mon Sep 17 00:00:00 2001 From: WesleyEdwards Date: Mon, 18 Mar 2024 15:10:40 -0600 Subject: [PATCH] adding card theme --- .../com/lightningkite/rock/models/Svg.kt | 29 ------------------ .../com/lightningkite/rock/models/Theme.kt | 4 +++ .../com/lightningkite/rock/models/data.kt | 30 ------------------- .../rock/views/ViewContextExtensions.kt | 2 +- .../com/lightningkite/rock/views/NView.js.kt | 2 +- .../rock/views/direct/ImageView.js.kt | 1 - 6 files changed, 6 insertions(+), 62 deletions(-) delete mode 100644 library/src/commonMain/kotlin/com/lightningkite/rock/models/Svg.kt diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/models/Svg.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/models/Svg.kt deleted file mode 100644 index 8aa8ddfd..00000000 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/models/Svg.kt +++ /dev/null @@ -1,29 +0,0 @@ -package com.lightningkite.rock.models - -fun convertToVector(input: String): ImageVector { - val viewBox = Regex("viewBox=\"([^\"]*)\"").find(input)?.groupValues?.get(1)?.split(" ")?.map { it.toInt() } - val width = Regex("width=\"([^\"]*)\"").find(input)?.groupValues?.get(1)?.toInt() - val height = Regex("height=\"([^\"]*)\"").find(input)?.groupValues?.get(1)?.toInt() - val fill = Regex("fill=\"([^\"]*)\"").find(input)?.groupValues?.get(1) - val fillColor = if (fill == null || fill == "none") null else Color.fromHexString(fill) - val stroke = Regex("stroke=\"([^\"]*)\"").find(input)?.groupValues?.get(1) - val strokeColor = if (stroke == null || stroke == "none") null else Color.fromHexString(stroke) - val strokeWidth = Regex("stroke-width=\"([^\"]*)\"").find(input)?.groupValues?.get(1)?.toDouble() - val paths = Regex("]*d=\"([^\"]*)\"[^>]*>").findAll(input).map { it.groupValues[1] }.toList() - return ImageVector( - width = width?.px ?: 24.px, - height = height?.px ?: 24.px, - viewBoxMinX = viewBox?.get(0) ?: 0, - viewBoxMinY = viewBox?.get(1) ?: 0, - viewBoxWidth = viewBox?.get(2) ?: 24, - viewBoxHeight = viewBox?.get(3) ?: 24, - paths = paths.map { path -> - ImageVector.Path( - path = path, - fillColor = fillColor, - strokeColor = strokeColor, - strokeWidth = strokeWidth, - ) - } - ) -} diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/models/Theme.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/models/Theme.kt index a7179156..914db2f0 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/models/Theme.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/models/Theme.kt @@ -13,6 +13,7 @@ data class Theme( val outline: Paint = Color.black, val outlineWidth: Dimension = 0.px, val background: Paint = Color.white, + val card: (Theme.() -> Theme) = { this }, val hover: (Theme.() -> Theme) = { copy( background = this.background.closestColor().highlight(0.2f), @@ -88,6 +89,9 @@ data class Theme( ) { val icon: Paint get() = iconOverride ?: foreground + private var cardCache: Theme? = null + @JsName("cardDirect") + fun card() = cardCache ?: card(this).also { cardCache = it } private var dialogCache: Theme? = null @JsName("dialogDirect") fun dialog() = dialogCache ?: dialog(this).also { dialogCache = it } diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/models/data.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/models/data.kt index c34c568e..f03282eb 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/models/data.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/models/data.kt @@ -96,36 +96,6 @@ data class SizeConstraints( val height: Dimension? = null, ) -data class Insets( - val left: Dimension? = null, - val top: Dimension? = null, - val right: Dimension? = null, - val bottom: Dimension? = null -) { - constructor(all: Dimension) : this(all, all, all, all) - - companion object { - fun zero() = Insets(0.px) - - val none = zero() - - fun symmetric(horizontal: Dimension = 0.px, vertical: Dimension = 0.px) = - Insets(horizontal, vertical, horizontal, vertical) - } -} - -data class TextStyle( - val color: Color = Color.black, - val disabledColor: Color = Color.gray, - val size: Double = 14.0, - val font: Font = systemDefaultFont, - val bold: Boolean = false, - val italic: Boolean = false, - val allCaps: Boolean = false, - val lineSpacingMultiplier: Double = 1.0, - val letterSpacing: Dimension = 0.px, -) - enum class Align { Start, Center, End, Stretch } diff --git a/library/src/commonMain/kotlin/com/lightningkite/rock/views/ViewContextExtensions.kt b/library/src/commonMain/kotlin/com/lightningkite/rock/views/ViewContextExtensions.kt index 9b697c56..ddadbf0c 100644 --- a/library/src/commonMain/kotlin/com/lightningkite/rock/views/ViewContextExtensions.kt +++ b/library/src/commonMain/kotlin/com/lightningkite/rock/views/ViewContextExtensions.kt @@ -42,7 +42,7 @@ var ViewWriter.navigator by viewWriterAddonLateInit() @ViewModifierDsl3 inline fun ViewWriter.tweakTheme(crossinline calculate: suspend (Theme)->Theme?): ViewWrapper { return themeModifier { val e = it(); calculate(e) ?: e } } -@ViewModifierDsl3 val ViewWriter.card: ViewWrapper get() = themeFromLast { it } +@ViewModifierDsl3 val ViewWriter.card: ViewWrapper get() = themeFromLast { it.card() } @ViewModifierDsl3 val ViewWriter.dialog: ViewWrapper get() = themeFromLast { it.dialog() } @ViewModifierDsl3 val ViewWriter.hover: ViewWrapper get() = themeFromLast { it.hover() } @ViewModifierDsl3 val ViewWriter.down: ViewWrapper get() = themeFromLast { it.down() } diff --git a/library/src/jsMain/kotlin/com/lightningkite/rock/views/NView.js.kt b/library/src/jsMain/kotlin/com/lightningkite/rock/views/NView.js.kt index ad1f96ab..5c145beb 100644 --- a/library/src/jsMain/kotlin/com/lightningkite/rock/views/NView.js.kt +++ b/library/src/jsMain/kotlin/com/lightningkite/rock/views/NView.js.kt @@ -81,7 +81,7 @@ actual var NView.spacing: Dimension set(value) { style.setProperty("--spacing", value.value) val cn = "spacingOf${value.value.replace(".", "_").filter { it.isLetterOrDigit() || it == '_' }}" - DynamicCSS.styleIfMissing(".$cn.$cn.$cn.$cn.$cn > *, .$cn.$cn.$cn.$cn.$cn > .hidingContainer > *", mapOf( + DynamicCSS.styleIfMissing(".$cn.$cn.$cn.$cn.$cn.$cn.$cn > *, .$cn.$cn.$cn.$cn.$cn.$cn.$cn > .hidingContainer > *", mapOf( "--parentSpacing" to value.value )) className = className.split(' ').filter { !it.startsWith("spacingOf") }.plus(cn).joinToString(" ") diff --git a/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ImageView.js.kt b/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ImageView.js.kt index 9b9868bd..8e2cb98c 100644 --- a/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ImageView.js.kt +++ b/library/src/jsMain/kotlin/com/lightningkite/rock/views/direct/ImageView.js.kt @@ -83,7 +83,6 @@ fun ImageView.setSrc(url: String) { } for(index in 0..