Skip to content

Commit

Permalink
Merge branch 'main' of github.com:lightningkite/kiteui
Browse files Browse the repository at this point in the history
  • Loading branch information
WesleyEdwards committed Jun 4, 2024
2 parents 0fe6a61 + c8218f7 commit bca23d9
Show file tree
Hide file tree
Showing 9 changed files with 67 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ actual typealias NDismissBackground = ViewGroup
@ViewDsl
actual inline fun ViewWriter.dismissBackgroundActual(crossinline setup: DismissBackground.() -> Unit) = element(SlightlyModifiedFrameLayout(context)) {
handleTheme(this, foreground = { it, view ->
view.setBackgroundColor(it.background.closestColor().copy(alpha = 0.5f).toInt())
view.setBackgroundColor(it.background.closestColor().darken(0.5f).applyAlpha(alpha = 0.5f).toInt())
}) {
setOnClickListener {
navigator.clear()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,16 @@ actual fun ViewWriter.sizedBox(constraints: SizeConstraints): ViewWrapper {
return ViewWrapper
}

@ViewModifierDsl3
actual fun ViewWriter.changingSizeConstraints(constraints: suspend () -> SizeConstraints): ViewWrapper {
wrapNext(DesiredSizeView(this.context)) {
calculationContext.reactiveScope {
this.constraints = constraints()
}
}
return ViewWrapper
}

interface MaxSizeLayoutParams {
var maxWidth: Int
var maxHeight: Int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import kotlin.math.sqrt
sealed interface Paint {
fun closestColor(): Color
fun applyAlpha(alpha: Float): Paint
fun lighten(ratio: Float): Paint
fun darken(ratio: Float): Paint
}

data class GradientStop(val ratio: Float, val color: Color)
Expand All @@ -33,8 +35,8 @@ data class LinearGradient(
override fun applyAlpha(alpha: Float) = copy(stops = stops.map { it.copy(color = it.color.applyAlpha(alpha)) })

fun toGrayscale() = copy(stops = stops.map { it.copy(color = it.color.toGrayscale()) })
fun darken(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.darken(ratio)) })
fun lighten(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.lighten(ratio)) })
override fun darken(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.darken(ratio)) })
override fun lighten(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.lighten(ratio)) })
fun toWhite(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.toWhite(ratio)) })
fun toBlack(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.toBlack(ratio)) })
fun highlight(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.highlight(ratio)) })
Expand All @@ -50,6 +52,8 @@ data class RadialGradient(
}

override fun applyAlpha(alpha: Float) = copy(stops = stops.map { it.copy(color = it.color.applyAlpha(alpha)) })
override fun darken(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.darken(ratio)) })
override fun lighten(ratio: Float) = copy(stops = stops.map { it.copy(color = it.color.lighten(ratio)) })
}

data class Color(
Expand All @@ -76,11 +80,11 @@ data class Color(
)
}

