mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-12 02:14:57 +00:00
Merge branch 'master' into ab/debug-subs
This commit is contained in:
@@ -32,14 +32,22 @@ struct ProfileImage: View {
|
||||
}
|
||||
}
|
||||
|
||||
private let squareToCircleRatio = 0.935
|
||||
|
||||
private let radiusFactor = (1 - squareToCircleRatio) / 50
|
||||
|
||||
@ViewBuilder func clipProfileImage(_ img: Image, size: CGFloat, radius: Double) -> some View {
|
||||
let v = img.resizable().frame(width: size, height: size)
|
||||
if radius <= 0 {
|
||||
v.clipShape(Rectangle())
|
||||
} else if radius >= 50 {
|
||||
v.clipShape(Circle())
|
||||
let v = img.resizable()
|
||||
if radius >= 50 {
|
||||
v.frame(width: size, height: size).clipShape(Circle())
|
||||
} else if radius <= 0 {
|
||||
let sz = size * squareToCircleRatio
|
||||
v.frame(width: sz, height: sz).padding((size - sz) / 2)
|
||||
} else {
|
||||
v.clipShape(RoundedRectangle(cornerRadius: size * radius / 100, style: .continuous))
|
||||
let sz = size * (squareToCircleRatio + radius * radiusFactor)
|
||||
v.frame(width: sz, height: sz)
|
||||
.clipShape(RoundedRectangle(cornerRadius: sz * radius / 100, style: .continuous))
|
||||
.padding((size - sz) / 2)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+23
-29
@@ -18,11 +18,11 @@ import androidx.compose.ui.unit.*
|
||||
import dev.icerock.moko.resources.compose.painterResource
|
||||
import dev.icerock.moko.resources.compose.stringResource
|
||||
import chat.simplex.common.model.ChatInfo
|
||||
import chat.simplex.common.platform.appPreferences
|
||||
import chat.simplex.common.platform.base64ToBitmap
|
||||
import chat.simplex.common.platform.*
|
||||
import chat.simplex.common.ui.theme.*
|
||||
import chat.simplex.res.MR
|
||||
import dev.icerock.moko.resources.ImageResource
|
||||
import kotlin.math.max
|
||||
|
||||
@Composable
|
||||
fun ChatInfoImage(chatInfo: ChatInfo, size: Dp, iconColor: Color = MaterialTheme.colors.secondaryVariant) {
|
||||
@@ -81,7 +81,7 @@ fun ProfileImage(
|
||||
imageBitmap,
|
||||
stringResource(MR.strings.image_descr_profile_image),
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(size).padding(size / 12).clip(ProfileIconShape())
|
||||
modifier = ProfileIconModifier(size)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -93,17 +93,31 @@ fun ProfileImage(size: Dp, image: ImageResource) {
|
||||
painterResource(image),
|
||||
stringResource(MR.strings.image_descr_profile_image),
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(size).padding(size / 12).clip(ProfileIconShape())
|
||||
modifier = ProfileIconModifier(size)
|
||||
)
|
||||
}
|
||||
|
||||
private const val squareToCircleRatio = 0.935f
|
||||
|
||||
private const val radiusFactor = (1 - squareToCircleRatio) / 50
|
||||
|
||||
@Composable
|
||||
fun ProfileIconShape(): Shape {
|
||||
fun ProfileIconModifier(size: Dp, padding: Boolean = true): Modifier {
|
||||
val percent = remember { appPreferences.profileImageCornerRadius.state }
|
||||
val r = max(0f, percent.value)
|
||||
val pad = if (padding) size / 12 else 0.dp
|
||||
val m = Modifier.size(size)
|
||||
return when {
|
||||
percent.value <= 0 -> RectangleShape
|
||||
percent.value >= 50 -> CircleShape
|
||||
else -> RoundedCornerShape(PercentCornerSize(percent.value))
|
||||
r >= 50 ->
|
||||
m.padding(pad).clip(CircleShape)
|
||||
r <= 0 -> {
|
||||
val sz = (size - 2 * pad) * squareToCircleRatio
|
||||
m.padding((size - sz) / 2)
|
||||
}
|
||||
else -> {
|
||||
val sz = (size - 2 * pad) * (squareToCircleRatio + r * radiusFactor)
|
||||
m.padding((size - sz) / 2).clip(RoundedCornerShape(size = sz * r / 100))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -131,31 +145,11 @@ fun ProfileImageForActiveCall(
|
||||
imageBitmap,
|
||||
stringResource(MR.strings.image_descr_profile_image),
|
||||
contentScale = ContentScale.Crop,
|
||||
modifier = Modifier.size(size).clip(ProfileIconShape())
|
||||
modifier = ProfileIconModifier(size, padding = false)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/** (c) [androidx.compose.foundation.shape.CornerSize] */
|
||||
private data class PercentCornerSize(
|
||||
private val percent: Float
|
||||
) : CornerSize, InspectableValue {
|
||||
init {
|
||||
if (percent < 0 || percent > 100) {
|
||||
throw IllegalArgumentException("The percent should be in the range of [0, 100]")
|
||||
}
|
||||
}
|
||||
|
||||
override fun toPx(shapeSize: Size, density: Density) =
|
||||
shapeSize.minDimension * (percent / 100f)
|
||||
|
||||
override fun toString(): String = "CornerSize(size = $percent%)"
|
||||
|
||||
override val valueOverride: String
|
||||
get() = "$percent%"
|
||||
}
|
||||
|
||||
|
||||
@Preview
|
||||
@Composable
|
||||
fun PreviewChatInfoImage() {
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
name: simplex-chat
|
||||
version: 5.7.0.4
|
||||
version: 5.7.0.5
|
||||
#synopsis:
|
||||
#description:
|
||||
homepage: https://github.com/simplex-chat/simplex-chat#readme
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@ cabal-version: 1.12
|
||||
-- see: https://github.com/sol/hpack
|
||||
|
||||
name: simplex-chat
|
||||
version: 5.7.0.4
|
||||
version: 5.7.0.5
|
||||
category: Web, System, Services, Cryptography
|
||||
homepage: https://github.com/simplex-chat/simplex-chat#readme
|
||||
author: simplex.chat
|
||||
|
||||
@@ -72,11 +72,11 @@ import UnliftIO.Directory (copyFile, createDirectoryIfMissing, doesDirectoryExis
|
||||
|
||||
-- when acting as host
|
||||
minRemoteCtrlVersion :: AppVersion
|
||||
minRemoteCtrlVersion = AppVersion [5, 6, 0, 0]
|
||||
minRemoteCtrlVersion = AppVersion [5, 7, 0, 3]
|
||||
|
||||
-- when acting as controller
|
||||
minRemoteHostVersion :: AppVersion
|
||||
minRemoteHostVersion = AppVersion [5, 7, 0, 0]
|
||||
minRemoteHostVersion = AppVersion [5, 7, 0, 3]
|
||||
|
||||
currentAppVersion :: AppVersion
|
||||
currentAppVersion = AppVersion SC.version
|
||||
|
||||
Reference in New Issue
Block a user