From 77bf7b383b8e9e6260cd1731e9a16951f47c2b70 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Mon, 16 Nov 2026 20:49:09 +0000 Subject: [PATCH 1/3] desktop: full-screen images zoom and pan (#8237) * desktop: full-screen images zoom and pan as on mobile * plans: desktop image zoom * ui: one pan bound for the wheel and the drag, and desktop drags keep a full-screen image open * plans: desktop image zoom keeps Android gestures as on stable * ui: base gestures on Android, fitted-image pan bound on desktop * plans: desktop zoom handlers before the layer, questions for the user * ui: desktop zoom handlers in view coordinates, base Android chain * plans: desktop zoom drags past 4 dp, keyed by image size * ui: desktop pan past 4 dp, primary button, keys by image size * desktop: zoom in desktop actuals, slower macOS trackpad zoom * plans: desktop zoom in desktop actuals, macOS trackpad speed * plans: desktop zoom macOS trackpad speed options for the user * desktop: even macOS scroll zoom, zoomed video clipped above its controls * desktop: zoom plan with decisions and mechanics only * desktop: zoomed drag kept when the image size changes, fewer zoom tests * desktop: zoom plan states the macOS wheel rate and the drag change * desktop: zoom tests run each scene on the AWT event thread --- .../chat/item/ImageFullScreenView.desktop.kt | 94 ++++++++- .../simplex/app/ImageFullScreenZoomTest.kt | 199 ++++++++++++++++++ plans/2026-11-15-desktop-image-zoom.md | 58 +++++ 3 files changed, 346 insertions(+), 5 deletions(-) create mode 100644 apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt create mode 100644 plans/2026-11-15-desktop-image-zoom.md diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt index c1d4a40dae..1a8958f437 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt @@ -1,13 +1,20 @@ package chat.simplex.common.views.chat.item import androidx.compose.foundation.* +import androidx.compose.foundation.gestures.awaitEachGesture +import androidx.compose.foundation.gestures.awaitFirstDown import androidx.compose.foundation.layout.* import androidx.compose.material.* import androidx.compose.runtime.* import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier +import androidx.compose.ui.draw.clipToBounds +import androidx.compose.ui.geometry.Offset import androidx.compose.ui.graphics.* +import androidx.compose.ui.input.pointer.* import androidx.compose.ui.layout.ContentScale +import androidx.compose.ui.layout.onSizeChanged +import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import chat.simplex.common.platform.* import chat.simplex.common.views.helpers.getBitmapFromByteArray @@ -16,16 +23,23 @@ import dev.icerock.moko.resources.compose.painterResource import dev.icerock.moko.resources.compose.stringResource import org.jetbrains.compose.videoplayer.SkiaBitmapVideoSurface import kotlin.math.max +import kotlin.math.min +import kotlin.math.pow + +private const val WHEEL_ZOOM_STEP = 1.2f +private const val MAC_SCROLL_UNITS_PER_NOTCH = 3f +private val DRAG_THRESHOLD = 4.dp @Composable actual fun FullScreenImageView(modifier: Modifier, data: ByteArray, imageBitmap: ImageBitmap) { // Decoded once, as an animation recomposes this on every frame val still = remember(data) { getBitmapFromByteArray(data, false) ?: MR.images.decentralized.image.toComposeImageBitmap() } + val image = rememberAnimatedImage(data, still) Image( - rememberAnimatedImage(data, still), + image, contentDescription = stringResource(MR.strings.image_descr), contentScale = ContentScale.Fit, - modifier = modifier, + modifier = modifier.zoomable(image), ) } @@ -33,7 +47,7 @@ actual fun FullScreenImageView(modifier: Modifier, data: ByteArray, imageBitmap: actual fun FullScreenVideoView(player: VideoPlayer, modifier: Modifier, close: () -> Unit) { Box { Box(Modifier.fillMaxSize().padding(bottom = 50.dp)) { - SurfaceFromPlayer(player, modifier) + SurfaceFromPlayer(player, modifier, frameModifier = { Modifier.zoomable(it) }) IconButton(onClick = close, Modifier.padding(top = 5.dp)) { Icon(painterResource(MR.images.ic_arrow_back_ios_new), null, Modifier.size(30.dp), tint = MaterialTheme.colors.primary) } @@ -43,7 +57,7 @@ actual fun FullScreenVideoView(player: VideoPlayer, modifier: Modifier, close: ( } @Composable -fun BoxScope.SurfaceFromPlayer(player: VideoPlayer, modifier: Modifier, contentScale: ContentScale = ContentScale.Fit) { +fun BoxScope.SurfaceFromPlayer(player: VideoPlayer, modifier: Modifier, contentScale: ContentScale = ContentScale.Fit, frameModifier: @Composable (ImageBitmap) -> Modifier = { Modifier }) { val surface = remember { SkiaBitmapVideoSurface().also { player.player.videoSurface().set(it) @@ -52,7 +66,7 @@ fun BoxScope.SurfaceFromPlayer(player: VideoPlayer, modifier: Modifier, contentS surface.bitmap.value?.let { bitmap -> Image( bitmap, - modifier = modifier.align(Alignment.Center), + modifier = modifier.then(frameModifier(bitmap)).align(Alignment.Center), contentDescription = null, contentScale = contentScale, alignment = Alignment.Center, @@ -76,3 +90,73 @@ private fun BoxScope.Controls(player: VideoPlayer) { ) } } + +@Composable +private fun Modifier.zoomable(content: ImageBitmap): Modifier { + var scale by remember { mutableStateOf(1f) } + var translation by remember { mutableStateOf(Offset.Zero) } + var viewSize by remember { mutableStateOf(IntSize.Zero) } + val contentSize by rememberUpdatedState(IntSize(content.width, content.height)) + fun panBy(delta: Offset) { + translation = boundTranslation(translation + delta, viewSize, contentSize, scale) + } + LaunchedEffect(contentSize) { panBy(Offset.Zero) } + return this + .onSizeChanged { + viewSize = it + panBy(Offset.Zero) + } + .pointerInput(Unit) { + detectDragPastThreshold { pan -> panBy(pan) } + } + .pointerInput(Unit) { + awaitPointerEventScope { + while (true) { + val event = awaitPointerEvent() + if (event.type != PointerEventType.Scroll) continue + val change = event.changes.first() + if (change.scrollDelta.y == 0f) continue + val notches = wheelNotches(change.scrollDelta.y) + val zoomed = (scale * WHEEL_ZOOM_STEP.pow(-notches)).coerceIn(1f, 20f) + val pointer = change.position - Offset(size.width / 2f, size.height / 2f) - translation + val shift = pointer * (1 - zoomed / scale) + scale = zoomed + panBy(shift) + change.consume() + } + } + } + .clipToBounds() + .graphicsLayer { + scaleX = scale + scaleY = scale + translationX = translation.x + translationY = translation.y + } +} + +private fun boundTranslation(translation: Offset, view: IntSize, content: IntSize, scale: Float): Offset { + val fit = min(view.width.toFloat() / content.width, view.height.toFloat() / content.height) + val maxX = max(0f, (content.width * fit * scale - view.width) / 2) + val maxY = max(0f, (content.height * fit * scale - view.height) / 2) + return Offset(translation.x.coerceIn(-maxX, maxX), translation.y.coerceIn(-maxY, maxY)) +} + +private suspend fun PointerInputScope.detectDragPastThreshold(onDrag: (Offset) -> Unit) = awaitEachGesture { + val down = awaitFirstDown(requireUnconsumed = false) + var pan = Offset.Zero + var dragging = false + do { + val change = awaitPointerEvent().changes.firstOrNull { it.id == down.id } ?: break + pan += change.positionChange() + if (!dragging) dragging = pan.getDistance() > DRAG_THRESHOLD.toPx() + if (dragging) { + onDrag(pan) + pan = Offset.Zero + change.consume() + } + } while (change.pressed) +} + +private fun wheelNotches(scrollDelta: Float): Float = + if (desktopPlatform.isMac()) scrollDelta / MAC_SCROLL_UNITS_PER_NOTCH else scrollDelta diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt new file mode 100644 index 0000000000..c43be77693 --- /dev/null +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt @@ -0,0 +1,199 @@ +package chat.simplex.app + +import androidx.compose.foundation.layout.Box +import androidx.compose.foundation.layout.padding +import androidx.compose.foundation.layout.size +import androidx.compose.runtime.Composable +import androidx.compose.runtime.mutableStateOf +import androidx.compose.ui.ExperimentalComposeUiApi +import androidx.compose.ui.ImageComposeScene +import androidx.compose.ui.Modifier +import androidx.compose.ui.geometry.Offset +import androidx.compose.ui.graphics.Color +import androidx.compose.ui.graphics.toComposeImageBitmap +import androidx.compose.ui.input.pointer.PointerButton +import androidx.compose.ui.input.pointer.PointerButtons +import androidx.compose.ui.input.pointer.PointerEventType +import androidx.compose.ui.unit.Density +import androidx.compose.ui.unit.DpSize +import androidx.compose.ui.unit.dp +import androidx.compose.ui.use +import androidx.compose.ui.window.WindowState +import chat.simplex.common.simplexWindowState +import chat.simplex.common.views.chat.ProviderMedia +import chat.simplex.common.views.chat.item.ImageFullScreenView +import chat.simplex.common.views.chat.item.ImageGalleryProvider +import kotlinx.coroutines.Dispatchers +import kotlinx.coroutines.runBlocking +import kotlinx.coroutines.swing.Swing +import org.jetbrains.skia.Bitmap +import org.jetbrains.skia.Image +import java.awt.image.BufferedImage +import java.io.ByteArrayOutputStream +import javax.imageio.ImageIO +import kotlin.test.Test +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue + +@OptIn(ExperimentalComposeUiApi::class) +class ImageFullScreenZoomTest { + private fun quadrants(width: Int, height: Int): ByteArray { + val image = BufferedImage(width, height, BufferedImage.TYPE_INT_RGB) + image.createGraphics().apply { + color = java.awt.Color.RED + fillRect(0, 0, width / 2, height / 2) + color = java.awt.Color.BLUE + fillRect(width / 2, 0, width / 2, height / 2) + color = java.awt.Color.GREEN + fillRect(0, height / 2, width / 2, height / 2) + color = java.awt.Color.YELLOW + fillRect(width / 2, height / 2, width / 2, height / 2) + dispose() + } + return ByteArrayOutputStream().also { ImageIO.write(image, "png", it) }.toByteArray() + } + + private fun gallery(image: ByteArray, data: () -> ByteArray = { image }) = object : ImageGalleryProvider { + private val bitmap = Image.makeFromEncoded(image).toComposeImageBitmap() + override val initialIndex = 0 + override val totalMediaSize = mutableStateOf(1) + override fun getMedia(index: Int) = if (index == 0) ProviderMedia.Image(data(), bitmap) else null + override fun currentPageChanged(index: Int) {} + override fun scrollToStart() {} + override fun onDismiss(index: Int) {} + } + + private enum class Shown { RED, BLUE, GREEN, YELLOW, BACKGROUND } + + private fun ImageComposeScene.shownAt(x: Int, y: Int = 200): Shown? { + val color = Color(Bitmap.makeFromImage(render()).getColor(x, y)) + fun high(c: Float) = c > 0.8f + fun low(c: Float) = c < 0.2f + return when { + high(color.red) && low(color.green) && low(color.blue) -> Shown.RED + low(color.red) && low(color.green) && high(color.blue) -> Shown.BLUE + low(color.red) && high(color.green) && low(color.blue) -> Shown.GREEN + high(color.red) && high(color.green) && low(color.blue) -> Shown.YELLOW + color.red < 0.1f && color.green < 0.1f && color.blue < 0.1f -> Shown.BACKGROUND + else -> null + } + } + + private fun ImageComposeScene.wheel(x: Float, notches: Float) { + sendPointerEvent(PointerEventType.Scroll, Offset(x, 300f), scrollDelta = Offset(0f, notches)) + render() + } + + private fun ImageComposeScene.drag(from: Offset, to: Offset, steps: Int = 1, beforeEachMove: () -> Unit = {}) { + sendPointerEvent(PointerEventType.Press, from, buttons = PointerButtons(isPrimaryPressed = true), button = PointerButton.Primary) + for (step in 1..steps) { + beforeEachMove() + sendPointerEvent(PointerEventType.Move, from + (to - from) * (step.toFloat() / steps), buttons = PointerButtons(isPrimaryPressed = true)) + render() + } + sendPointerEvent(PointerEventType.Release, to, buttons = PointerButtons(), button = PointerButton.Primary) + } + + private fun ImageComposeScene.click(x: Float) { + sendPointerEvent(PointerEventType.Press, Offset(x, 300f), buttons = PointerButtons(isPrimaryPressed = true), button = PointerButton.Primary) + sendPointerEvent(PointerEventType.Release, Offset(x, 300f), buttons = PointerButtons(), button = PointerButton.Primary) + } + + private fun fullScreen( + provider: ImageGalleryProvider = gallery(quadrants(400, 200)), + wrapper: @Composable (@Composable () -> Unit) -> Unit = { it() }, + test: ImageComposeScene.(closed: () -> Boolean) -> Unit + ) { + var closed = false + simplexWindowState.windowState = WindowState(size = DpSize(800.dp, 600.dp)) + runBlocking(Dispatchers.Swing) { + ImageComposeScene(800, 600, Density(1f), coroutineContext = Dispatchers.Unconfined) { + wrapper { ImageFullScreenView({ provider }) { closed = true } } + }.use { scene -> scene.test { closed } } + } + } + + @Test + fun testWheelZoomsAtThePointerDragPansAndWheelBackFits() = fullScreen { closed -> + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(390), shownAt(410))) + wheel(200f, -3f) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(530), shownAt(560))) + drag(Offset(300f, 300f), Offset(200f, 300f)) + assertFalse(closed()) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(430), shownAt(460))) + wheel(200f, 10f) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(390), shownAt(410))) + drag(Offset(300f, 300f), Offset(500f, 300f)) + assertFalse(closed()) + click(300f) + assertTrue(closed()) + } + + @Test + fun testDragKeepsALetterboxedImageInTheView() = fullScreen(gallery(quadrants(200, 400))) { closed -> + wheel(400f, -8f) + drag(Offset(750f, 300f), Offset(50f, 300f)) + drag(Offset(750f, 300f), Offset(50f, 300f)) + assertFalse(closed()) + assertEquals(Shown.BLUE, shownAt(790, 200)) + } + + @Test + fun testShortDragAt4xPansWithThePointer() = fullScreen { closed -> + wheel(400f, -8f) + drag(Offset(400f, 300f), Offset(340f, 300f), steps = 6) + assertFalse(closed()) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(330), shownAt(350))) + } + + @Test + fun testDragFollowsThePointerWhileTheGalleryDecodesTheImageAgain() { + val image = quadrants(400, 200) + val larger = quadrants(800, 400) + val data = mutableStateOf(image) + fullScreen(gallery(image) { data.value }) { closed -> + wheel(400f, -8f) + drag(Offset(400f, 300f), Offset(340f, 300f), steps = 6) { + data.value = larger.copyOf() + render() + } + assertFalse(closed()) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(330), shownAt(350))) + } + } + + @Test + fun testSecondaryButtonDragDoesNotPan() = fullScreen { _ -> + wheel(400f, -3f) + sendPointerEvent(PointerEventType.Press, Offset(500f, 300f), buttons = PointerButtons(isSecondaryPressed = true), button = PointerButton.Secondary) + sendPointerEvent(PointerEventType.Move, Offset(400f, 300f), buttons = PointerButtons(isSecondaryPressed = true)) + sendPointerEvent(PointerEventType.Release, Offset(400f, 300f), buttons = PointerButtons(), button = PointerButton.Secondary) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(390), shownAt(410))) + } + + @Test + fun testClickWithPointerJitterCloses() = fullScreen { closed -> + wheel(400f, -8f) + drag(Offset(300f, 300f), Offset(301f, 300f)) + assertTrue(closed()) + } + + @Test + fun testNarrowerViewKeepsTheZoomedImageInIt() { + val width = mutableStateOf(800) + fullScreen(wrapper = { Box(Modifier.size(width.value.dp, 600.dp)) { it() } }) { _ -> + wheel(0f, -3f) + assertEquals(Shown.RED, shownAt(600)) + width.value = 600 + render() + assertEquals(Shown.RED, shownAt(15)) + } + } + + @Test + fun testZoomedImageIsClippedToItsView() = fullScreen(wrapper = { Box(Modifier.padding(bottom = 100.dp)) { it() } }) { _ -> + wheel(400f, -8f) + assertEquals(listOf(Shown.GREEN, Shown.BACKGROUND), listOf(shownAt(300, 490), shownAt(300, 510))) + } +} diff --git a/plans/2026-11-15-desktop-image-zoom.md b/plans/2026-11-15-desktop-image-zoom.md new file mode 100644 index 0000000000..bb457c36fd --- /dev/null +++ b/plans/2026-11-15-desktop-image-zoom.md @@ -0,0 +1,58 @@ +# Desktop: full-screen images zoom and pan + +## Problem + +On desktop, a full-screen image can't be zoomed. Android zooms it by a two-finger pinch, which a mouse can't make. To see an image at full detail, a desktop user saves the file and opens it in another app. + +## Change + +Common code is the base code: `ImageFullScreenView.kt` and `GestureDetector.kt` are unchanged, so Android behaviour is that of the base. Under a mouse, the view is left as it is by the common modifier: with one pointer, the zoom passed to the base rule by `detectTransformGestures` is 1, and under that rule scale 1 and translation 0 are kept. + +In the desktop actuals of `ImageFullScreenView.desktop.kt`, `zoomable(content)` is appended to the common modifier. `content` is the drawn bitmap: + +- `FullScreenImageView`: the still image or the current animation frame. +- `FullScreenVideoView`: the current VLC frame, passed through the new `frameModifier` parameter of `SurfaceFromPlayer`. The chat item player is called without it. + +In `zoomable`, the scale and the translation of the shown media are remembered. The handlers are placed before the layer, so their coordinates are view coordinates. The state is read in the layer's block, so the view is redrawn without recomposition on each wheel or pan step. + +- The image is zoomed 1.2× per wheel notch at the pointer on Windows and Linux, from 1× to 20×. Every vertical scroll event is taken as a wheel event, a trackpad's included. +- On macOS, every scroll delta is divided by 3 in `wheelNotches`, a wheel's included: a trackpad unit is a third of a notch, and the image is zoomed 1.2^(1/3), about 1.06×, per wheel click with a delta of 1. +- The zoomed image is panned 1:1 with the pointer by a primary-button drag once the pointer has moved more than 4 dp. The drag is then consumed, so the gallery stays open on its release, at 1× too. On the base, the gallery was closed on the release of any drag. The gallery is closed by a click whose pointer moves less than 4 dp, as on the base. Drags with other buttons are ignored. +- After each wheel step, drag step and change of the view's or the content's size, the translation is clamped per axis by `boundTranslation` to `max(0, (w·fit·s − W) / 2)`, with `fit = min(W/w, H/h)`, for content `w×h`, view `W×H` and scale `s`. In an axis where the zoomed content is larger than the view, the view is covered by it; in an axis where it is smaller, it is centred. +- The zoomed content is clipped to the view, so a zoomed video is kept out of its controls row. +- The handlers are started once, and the content's size is read from a state that is updated on each composition, so a drag is kept running when a new bitmap of any size is drawn: an animation frame, a VLC frame, or a decode of data read again. + +```mermaid +flowchart TD + subgraph Common["Common modifier, as on the base"] + C["onGloballyPositioned, layer at scale 1, detectTransformGestures, fillMaxSize"] + end + subgraph Zoomable["Desktop: zoomable(content)"] + S[View or content size change] --> B + D["Primary-button drag past 4 dp: pan 1:1, consumed"] --> B + W["Scroll: delta ÷ 3 on macOS, then scale × 1.2^-notches, 1..20, at the pointer"] --> B + B["boundTranslation: content size, view size, scale"] --> L["Clip to the view, then layer: scale, translation"] + end + C --> S + L --> I["Image: still or animation frame, or VLC frame"] + K[Click under 4 dp] --> X[Gallery closed] +``` + +## Not in this change + +The Android rule is kept as on the base. In a later master item, it is fused with the desktop bound: a vertical bound, translation zero at 1×, and a predicate for mainly horizontal swipes. + +## Tests + +In `ImageFullScreenZoomTest` (desktopTest), the view is rendered in an 800×600 scene, and its pixels are checked after: + +- wheel zoom at the pointer, drag pan and wheel back to fit; the view is kept open by a drag at 1× and closed by a click; +- two long drags of a letterboxed tall image: the image is kept in the view; +- a 60 px drag in 6 steps at 4×: the image is moved 60 px, and the view is kept open; +- the same with a new copy of a 2× larger image returned by the gallery before each step, so the content's size is changed at the first step and a new bitmap is drawn at each step; with handlers keyed by the content's size, the drag is lost and the view is closed on its release; +- a secondary-button drag: nothing is panned; +- a click with 1 px of pointer jitter at 4×: the view is closed; +- a narrower view: the zoomed image is kept over its edge; +- a zoom to 4.3× in a view padded at the bottom: nothing is drawn in the padding. + +In the drag helper, a frame is rendered after each move. One data array is returned by the gallery unless a test replaces it. From 3b88b13bae8e647166318f746df82b1262339595 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Mon, 16 Nov 2026 22:25:22 +0000 Subject: [PATCH 2/3] desktop, android: avatar hover and press in the avatar's shape (#8218) * ui: agent placeholder as white dots on a filled circle; avatar hover and press in its shape The agent avatar is a filled circle with three dots cut out, on iOS (agent.circle.fill) and Android/desktop (ic_avatar_agent), as the other filled placeholders; the small agent icon stays. Avatars in chats take clicks through AvatarClickArea, whose indication is clipped to the avatar: a circle for placeholders, the photo's rounded square for photos, in Flat and Classic rows, for members and channels. * ui: references of the agent placeholder; the profile menu keeps the agent dots The profile menu row draws an outline person, so it keeps the three-dot agent icon at text size. * ios: references of the peer type placeholders with the agent circle * ui: agent placeholder as on stable * ios: remove the unused agent circle image --- .../simplex/common/views/chat/ChatView.kt | 6 ++-- .../views/chat/item/TerminalItemView.kt | 6 ++-- .../common/views/helpers/ChatInfoImage.kt | 29 +++++++++++++++++++ apps/multiplatform/spec/client/chat-view.md | 18 ++++++------ 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt index fc70fb0732..2a83513f36 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt @@ -2122,8 +2122,9 @@ fun BoxScope.ChatItemsList( } Row(Modifier.graphicsLayer { translationX = selectionOffset.toPx() }) { val member = cItem.chatDir.groupMember - Box(Modifier.clickable { showMemberInfo(chatInfo.groupInfo, member) }) { + Box { MemberImage(member, 31.dp * fontSizeSqrtMultiplier, Modifier.centeredIn(MEMBER_IMAGE_SIZE * fontSizeSqrtMultiplier)) + AvatarClickArea(member.image, 31.dp * fontSizeSqrtMultiplier, Modifier.centeredIn(MEMBER_IMAGE_SIZE * fontSizeSqrtMultiplier)) { showMemberInfo(chatInfo.groupInfo, member) } } Box(modifier = Modifier.padding(top = 2.dp, start = 4.dp).chatItemOffset(cItem, itemSeparation.largeGap, revealed = revealed.value)) { ChatItemViewShortHand(cItem, itemSeparation, range, false, dismissState.offset.value) @@ -2198,7 +2199,7 @@ fun BoxScope.ChatItemsList( SelectedListItem(Modifier, cItem.id, selectedChatItems) } Row(Modifier.graphicsLayer { translationX = selectionOffset.toPx() }) { - Box(Modifier.clickable { showChatInfo() }) { + Box { ProfileImage( 31.dp * fontSizeSqrtMultiplier, chatInfo.groupInfo.image, @@ -2206,6 +2207,7 @@ fun BoxScope.ChatItemsList( backgroundColor = MaterialTheme.colors.background, modifier = Modifier.centeredIn(MEMBER_IMAGE_SIZE * fontSizeSqrtMultiplier) ) + AvatarClickArea(chatInfo.groupInfo.image, 31.dp * fontSizeSqrtMultiplier, Modifier.centeredIn(MEMBER_IMAGE_SIZE * fontSizeSqrtMultiplier)) { showChatInfo() } } Box(modifier = Modifier.padding(top = 2.dp, start = 4.dp).chatItemOffset(cItem, itemSeparation.largeGap, revealed = revealed.value)) { ChatItemViewShortHand(cItem, itemSeparation, range, false) diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt index 010a4cecb6..003d2dfbdd 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt @@ -332,8 +332,9 @@ fun chatItemSender( return when { cItem.channelIsSender && chatInfo is ChatInfo.Group -> ChatItemSender(chatInfo.chatViewName, null, stringResource(MR.strings.channel_role_label), dir.sent) { - Box(Modifier.clickable { showChatInfo() }) { + Box { ProfileImage(imageSize, chatInfo.groupInfo.image, chatInfo.groupInfo.chatIconName, backgroundColor = MaterialTheme.colors.background) + AvatarClickArea(chatInfo.groupInfo.image, imageSize, Modifier.matchParentSize()) { showChatInfo() } } } dir is CIDirection.DirectRcv -> @@ -348,8 +349,9 @@ fun chatItemSender( if (memCount == 1) memberRole(member, chatInfo.isChannel) else null, false ) { - Box(Modifier.clickable { showMemberInfo(chatInfo.groupInfo, member) }) { + Box { MemberImage(member, imageSize) + AvatarClickArea(member.image, imageSize, Modifier.matchParentSize()) { showMemberInfo(chatInfo.groupInfo, member) } } } } diff --git a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/ChatInfoImage.kt b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/ChatInfoImage.kt index a0b697847e..0e0f790dcb 100644 --- a/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/ChatInfoImage.kt +++ b/apps/multiplatform/common/src/commonMain/kotlin/chat/simplex/common/views/helpers/ChatInfoImage.kt @@ -16,6 +16,9 @@ import androidx.compose.runtime.remember import androidx.compose.ui.Alignment import androidx.compose.ui.Modifier import androidx.compose.ui.draw.* +import androidx.compose.ui.geometry.CornerRadius +import androidx.compose.ui.geometry.RoundRect +import androidx.compose.ui.geometry.Size import androidx.compose.ui.graphics.* import androidx.compose.ui.layout.ContentScale import androidx.compose.ui.layout.layout @@ -312,6 +315,32 @@ private fun Modifier.insetTo(ratio: Float): Modifier = layout { measurable, cons } } +@Composable +fun profileImageShape(image: String?, size: Dp): Shape { + val percent = remember { appPreferences.profileImageCornerRadius.state } + val r = max(0f, percent.value) + return when { + image == null || r >= 50 -> CircleShape + r <= 0 -> InsetSquareShape(squareToCircleRatio, 0.dp) + else -> { + val ratio = squareToCircleRatio + r * radiusFactor + InsetSquareShape(ratio, size * ratio * r / 100) + } + } +} + +private class InsetSquareShape(private val ratio: Float, private val radius: Dp) : Shape { + override fun createOutline(size: Size, layoutDirection: LayoutDirection, density: Density): Outline { + val inset = ((size.width - size.width * ratio) / 2).roundToInt().toFloat() + return Outline.Rounded(RoundRect(inset, inset, size.width - inset, size.height - inset, CornerRadius(with(density) { radius.toPx() }))) + } +} + +@Composable +fun AvatarClickArea(image: String?, size: Dp, modifier: Modifier, onClick: () -> Unit) { + Box(modifier.clip(profileImageShape(image, size)).clickable(onClick = onClick)) +} + @Preview @Composable fun PreviewChatInfoImage() { diff --git a/apps/multiplatform/spec/client/chat-view.md b/apps/multiplatform/spec/client/chat-view.md index b55b329d5c..2f74d41332 100644 --- a/apps/multiplatform/spec/client/chat-view.md +++ b/apps/multiplatform/spec/client/chat-view.md @@ -128,7 +128,7 @@ The message list is a `LazyColumnWithScrollBar` with `reverseLayout = true`, mea ### Item Layout (ChatViewListItem) -- **Group received messages** with `showAvatar = true`: Column layout with `MemberNameAndRole` header, `MemberImage` (clickable to `showMemberInfo`), and message bubble. The name starts at the bubble edge, 4dp after the avatar, as the bubble (user, as iOS). +- **Group received messages** with `showAvatar = true`: Column layout with `MemberNameAndRole` header, `MemberImage` (clickable to `showMemberInfo`), and message bubble. Avatars in chats take clicks through `AvatarClickArea` over the image: its hover and press indication is clipped to the avatar's shape (`profileImageShape`): a circle for placeholders, the photo's rounded square with the corner radius setting for photos (user); Flat senders use it too. The name starts at the bubble edge, 4dp after the avatar, as the bubble (user, as iOS). - **Group received without avatar:** Indented to align with avatar-bearing messages. - **Sent messages (group or direct):** Right-aligned with larger start padding. - **Direct messages:** Symmetric padding (76dp opposite side). @@ -206,7 +206,7 @@ P + H/2 a sender change in a group, above the avatar (H: TERMINAL_LEVEL_STEP) In chats with avatars the item is in the message column, after the avatar column (section 10, Row Layout). - Cards: images and videos, link previews, chat link cards, code blocks, tables and rules, files, voice messages, the quote, large emoji, group invitations, and the rounded cards of deleted and error items (`ItemTextCard`, `DecryptionErrorCard`). Each is marked with [`Modifier.messageCard()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L239); the marks are read in terminal rows only. A card has `TERMINAL_PARAGRAPH_GAP` next to text or another card of its item, as the top padding of the lower part. At the top of an item it has none above it: `TerminalChatItemRow` adds `TERMINAL_PARAGRAPH_GAP` under the sender row when the item reports a card at its top. At the bottom of an item it has none below it: `ItemWithMeta` adds `gapBelowCard` when the content reports a card at its bottom, [`terminalReactionsGap(item)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L153-L154), `TERMINAL_PARAGRAPH_GAP` when reactions follow as a line of text, otherwise 0. -- Event, feature and member-created items use [`chatEventPadding()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIEventView.kt#L24-L27): in terminal rows the text edge at the sides and no padding above and below, so that the row gap, `TERMINAL_PARAGRAPH_GAP`, separates an event from the rows above and below it (classic: 6dp at the sides, above and below). The icons of feature and preference items are centred on the text and take no height (`Modifier.inlineIcon()`); the row of merged feature icons is one event text line high; both also in bubbles. `CIEventView` has no line limit in terminal rows, so the copy of the time stays at the end of the text (user, D23; classic: 4 lines). Voice and call items, reactions and group invitations start at the text edge. The rounded cards of deleted and error items (`ItemTextCard`, `DecryptionErrorCard`) start [`terminalPillStart()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L454-L455) into the message column: `CHAT_ITEM_TEXT_PADDING` less the gutter of the row, at least 0, read from [`LocalTerminalGutter`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L452), which `TerminalChatItemRow` provides. In groups the card starts at the column and its text, 12dp inside, is on the text edge of the messages, as on master (user); in chats without avatars the card starts at the text edge, 12dp from the screen edge. The voice play button and file status circle are filled with the quote colour (`sentQuote`, `receivedQuote`; classic: `sentMessage`, `receivedMessage`). +- Event, feature and member-created items use [`chatEventPadding()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIEventView.kt#L24-L27): in terminal rows the text edge at the sides and no padding above and below, so that the row gap, `TERMINAL_PARAGRAPH_GAP`, separates an event from the rows above and below it (classic: 6dp at the sides, above and below). The icons of feature and preference items are centred on the text and take no height (`Modifier.inlineIcon()`); the row of merged feature icons is one event text line high; both also in bubbles. `CIEventView` has no line limit in terminal rows, so the copy of the time stays at the end of the text (user, D23; classic: 4 lines). Voice and call items, reactions and group invitations start at the text edge. The rounded cards of deleted and error items (`ItemTextCard`, `DecryptionErrorCard`) start [`terminalPillStart()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L456-L457) into the message column: `CHAT_ITEM_TEXT_PADDING` less the gutter of the row, at least 0, read from [`LocalTerminalGutter`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L454), which `TerminalChatItemRow` provides. In groups the card starts at the column and its text, 12dp inside, is on the text edge of the messages, as on master (user); in chats without avatars the card starts at the text edge, 12dp from the screen edge. The voice play button and file status circle are filled with the quote colour (`sentQuote`, `receivedQuote`; classic: `sentMessage`, `receivedMessage`). - Time and status: placed at the end of the row by [`ItemWithMeta`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L258-L272), the baseline of the time on the last baseline of the content (section 10). Message text ends with [`metaReserveCopy`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIMetaView.kt#L226-L272), in both layouts: a transparent copy of the meta with no-break spaces, in `FontWeight.Normal`. The copy starts with a breaking space (`breakBefore`, user) when text precedes it in its paragraph, so the time alone moves to the next line when it does not fit; the copy of the meta line under a last card or rule (`range` empty) and the copy measured for `ruleMinWidth` start with a word joiner (U+2060), which forbids a line break before the copy. The direction mark of its paragraph follows (U+200E left-to-right, U+200F right-to-left), so that the bidirectional algorithm places the copy at the end of the line, also after words in the other direction on a wrapped last line. Its spaces and texts are appended by [`reserveSpaceForMeta`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIMetaView.kt#L144-L224), which has the conditions of `CIMetaText`, except that the timer is reserved for every timed message, and returns the classic string unchanged, through span parameters: icon spaces and the spaces between them are no-break spaces at the `body1` size in dp (16dp converted to sp with the density, so that they keep their width at every font scale, as the icons do; also after a heading and in event text), 18dp for each icon, wider than a 12dp icon with its spacer (15dp or 16dp); after the 17dp icons one more space is added (22.5dp against 21dp): the sent and received status icons (`tallStatusIcon`, also used by `CIMetaText`) and the via-proxy icon; the time and the timer text of a disappearing message are at 12sp. The copy includes the file encryption and signature icons (`encrypted` and `signedFileVerified` of `MarkdownText`, passed by `CIMarkdownText` from the item). Text whose paragraph direction (`textLayoutDirection`: right-to-left when the first 50 characters of the message text hold a right-to-left character; all blocks and lines of a message take it) differs from the outer direction (`parentDirection`, passed by the blocks and by the meta line of a live message; otherwise `LocalLayoutDirection`) ends with a line break instead of the copy, so the time is placed on an added empty line. Emoji, and the last code block, table or rule of a message, report their width (`Modifier.messageLastLine()`); the time moves under them when the row leaves no room for it beside them. The meta line with the time is drawn under such a block only for live messages, for the typing indicator. In terminal rows the status of an item being sent (`SndNew`), completely sent (`SndSent`, complete), delivered (`SndRcvd`, receipt ok, complete), unread (`RcvNew`) or read (`RcvRead`) is drawn only with the time ([`terminalShowsStatus(status, showTimestamp)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L156-L161)), as on iOS; the status of a partial delivery, an error or a warning is drawn without the time too. `CIMetaView`, `metaReserveCopy` and the size line of files (`CIFileView`) apply it through [`shownStatus(showStatus, meta, showTimestamp)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIMetaView.kt#L274-L276); in bubbles `showStatus` is unchanged. File text keeps the space reserved for the time at the end of its size line. Images and videos without a caption (`captionlessMedia`) keep the meta in `secondary` beside the media when it fits in the row, otherwise the meta is drawn over the bottom end of the media in white, as in the classic layout (`overlayMeta`). Event items are wrapped in [`ChatEventWithMeta`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/CIEventView.kt#L29-L42), which passes the separator and the end of the event text apart (`separator`, `ts`): in the classic layout two spaces and the time without a style, in the terminal layout three transparent no-break spaces in `chatEventStyle` and the transparent `metaReserveCopy` of the meta without status and edit icons, so the last word of the event text is moved to the next line with the time when they do not fit. Each view puts the separator where the classic layout has two spaces (user, D28): after the event text, or in the "Open" and "Accept" links, so the classic output is unchanged. - Group invitations, deleted items and error items (`IntegrityErrorItemView`, `CIRcvDecryptionError`) keep their rounded coloured card. Its shape is [`terminalCardShape()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/ChatItemView.kt#L1262-L1263): 18dp × the `chatItemRoundness` preference, without a tail, as the clip of media (user); square at 0. @@ -441,18 +441,18 @@ Colours: the app, user and chat themes apply as in the classic layout. Wallpaper | [`Modifier.inlineIcon()`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L247-L256) | Terminal: lays the element out with no height, centred on its position, so that a row with `Alignment.CenterVertically` takes the height of its text and centres the element on it: icons of feature and preference items and of message headers. Also in bubbles; outside chats: the modifier unchanged | | [`ItemWithMeta(meta, overlayMeta, metaReserved, endButton, gapBelowCard, content)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L258-L272) | Classic: `content` with the meta passed as `inlineMeta`. Terminal: `content` without meta, and the meta in a box with 12dp end padding at the end of the available width, the row (private [`TerminalMetaLayout`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L274-L314)). `endButton`, in a box with the same end padding, is placed at the end of the row, centred vertically between the content top and the top of the time box (the whole content when the time is over media); the content is measured in the width less the wider of this box and, without `metaReserved`, the time box. The meta is measured first. Without `metaReserved` and `overlayMeta`, the content is measured in the width less the width of the box, so that it does not reach under the time. `metaReserved` is true for content with its own reserve of the space or a reported last line: text with the transparent copy (`metaReserved` of `FramedItemView`), files, emoji and event items. The first baseline of the box (the baseline of the time; without a time, the baseline of a 12sp time centred in the box) is placed on the last baseline of the content. When the content reports its last line and the line and the box together are wider than the row, the box is placed `TERMINAL_META_GAP` (6sp) under the content and the bottom of the row moves down by that gap and the height of the box. When the content reports a card at its bottom (`CardBottom` at the content height), `gapBelowCard` is added below the content (section 4, cards). Content without a baseline (a message of a rule only, a failed call), and captionless media with `overlayMeta`: the box ends `TERMINAL_META_GAP` above the content bottom; when the content and the box together are wider than the row, the `overlayMeta` box is placed at the bottom end of the content instead, `TERMINAL_META_GAP` above its bottom. Either box is placed at the top of the content at most, and the row is at least as tall as the box. When the rule leaves room for the time beside it, the time stays on the baseline of the last text line above it (D24); otherwise it is placed under the rule. | | [`ChatItemSender`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L319) | Name, badge, role label, `own`, avatar | -| [`chatItemSender(chatInfo, cItem, range, reversedChatItems, showMemberInfo, showChatInfo)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L321-L369) | Sender of a row (table below) | -| [`SenderNameAndRole(sender, modifier)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L374-L398) | Private; name and badge (the `body1` size, semibold; primary for own items, `secondary` otherwise; user) and role label (the same size, medium, `secondary`) | -| [`terminalGutter(chatInfo)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L404-L406) | The start of the message column: in groups `TERMINAL_MEMBER_IMAGE_SIZE` (27dp, scaled by `fontSizeSqrtMultiplier`) plus `TERMINAL_AVATAR_GAP` less `TERMINAL_AVATAR_OVERSHOOT`, 35dp, so that the text starts at 47dp; 0 in other chats | -| [`TerminalChatItemRow(sender, gutter, topGap, modifier, content)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L408-L450) | Row layout below; constants `TERMINAL_MEMBER_IMAGE_SIZE`, `TERMINAL_AVATAR_OVERSHOOT` and `TERMINAL_AVATAR_GAP` ([L400-L402](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L400-L402)) | +| [`chatItemSender(chatInfo, cItem, range, reversedChatItems, showMemberInfo, showChatInfo)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L321-L371) | Sender of a row (table below) | +| [`SenderNameAndRole(sender, modifier)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L376-L400) | Private; name and badge (the `body1` size, semibold; primary for own items, `secondary` otherwise; user) and role label (the same size, medium, `secondary`) | +| [`terminalGutter(chatInfo)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L406-L408) | The start of the message column: in groups `TERMINAL_MEMBER_IMAGE_SIZE` (27dp, scaled by `fontSizeSqrtMultiplier`) plus `TERMINAL_AVATAR_GAP` less `TERMINAL_AVATAR_OVERSHOOT`, 35dp, so that the text starts at 47dp; 0 in other chats | +| [`TerminalChatItemRow(sender, gutter, topGap, modifier, content)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L410-L452) | Row layout below; constants `TERMINAL_MEMBER_IMAGE_SIZE`, `TERMINAL_AVATAR_OVERSHOOT` and `TERMINAL_AVATAR_GAP` ([L402-L404](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/item/TerminalItemView.kt#L402-L404)) | In `ChatView.kt`, shared with the classic date separator: | Function | Purpose | |---|---| -| [`terminalRowsSeparated(olderRow)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L3831-L3835) | A date separator or the chat banner between a row and the older row: the newest item of the older row is the banner, or the separation of the older row ([`rowItemSeparation(row, terminal)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L3826-L3829)) has a date. False without an older row. The older row is the row of the nearest shown older item ([`MergedItems.olderShownRow(row)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsMerger.kt#L112-L115)) | +| [`terminalRowsSeparated(olderRow)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L3833-L3837) | A date separator or the chat banner between a row and the older row: the newest item of the older row is the banner, or the separation of the older row ([`rowItemSeparation(row, terminal)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L3828-L3831)) has a date. False without an older row. The older row is the row of the nearest shown older item ([`MergedItems.olderShownRow(row)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatItemsMerger.kt#L112-L115)) | | `rowItemSeparation(row, terminal)` | Private; the separation of a row, also used by `ChatItemsList` for the date separator it draws: `getItemSeparation` of the newest item of the row and the nearest shown newer item (the oldest item of the newer shown row) when the row is revealed (`MergedItem.revealed`: a single item or a revealed group row), without the newer item otherwise (user, D32). In bubbles `ChatItemsList` applies the event run gap to it (section 4, Bubbles) | -| [`getItemSeparation(chatItem, prevItem, terminal)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L3803-L3821) | Private; the time, the large gap and the date between an item and the newer item `prevItem`. The time is hidden when the newer item has the same sender, is less than 60 seconds newer and shows the same minute; in terminal rows it stays shown when the newer item has deleted, moderated or blocked content (`isDeletedContent`) or is marked deleted (`meta.itemDeleted`), although its card shows its own time (user). Bubbles keep this grouping: a bubble before a deleted item in the same minute shows no time | +| [`getItemSeparation(chatItem, prevItem, terminal)`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L3805-L3823) | Private; the time, the large gap and the date between an item and the newer item `prevItem`. The time is hidden when the newer item has the same sender, is less than 60 seconds newer and shows the same minute; in terminal rows it stays shown when the newer item has deleted, moderated or blocked content (`isDeletedContent`) or is marked deleted (`meta.itemDeleted`), although its card shows its own time (user). Bubbles keep this grouping: a bubble before a deleted item in the same minute shows no time | ### Row Layout @@ -475,7 +475,7 @@ item ChatItemView in the message column: at terminalGutter(chatInf row height the lower of the item's bottom and the avatar's bottom ``` -`ChatItemsList` passes [`showAvatar`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L2466) = `terminalItemShowsSender(item, merged.oldest().nextItem)`, the nearest shown older item, and the row gets `chatItemSender(...)` when it is true, `null` otherwise; the [gap above the row](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L2467-L2472), with `terminalRowsSeparated` of the row of that item (`MergedItems.olderShownRow`), is passed to `ChatViewListItem` as `terminalGap`. +`ChatItemsList` passes [`showAvatar`](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L2468) = `terminalItemShowsSender(item, merged.oldest().nextItem)`, the nearest shown older item, and the row gets `chatItemSender(...)` when it is true, `null` otherwise; the [gap above the row](../../common/src/commonMain/kotlin/chat/simplex/common/views/chat/ChatView.kt#L2469-L2474), with `terminalRowsSeparated` of the row of that item (`MergedItems.olderShownRow`), is passed to `ChatViewListItem` as `terminalGap`. ### Sender Rule From cb4b50db169a2638c78e0b41730d5759c559b473 Mon Sep 17 00:00:00 2001 From: "Evgeny @ SimpleX Chat" <259188159+evgeny-simplex@users.noreply.github.com> Date: Mon, 16 Nov 2026 23:48:49 +0000 Subject: [PATCH 3/3] desktop: trackpad pinch zooms full-screen images (#8240) * desktop: plan of trackpad pinch zoom on full-screen images * desktop: test of pinch zoom at the pointer * desktop: trackpad pinch zooms full-screen images on macOS * desktop: pinch listener answers equals, hashCode and toString * desktop: pinch zoom plan covers videos and cites the Windows input --- .../kotlin/chat/simplex/common/DesktopApp.kt | 2 + .../chat/item/ImageFullScreenView.desktop.kt | 47 +++++++++++++++-- .../simplex/app/ImageFullScreenZoomTest.kt | 9 ++++ apps/multiplatform/desktop/build.gradle.kts | 5 +- plans/2026-11-16-desktop-pinch-zoom.md | 51 +++++++++++++++++++ 5 files changed, 108 insertions(+), 6 deletions(-) create mode 100644 plans/2026-11-16-desktop-pinch-zoom.md diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt index 0a197f4da4..04d0929a33 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/DesktopApp.kt @@ -17,6 +17,7 @@ import chat.simplex.common.platform.* import chat.simplex.common.ui.theme.DEFAULT_START_MODAL_WIDTH import chat.simplex.common.ui.theme.SimpleXTheme import chat.simplex.common.views.TerminalView +import chat.simplex.common.views.chat.item.addPinchListener import chat.simplex.common.views.helpers.* import chat.simplex.res.* import dev.icerock.moko.resources.compose.painterResource @@ -202,6 +203,7 @@ private fun ApplicationScope.AppWindow(closedByError: MutableState) { AppLock.appWasHidden() } }) + if (desktopPlatform.isMac()) addPinchListener(window.rootPane) } } } diff --git a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt index 1a8958f437..04e5fe5c9b 100644 --- a/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt +++ b/apps/multiplatform/common/src/desktopMain/kotlin/chat/simplex/common/views/chat/item/ImageFullScreenView.desktop.kt @@ -17,11 +17,15 @@ import androidx.compose.ui.layout.onSizeChanged import androidx.compose.ui.unit.IntSize import androidx.compose.ui.unit.dp import chat.simplex.common.platform.* +import chat.simplex.common.views.helpers.detectCursorMove import chat.simplex.common.views.helpers.getBitmapFromByteArray import chat.simplex.res.* import dev.icerock.moko.resources.compose.painterResource import dev.icerock.moko.resources.compose.stringResource +import kotlinx.coroutines.flow.MutableSharedFlow import org.jetbrains.compose.videoplayer.SkiaBitmapVideoSurface +import java.lang.reflect.Proxy +import javax.swing.JComponent import kotlin.math.max import kotlin.math.min import kotlin.math.pow @@ -30,6 +34,8 @@ private const val WHEEL_ZOOM_STEP = 1.2f private const val MAC_SCROLL_UNITS_PER_NOTCH = 3f private val DRAG_THRESHOLD = 4.dp +internal val pinchZooms = MutableSharedFlow(extraBufferCapacity = Int.MAX_VALUE) + @Composable actual fun FullScreenImageView(modifier: Modifier, data: ByteArray, imageBitmap: ImageBitmap) { // Decoded once, as an animation recomposes this on every frame @@ -96,11 +102,22 @@ private fun Modifier.zoomable(content: ImageBitmap): Modifier { var scale by remember { mutableStateOf(1f) } var translation by remember { mutableStateOf(Offset.Zero) } var viewSize by remember { mutableStateOf(IntSize.Zero) } + var cursor by remember { mutableStateOf(null) } val contentSize by rememberUpdatedState(IntSize(content.width, content.height)) fun panBy(delta: Offset) { translation = boundTranslation(translation + delta, viewSize, contentSize, scale) } + fun zoomAt(position: Offset, zoom: Float) { + val zoomed = (scale * zoom).coerceIn(1f, 20f) + val pointer = position - Offset(viewSize.width / 2f, viewSize.height / 2f) - translation + val shift = pointer * (1 - zoomed / scale) + scale = zoomed + panBy(shift) + } LaunchedEffect(contentSize) { panBy(Offset.Zero) } + LaunchedEffect(Unit) { + pinchZooms.collect { zoom -> cursor?.let { zoomAt(it, zoom) } } + } return this .onSizeChanged { viewSize = it @@ -109,6 +126,9 @@ private fun Modifier.zoomable(content: ImageBitmap): Modifier { .pointerInput(Unit) { detectDragPastThreshold { pan -> panBy(pan) } } + .pointerInput(Unit) { + detectCursorMove(onExit = { cursor = null }) { cursor = it } + } .pointerInput(Unit) { awaitPointerEventScope { while (true) { @@ -117,11 +137,7 @@ private fun Modifier.zoomable(content: ImageBitmap): Modifier { val change = event.changes.first() if (change.scrollDelta.y == 0f) continue val notches = wheelNotches(change.scrollDelta.y) - val zoomed = (scale * WHEEL_ZOOM_STEP.pow(-notches)).coerceIn(1f, 20f) - val pointer = change.position - Offset(size.width / 2f, size.height / 2f) - translation - val shift = pointer * (1 - zoomed / scale) - scale = zoomed - panBy(shift) + zoomAt(change.position, WHEEL_ZOOM_STEP.pow(-notches)) change.consume() } } @@ -160,3 +176,24 @@ private suspend fun PointerInputScope.detectDragPastThreshold(onDrag: (Offset) - private fun wheelNotches(scrollDelta: Float): Float = if (desktopPlatform.isMac()) scrollDelta / MAC_SCROLL_UNITS_PER_NOTCH else scrollDelta + +internal fun addPinchListener(component: JComponent) { + try { + val gestureListener = Class.forName("com.apple.eawt.event.GestureListener") + val magnificationListener = Class.forName("com.apple.eawt.event.MagnificationListener") + val magnification = Class.forName("com.apple.eawt.event.MagnificationEvent").getMethod("getMagnification") + val listener = Proxy.newProxyInstance(magnificationListener.classLoader, arrayOf(magnificationListener)) { proxy, method, args -> + when (method.name) { + "magnify" -> pinchZooms.tryEmit(1 + (magnification.invoke(args[0]) as Double).toFloat()) + "equals" -> proxy === args[0] + "hashCode" -> System.identityHashCode(proxy) + else -> magnificationListener.name + } + } + Class.forName("com.apple.eawt.event.GestureUtilities") + .getMethod("addGestureListenerTo", JComponent::class.java, gestureListener) + .invoke(null, component, listener) + } catch (e: ReflectiveOperationException) { + Log.w(TAG, "pinch zoom: gesture listener unavailable: ${e.message}") + } +} diff --git a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt index c43be77693..acb7ec5e5b 100644 --- a/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt +++ b/apps/multiplatform/common/src/desktopTest/kotlin/chat/simplex/app/ImageFullScreenZoomTest.kt @@ -23,6 +23,7 @@ import chat.simplex.common.simplexWindowState import chat.simplex.common.views.chat.ProviderMedia import chat.simplex.common.views.chat.item.ImageFullScreenView import chat.simplex.common.views.chat.item.ImageGalleryProvider +import chat.simplex.common.views.chat.item.pinchZooms import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.runBlocking import kotlinx.coroutines.swing.Swing @@ -31,6 +32,7 @@ import org.jetbrains.skia.Image import java.awt.image.BufferedImage import java.io.ByteArrayOutputStream import javax.imageio.ImageIO +import kotlin.math.pow import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertFalse @@ -130,6 +132,13 @@ class ImageFullScreenZoomTest { assertTrue(closed()) } + @Test + fun testPinchZoomsAtThePointerAsTheWheel() = fullScreen { _ -> + sendPointerEvent(PointerEventType.Move, Offset(200f, 300f)) + pinchZooms.tryEmit(1.2f.pow(3)) + assertEquals(listOf(Shown.RED, Shown.BLUE), listOf(shownAt(530), shownAt(560))) + } + @Test fun testDragKeepsALetterboxedImageInTheView() = fullScreen(gallery(quadrants(200, 400))) { closed -> wheel(400f, -8f) diff --git a/apps/multiplatform/desktop/build.gradle.kts b/apps/multiplatform/desktop/build.gradle.kts index 5b762190b6..3b358d2c84 100644 --- a/apps/multiplatform/desktop/build.gradle.kts +++ b/apps/multiplatform/desktop/build.gradle.kts @@ -40,6 +40,10 @@ compose { ) } mainClass = "chat.simplex.desktop.MainKt" + val os = System.getProperty("os.name", "generic").toDefaultLowerCase() + if (os.contains("mac")) { + jvmArgs += "--add-exports=java.desktop/com.apple.eawt.event=ALL-UNNAMED" + } nativeDistributions { copyright = "(c) 2020-2026 SimpleX Chat" // For debugging via VisualVM @@ -49,7 +53,6 @@ compose { // 'jdk.unsupported' is for vlcj modules("jdk.zipfs", "jdk.unsupported") } - val os = System.getProperty("os.name", "generic").toDefaultLowerCase() // 'jdk.accessibility' provides Java Access Bridge on Windows - without it the app // fails to start with "Failed to launch JVM" when assistive technologies are enabled // in the system (see #4146). Packages are always built on the target OS, so only diff --git a/plans/2026-11-16-desktop-pinch-zoom.md b/plans/2026-11-16-desktop-pinch-zoom.md new file mode 100644 index 0000000000..b41772ddda --- /dev/null +++ b/plans/2026-11-16-desktop-pinch-zoom.md @@ -0,0 +1,51 @@ +# Desktop: trackpad pinch zooms full-screen images and videos + +## Problem + +On desktop, a full-screen image or video is zoomed by the mouse wheel. On a macOS trackpad, a pinch leaves it as it is. + +## Change + +macOS: + +- On a macOS build, `--add-exports=java.desktop/com.apple.eawt.event=ALL-UNNAMED` is added to `jvmArgs` in `desktop/build.gradle.kts`. The option is passed to the launcher of the packaged app and to `run`. +- After the main window is composed, `addPinchListener` adds a `MagnificationListener` to the window's root pane with `GestureUtilities.addGestureListenerTo`, by reflection. The JDK calls the listener on the event dispatch thread for each pinch step over the window. +- For each step, the zoom factor `1 + magnification` is emitted to `pinchZooms`. +- `com.apple.eawt.event` is a JDK-internal package of the macOS JDK. When its classes or the export are missing, a warning is logged, and pinch zoom is off. +- The listener's proxy answers `equals` by identity, `hashCode` by `System.identityHashCode` and `toString` by the interface name. + +Full-screen view, `zoomable`: + +- `zoomable` is applied to the full-screen image and to the frames of the full-screen video, as on the base. +- The pointer position over the view is kept by `detectCursorMove` and cleared when the pointer leaves the view. +- Each factor from `pinchZooms` zooms the view at the pointer by `zoomAt`. A factor received without a pointer over the view is ignored. +- The wheel zooms by the same `zoomAt`, with the factor `1.2^-notches`. +- In `zoomAt`, the scale is limited to 1×–20×, and the translation is clamped by `boundTranslation`, as for the wheel on the base. + +Windows: a precision touchpad sends a pinch as Ctrl+wheel input, which is zoomed by the wheel handler, as on the base. Microsoft's [touchpad gesture implementation guide](https://learn.microsoft.com/en-us/previous-versions/windows/hardware/design/dn614021(v=vs.85)): "When processing a two-finger zoom, the touchpad device should: Issue Ctrl+vertical wheel input when the user performs the zoom gesture." + +Linux: AWT receives the wheel only as X11 buttons 4 and 5, so a touchpad pinch leaves the view as it is, as on the base. + +```mermaid +flowchart TD + subgraph JDK["macOS JDK"] + N["NSWindow magnifyWithEvent:"] --> G["GestureHandler, on the event dispatch thread"] + end + subgraph App["Main window, macOS"] + G --> P["MagnificationListener proxy on the root pane"] + P --> F["pinchZooms: 1 + magnification"] + end + subgraph Zoomable["zoomable(content)"] + M["detectCursorMove: cursor, null on exit"] --> C + F --> C{"cursor over the view?"} + C -- yes --> Z + C -- no --> I[Ignored] + W["Scroll: 1.2^-notches at the pointer"] --> Z + Z["zoomAt: scale × factor, 1..20, at the position"] --> B["boundTranslation"] + B --> L["Clip to the view, then layer: scale, translation"] + end +``` + +## Tests + +In `ImageFullScreenZoomTest` (desktopTest), the pointer is moved to x = 200, and the factor 1.2³ is emitted to `pinchZooms`. The boundary between the red and blue halves is then checked where the wheel test checks it after three notches at the same pointer. Before the change, the factor is not collected, and the image stays at 1×.