From 839b4d891f98273384889abf47da3557cf6178b9 Mon Sep 17 00:00:00 2001 From: Uyanide Date: Thu, 15 Jan 2026 07:33:44 +0100 Subject: [PATCH] fix: ensure correct focusing index after image loading --- src/images_carousel.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/images_carousel.cpp b/src/images_carousel.cpp index 51bc3f9..5183327 100644 --- a/src/images_carousel.cpp +++ b/src/images_carousel.cpp @@ -1,7 +1,7 @@ /* * @Author: Uyanide pywang0608@foxmail.com * @Date: 2025-08-05 01:22:53 - * @LastEditTime: 2026-01-15 07:24:52 + * @LastEditTime: 2026-01-15 07:33:22 * @Description: Animated carousel widget for displaying and selecting images. */ #include "images_carousel.h" @@ -238,20 +238,26 @@ void ImagesCarousel::_processImageInsertQueue() { } } if (m_noLoadingScreen) _enableUIUpdates(false); - int currPos = m_currentIndex; + int currPos = m_currentIndex; + bool anyLoaded = false; for (ImageData* data : batch) { int pos = _insertImage(data); // Keep the focusing index correct if (pos >= 0 && pos <= currPos) { currPos++; + } else if (pos >= 0) { + anyLoaded = true; } } - // Update focusing index if any if (m_currentIndex >= 0) { + // Update focusing index if any m_currentIndex = currPos; if (m_currentIndex < 0 || m_currentIndex >= getLoadedImagesCount()) { m_currentIndex = 0; } + } else if (anyLoaded) { + // Focus the first image if none focused before + m_currentIndex = 0; } if (m_noLoadingScreen) _enableUIUpdates(true); focusCurrImage();