fun darken(ratio: Float): Color = copy(
override fun darken(ratio: Float): Color = copy(
red = red * (1f - ratio), green = green * (1f - ratio), blue = blue * (1f - ratio)
)

fun lighten(ratio: Float): Color = copy(
override fun lighten(ratio: Float): Color = copy(
red = red + (1f - red) * ratio, green = green + (1f - green) * ratio, blue = blue + (1f - blue) * ratio
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ fun ViewWriter.sizeConstraints(
height = height
))
@ViewModifierDsl3
expect fun ViewWriter.changingSizeConstraints(constraints: suspend () -> SizeConstraints): ViewWrapper
@ViewModifierDsl3
@Deprecated("No longer needed - just tell the parent what its spacing value should be.")
val ViewWriter.marginless: ViewWrapper get() = ViewWrapper
@ViewModifierDsl3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ actual inline fun ViewWriter.dismissBackgroundActual(crossinline setup: DismissB
handleTheme(
this,
foreground = {
backgroundColor = it.background.closestColor().copy(alpha = 0.5f).toUiColor()
backgroundColor = it.background.closestColor().darken(0.5f).applyAlpha(alpha = 0.5f).toUiColor()
},
) {
val d = DismissBackground(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,17 @@ actual fun ViewWriter.sizedBox(constraints: SizeConstraints): ViewWrapper {
return ViewWrapper
}

@ViewModifierDsl3
actual fun ViewWriter.changingSizeConstraints(constraints: suspend () -> SizeConstraints): ViewWrapper {
beforeNextElementSetup {
calculationContext.reactiveScope {
extensionSizeConstraints = constraints()
informParentOfSizeChange()
}
}
return ViewWrapper
}

@ViewModifierDsl3
actual val ViewWriter.padded: ViewWrapper
get() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1322,7 +1322,7 @@ object DynamicCSS {
"outline-width" to "0",
"backdrop-filter" to "blur(5px)",
"-webkit-backdrop-filter" to "blur(5px)",
) + when (val it = theme.background.applyAlpha(0.5f)) {
) + when (val it = theme.background.darken(0.5f).applyAlpha(0.5f)) {
is Color -> mapOf("background-color" to it.toCss())
is LinearGradient -> mapOf(
"background-image" to "linear-gradient(${it.angle.plus(Angle.quarterTurn).turns}turn, ${
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,30 +366,43 @@ actual val ViewWriter.scrollsHorizontally: ViewWrapper
return ViewWrapper
}

@ViewModifierDsl3
actual fun ViewWriter.sizedBox(constraints: SizeConstraints): ViewWrapper {
beforeNextElementSetup {
private fun NView.applySizeConstraints(constraints: SizeConstraints) {
if (constraints.minHeight == null) style.removeProperty("minHeight")
else style.minHeight = constraints.minHeight.value

if (constraints.minHeight == null) style.removeProperty("minHeight")
else style.minHeight = constraints.minHeight.value
if (constraints.maxHeight == null) style.removeProperty("maxHeight")
else style.maxHeight = constraints.maxHeight.value

if (constraints.maxHeight == null) style.removeProperty("maxHeight")
else style.maxHeight = constraints.maxHeight.value
if (constraints.minWidth == null) style.removeProperty("minWidth")
else style.minWidth = constraints.minWidth.value

if (constraints.minWidth == null) style.removeProperty("minWidth")
else style.minWidth = constraints.minWidth.value
if (constraints.maxWidth == null) style.removeProperty("maxWidth")
else style.maxWidth = constraints.maxWidth.value

if (constraints.maxWidth == null) style.removeProperty("maxWidth")
else style.maxWidth = constraints.maxWidth.value
if (constraints.aspectRatio == null) style.removeProperty("aspect-ratio")
else style.setProperty("aspect-ratio", "${constraints.aspectRatio.first} / ${constraints.aspectRatio.second}")

if (constraints.aspectRatio == null) style.removeProperty("aspect-ratio")
else style.setProperty("aspect-ratio", "${constraints.aspectRatio.first} / ${constraints.aspectRatio.second}")
if (constraints.width == null) style.removeProperty("width")
else style.width = constraints.width.value

if (constraints.width == null) style.removeProperty("width")
else style.width = constraints.width.value
if (constraints.height == null) style.removeProperty("height")
else style.height = constraints.height.value
}

if (constraints.height == null) style.removeProperty("height")
else style.height = constraints.height.value
@ViewModifierDsl3
actual fun ViewWriter.sizedBox(constraints: SizeConstraints): ViewWrapper {
beforeNextElementSetup {
applySizeConstraints(constraints)
}
return ViewWrapper
}

@ViewModifierDsl3
actual fun ViewWriter.changingSizeConstraints(constraints: suspend () -> SizeConstraints): ViewWrapper {
beforeNextElementSetup {
calculationContext.reactiveScope {
applySizeConstraints(constraints())
}
}
return ViewWrapper
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,9 @@ actual val ViewWriter.scrollsHorizontally: ViewWrapper get() = TODO()
@ViewModifierDsl3
actual fun ViewWriter.sizedBox(constraints: SizeConstraints): ViewWrapper = TODO()

@ViewModifierDsl3
actual fun ViewWriter.changingSizeConstraints(constraints: suspend () -> SizeConstraints): ViewWrapper = TODO()

@ViewModifierDsl3
actual val ViewWriter.padded: ViewWrapper get() = TODO()

Expand Down

0 comments on commit bca23d9

Please sign in to comment.