Introduce CropDefaults
This commit is contained in:
1 parent
b820159736
commit
4c7b4dbc51
3 files changed
+12
-3
No files matched your search
@@ -0,0 +1,8 @@
|
||||
package com.hippo.ehviewer.ui.compose
|
||||
|
||||
object CropDefaults {
|
||||
private const val CROP_MIN_ASPECT = 0.5F
|
||||
private const val CROP_MAX_ASPECT = 0.8f
|
||||
private val CROP_GOOD_RANGE = CROP_MIN_ASPECT..CROP_MAX_ASPECT
|
||||
fun shouldCrop(width: Int, height: Int) = width.toFloat() / height in CROP_GOOD_RANGE
|
||||
}
|
||||
@@ -45,7 +45,7 @@ fun EhAsyncCropThumb(
|
||||
onState = {
|
||||
if (it is AsyncImagePainter.State.Success) {
|
||||
it.result.drawable.run {
|
||||
if (intrinsicWidth.toFloat() / intrinsicHeight in 0.5..0.8) {
|
||||
if (CropDefaults.shouldCrop(intrinsicWidth, intrinsicHeight)) {
|
||||
contentScale = ContentScale.Crop
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,7 @@ import coil.request.ImageRequest
|
||||
import com.hippo.ehviewer.client.data.GalleryPreview
|
||||
import com.hippo.ehviewer.client.data.NormalGalleryPreview
|
||||
import com.hippo.ehviewer.coil.imageRequest
|
||||
import com.hippo.ehviewer.ui.compose.CropDefaults
|
||||
import com.hippo.ehviewer.ui.compose.CrystalCard
|
||||
|
||||
@Composable
|
||||
@@ -67,12 +68,12 @@ fun EhAsyncPreview(
|
||||
if (it is AsyncImagePainter.State.Success) {
|
||||
model.run {
|
||||
if (this is NormalGalleryPreview) {
|
||||
if (clipWidth.toFloat() / clipHeight in 0.5..0.8) {
|
||||
if (CropDefaults.shouldCrop(clipWidth, clipHeight)) {
|
||||
contentScale = ContentScale.Crop
|
||||
}
|
||||
} else {
|
||||
it.result.drawable.run {
|
||||
if (intrinsicWidth.toFloat() / intrinsicHeight in 0.5..0.8) {
|
||||
if (CropDefaults.shouldCrop(intrinsicWidth, intrinsicHeight)) {
|
||||
contentScale = ContentScale.Crop
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user