fix: ensure correct focusing index after image loading
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* @Author: Uyanide pywang0608@foxmail.com
|
* @Author: Uyanide pywang0608@foxmail.com
|
||||||
* @Date: 2025-08-05 01:22:53
|
* @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.
|
* @Description: Animated carousel widget for displaying and selecting images.
|
||||||
*/
|
*/
|
||||||
#include "images_carousel.h"
|
#include "images_carousel.h"
|
||||||
@@ -238,20 +238,26 @@ void ImagesCarousel::_processImageInsertQueue() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (m_noLoadingScreen) _enableUIUpdates(false);
|
if (m_noLoadingScreen) _enableUIUpdates(false);
|
||||||
int currPos = m_currentIndex;
|
int currPos = m_currentIndex;
|
||||||
|
bool anyLoaded = false;
|
||||||
for (ImageData* data : batch) {
|
for (ImageData* data : batch) {
|
||||||
int pos = _insertImage(data);
|
int pos = _insertImage(data);
|
||||||
// Keep the focusing index correct
|
// Keep the focusing index correct
|
||||||
if (pos >= 0 && pos <= currPos) {
|
if (pos >= 0 && pos <= currPos) {
|
||||||
currPos++;
|
currPos++;
|
||||||
|
} else if (pos >= 0) {
|
||||||
|
anyLoaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Update focusing index if any
|
|
||||||
if (m_currentIndex >= 0) {
|
if (m_currentIndex >= 0) {
|
||||||
|
// Update focusing index if any
|
||||||
m_currentIndex = currPos;
|
m_currentIndex = currPos;
|
||||||
if (m_currentIndex < 0 || m_currentIndex >= getLoadedImagesCount()) {
|
if (m_currentIndex < 0 || m_currentIndex >= getLoadedImagesCount()) {
|
||||||
m_currentIndex = 0;
|
m_currentIndex = 0;
|
||||||
}
|
}
|
||||||
|
} else if (anyLoaded) {
|
||||||
|
// Focus the first image if none focused before
|
||||||
|
m_currentIndex = 0;
|
||||||
}
|
}
|
||||||
if (m_noLoadingScreen) _enableUIUpdates(true);
|
if (m_noLoadingScreen) _enableUIUpdates(true);
|
||||||
focusCurrImage();
|
focusCurrImage();
|
||||||
|
|||||||
Reference in New Issue
Block a user