fix: ensure correct focusing index after image loading

This commit is contained in:
2026-01-15 07:33:44 +01:00
parent 0c218a1e3c
commit 839b4d891f
+8 -2
View File
@@ -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"
@@ -239,19 +239,25 @@ void ImagesCarousel::_processImageInsertQueue() {
}
if (m_noLoadingScreen) _enableUIUpdates(false);
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();