|
|
@ -4,7 +4,6 @@ import androidx.compose.foundation.background
|
|
|
|
import androidx.compose.foundation.combinedClickable
|
|
|
|
import androidx.compose.foundation.combinedClickable
|
|
|
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
|
import androidx.compose.foundation.interaction.MutableInteractionSource
|
|
|
|
import androidx.compose.foundation.isSystemInDarkTheme
|
|
|
|
import androidx.compose.foundation.isSystemInDarkTheme
|
|
|
|
import androidx.compose.material3.LocalMinimumTouchTargetEnforcement
|
|
|
|
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.material3.MaterialTheme
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.runtime.remember
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
|
import androidx.compose.ui.Modifier
|
|
|
@ -13,16 +12,7 @@ import androidx.compose.ui.draw.alpha
|
|
|
|
import androidx.compose.ui.input.key.Key
|
|
|
|
import androidx.compose.ui.input.key.Key
|
|
|
|
import androidx.compose.ui.input.key.key
|
|
|
|
import androidx.compose.ui.input.key.key
|
|
|
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
|
|
|
import androidx.compose.ui.input.key.onPreviewKeyEvent
|
|
|
|
import androidx.compose.ui.layout.LayoutModifier
|
|
|
|
|
|
|
|
import androidx.compose.ui.layout.Measurable
|
|
|
|
|
|
|
|
import androidx.compose.ui.layout.MeasureResult
|
|
|
|
|
|
|
|
import androidx.compose.ui.layout.MeasureScope
|
|
|
|
|
|
|
|
import androidx.compose.ui.platform.LocalViewConfiguration
|
|
|
|
|
|
|
|
import androidx.compose.ui.platform.debugInspectorInfo
|
|
|
|
|
|
|
|
import androidx.compose.ui.unit.Constraints
|
|
|
|
|
|
|
|
import androidx.compose.ui.unit.DpSize
|
|
|
|
|
|
|
|
import tachiyomi.presentation.core.components.material.SecondaryItemAlpha
|
|
|
|
import tachiyomi.presentation.core.components.material.SecondaryItemAlpha
|
|
|
|
import kotlin.math.roundToInt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fun Modifier.selectedBackground(isSelected: Boolean): Modifier = composed {
|
|
|
|
fun Modifier.selectedBackground(isSelected: Boolean): Modifier = composed {
|
|
|
|
if (isSelected) {
|
|
|
|
if (isSelected) {
|
|
|
@ -62,47 +52,3 @@ fun Modifier.runOnEnterKeyPressed(action: () -> Unit): Modifier = this.onPreview
|
|
|
|
else -> false
|
|
|
|
else -> false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Suppress("ModifierInspectorInfo")
|
|
|
|
|
|
|
|
fun Modifier.minimumTouchTargetSize(): Modifier = composed(
|
|
|
|
|
|
|
|
inspectorInfo = debugInspectorInfo {
|
|
|
|
|
|
|
|
name = "minimumTouchTargetSize"
|
|
|
|
|
|
|
|
properties["README"] = "Adds outer padding to measure at least 48.dp (default) in " +
|
|
|
|
|
|
|
|
"size to disambiguate touch interactions if the element would measure smaller"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
if (LocalMinimumTouchTargetEnforcement.current) {
|
|
|
|
|
|
|
|
val size = LocalViewConfiguration.current.minimumTouchTargetSize
|
|
|
|
|
|
|
|
MinimumTouchTargetModifier(size)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
Modifier
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private class MinimumTouchTargetModifier(val size: DpSize) : LayoutModifier {
|
|
|
|
|
|
|
|
override fun MeasureScope.measure(
|
|
|
|
|
|
|
|
measurable: Measurable,
|
|
|
|
|
|
|
|
constraints: Constraints,
|
|
|
|
|
|
|
|
): MeasureResult {
|
|
|
|
|
|
|
|
val placeable = measurable.measure(constraints)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Be at least as big as the minimum dimension in both dimensions
|
|
|
|
|
|
|
|
val width = maxOf(placeable.width, size.width.roundToPx())
|
|
|
|
|
|
|
|
val height = maxOf(placeable.height, size.height.roundToPx())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return layout(width, height) {
|
|
|
|
|
|
|
|
val centerX = ((width - placeable.width) / 2f).roundToInt()
|
|
|
|
|
|
|
|
val centerY = ((height - placeable.height) / 2f).roundToInt()
|
|
|
|
|
|
|
|
placeable.place(centerX, centerY)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun equals(other: Any?): Boolean {
|
|
|
|
|
|
|
|
val otherModifier = other as? MinimumTouchTargetModifier ?: return false
|
|
|
|
|
|
|
|
return size == otherModifier.size
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
override fun hashCode(): Int {
|
|
|
|
|
|
|
|
return size.hashCode()
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|