Add unsafe values mode to enable broader input range

This commit is contained in:
Kyant0 committed 2025-06-20 15:39:48 +08:00
1 parent 2391aef5bf
commit 6dd080078b
7 files changed
+23 -5

No files matched your search

Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,5 +1,6 @@
package com.kyant.glass.playground
import androidx.compose.animation.animateContentSize
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Arrangement
import androidx.compose.foundation.layout.Column
@@ -16,7 +17,9 @@ import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import com.kyant.expressa.components.button.Button
import com.kyant.expressa.components.iconbutton.IconButton
import com.kyant.expressa.m3.motion.MotionScheme
import com.kyant.expressa.m3.shape.CornerShape
import com.kyant.expressa.prelude.*
import com.kyant.expressa.ui.Icon
@@ -97,6 +100,13 @@ fun ConfigurationBottomSheet(
}
ConfigurationMode.Advanced -> {
Button({ state.unsafeMode = !state.unsafeMode }) {
Text(
if (state.unsafeMode) stringResource(R.string.disable_unsafe_mode)
else stringResource(R.string.enable_unsafe_mode),
Modifier.animateContentSize(MotionScheme.fastSpatial())
)
}
SliderChip(
state.bleedOpacity,
stringResource(R.string.bleed_opacity),
@@ -34,6 +34,7 @@ class PreviewState {
}
var displayControls: Boolean by mutableStateOf(true)
var unsafeMode: Boolean by mutableStateOf(false)
var imageBitmap: ImageBitmap? by mutableStateOf(null)
@@ -168,15 +169,18 @@ class PreviewState {
private var state: T by mutableStateOf(initialValue)
val range: ClosedRange<T>
get() = if (unsafeMode) valueRange() else safeValueRange()
val value: T by derivedStateOf {
state.coerceIn(valueRange())
state.coerceIn(range)
}
val unsafeValue: T
get() = state
val isValid: Boolean by derivedStateOf {
state in valueRange()
state in range
}
val isSafe: Boolean by derivedStateOf {
@@ -184,7 +188,7 @@ class PreviewState {
}
val progress: Float by derivedStateOf {
val range = valueRange()
val range = range
if (range.isEmpty()) {
0f
} else {
@@ -208,7 +212,7 @@ class PreviewState {
}
fun setValue(value: T) {
state = value.coerceIn(valueRange())
state = value.coerceIn(range)
}
fun setFloatValue(value: Float) {
@@ -216,7 +220,7 @@ class PreviewState {
}
fun setProgress(progress: Float) {
val range = valueRange()
val range = range
val start = typeConverter.convertToVector(range.start).value
val end = typeConverter.convertToVector(range.endInclusive).value
setFloatValue(lerp(start, end, progress))
@@ -9,8 +9,10 @@
<string name="close">关闭</string>
<string name="colors">颜色</string>
<string name="corner_radius">圆角半径</string>
<string name="disable_unsafe_mode">禁用不安全值</string>
<string name="dispersion_height">色散高度</string>
<string name="eccentric_factor">离心系数</string>
<string name="enable_unsafe_mode">启用不安全值</string>
<string name="height">高度</string>
<string name="hide_controls">隐藏控件</string>
<string name="opacity">不透明度</string>
+2
View File
@@ -9,8 +9,10 @@
<string name="close">Close</string>
<string name="colors">Colors</string>
<string name="corner_radius">Corner radius</string>
<string name="disable_unsafe_mode">Disable unsafe values</string>
<string name="dispersion_height">Dispersion height</string>
<string name="eccentric_factor">Eccentric factor</string>
<string name="enable_unsafe_mode">Enable unsafe values</string>
<string name="height">Height</string>
<string name="hide_controls">Hide controls</string>
<string name="opacity">Opacity</string>