fix(core): fix scrollbar position overflows for huge content sizes (#9871)
Arduino Lint / lint (push) Has been cancelled
Build Examples with C++ Compiler / build-examples (push) Has been cancelled
MicroPython CI / Build esp32 port (push) Has been cancelled
MicroPython CI / Build rp2 port (push) Has been cancelled
MicroPython CI / Build stm32 port (push) Has been cancelled
MicroPython CI / Build unix port (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_NORMAL_8BIT - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_SDL - Ubuntu (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_16BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_24BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - cl - Windows (push) Has been cancelled
C/C++ CI / Build OPTIONS_FULL_32BIT - gcc - Windows (push) Has been cancelled
C/C++ CI / Build ESP IDF ESP32S3 (push) Has been cancelled
C/C++ CI / Run tests with 32bit build (push) Has been cancelled
C/C++ CI / Run tests with 64bit build (push) Has been cancelled
BOM Check / bom-check (push) Has been cancelled
Verify GDB constants are up-to-date / verify-gdb-consts (push) Has been cancelled
Verify the widget property name / verify-property-name (push) Has been cancelled
Verify code formatting / verify-formatting (push) Has been cancelled
Compare file templates with file names / template-check (push) Has been cancelled
Build Docs / build-and-deploy (push) Has been cancelled
Build .deb packages / build (push) Has been cancelled
Validate pkg-config and CMake config / cmake (linux) (push) Has been cancelled
Validate pkg-config and CMake config / pkgconfig (linux) (push) Has been cancelled
Validate pkg-config and CMake config / cmake (linux-3d) (push) Has been cancelled
Validate pkg-config and CMake config / pkgconfig (linux-3d) (push) Has been cancelled
Test API JSON generator / Test API JSON (push) Has been cancelled
Install LVGL using CMake / build-examples (private) (push) Has been cancelled
Install LVGL using CMake / build-examples (public) (push) Has been cancelled
Check Makefile / Build using Makefile (push) Has been cancelled
Check Makefile for UEFI / Build using Makefile for UEFI (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/benchmark_results_comment/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/filter_docker_logs/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Script Check (scripts/perf/tests/serialize_results/test.sh) (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 32b - lv_conf_perf32b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark 64b - lv_conf_perf64b (push) Has been cancelled
Emulated Performance Test / ARM Emulated Benchmark - Save PR Number (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_32B - Ubuntu (push) Has been cancelled
Performance Tests CI / Perf Tests OPTIONS_TEST_PERF_64B - Ubuntu (push) Has been cancelled
Port repo release update / run-release-branch-updater (push) Has been cancelled
Static Checks / Static Checks (push) Has been cancelled
Verify Font License / verify-font-license (push) Has been cancelled
Verify Kconfig / verify-kconfig (push) Has been cancelled
Verify that lv_conf_internal.h matches repository state / verify-conf-internal (push) Has been cancelled
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled

This commit is contained in:
Niklas Fiekas
2026-07-15 14:05:53 +02:00
committed by GitHub
parent 890cac0033
commit 4bce3b8c93
6 changed files with 62 additions and 4 deletions
+10 -4
View File
@@ -35,6 +35,7 @@
/**********************
* STATIC PROTOTYPES
**********************/
static inline int32_t mul_div(int32_t v, int32_t factor, int32_t divisor);
static void scroll_x_anim(void * obj, int32_t v);
static void scroll_y_anim(void * obj, int32_t v);
static void scroll_end_cb(lv_anim_t * a);
@@ -600,7 +601,7 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t *
ver_area->x1 = ver_area->x2 - thickness + 1;
}
int32_t sb_h = ((obj_h - top_space - bottom_space - hor_req_space) * obj_h) / content_h;
int32_t sb_h = mul_div(obj_h - top_space - bottom_space - hor_req_space, obj_h, content_h);
sb_h = LV_MAX(length > 0 ? length : sb_h, SCROLLBAR_MIN_SIZE); /*Style-defined size, calculated size, or minimum size*/
sb_h = LV_MIN(sb_h, obj_h); /*Limit scrollbar length to parent height*/
rem = (obj_h - top_space - bottom_space - hor_req_space) -
@@ -611,7 +612,7 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t *
ver_area->y2 = obj->coords.y2 - bottom_space - hor_req_space - 1;
}
else {
int32_t sb_y = (rem * sb) / scroll_h;
int32_t sb_y = mul_div(rem, sb, scroll_h);
sb_y = rem - sb_y;
ver_area->y1 = obj->coords.y1 + sb_y + top_space;
@@ -639,7 +640,7 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t *
hor_area->x1 = obj->coords.x1;
hor_area->x2 = obj->coords.x2;
int32_t sb_w = ((obj_w - left_space - right_space - ver_reg_space) * obj_w) / content_w;
int32_t sb_w = mul_div(obj_w - left_space - right_space - ver_reg_space, obj_w, content_w);
sb_w = LV_MAX(length > 0 ? length : sb_w, SCROLLBAR_MIN_SIZE); /*Style-defined size, calculated size, or minimum size*/
sb_w = LV_MIN(sb_w, obj_w); /*Limit scrollbar length to parent width*/
rem = (obj_w - left_space - right_space - ver_reg_space) -
@@ -656,7 +657,7 @@ void lv_obj_get_scrollbar_area(lv_obj_t * obj, lv_area_t * hor_area, lv_area_t *
}
}
else {
int32_t sb_x = (rem * sr) / scroll_w;
int32_t sb_x = mul_div(rem, sr, scroll_w);
sb_x = rem - sb_x;
if(rtl) {
@@ -748,6 +749,11 @@ void lv_obj_readjust_scroll(lv_obj_t * obj, lv_anim_enable_t anim_en)
* STATIC FUNCTIONS
**********************/
static inline int32_t mul_div(int32_t v, int32_t factor, int32_t divisor)
{
return ((int64_t)v * factor) / divisor;
}
static void scroll_x_anim(void * obj, int32_t v)
{
lv_obj_scroll_by_raw(obj, v + lv_obj_get_scroll_x(obj), 0);
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

+52
View File
@@ -0,0 +1,52 @@
#if LV_BUILD_TEST
#include "../lvgl.h"
#include "../../lvgl_private.h"
#include "unity/unity.h"
void setUp(void)
{
/* Function run before every test */
}
void tearDown(void)
{
/* Function run after every test */
lv_obj_clean(lv_screen_active());
}
void test_scrollbar_vertical(void)
{
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_ROW);
const int32_t inner_sizes[] = {100, 500, 1000, 5000, 100000, 500000, 1000000, 4000000};
for(size_t i = 0; i < sizeof(inner_sizes) / sizeof(inner_sizes[0]); i++) {
lv_obj_t * wrapper = lv_obj_create(lv_screen_active());
lv_obj_set_flex_grow(wrapper, 1);
lv_obj_set_height(wrapper, LV_PCT(100));
lv_obj_t * inner = lv_obj_create(wrapper);
lv_obj_set_size(inner, LV_PCT(100), inner_sizes[i]);
}
TEST_ASSERT_EQUAL_SCREENSHOT("scrollbar_vertical.png");
}
void test_scrollbar_horizontal(void)
{
lv_obj_set_flex_flow(lv_screen_active(), LV_FLEX_FLOW_COLUMN);
const int32_t inner_sizes[] = {100, 500, 1000, 5000, 100000, 500000, 1000000, 4000000};
for(size_t i = 0; i < sizeof(inner_sizes) / sizeof(inner_sizes[0]); i++) {
lv_obj_t * wrapper = lv_obj_create(lv_screen_active());
lv_obj_set_flex_grow(wrapper, 1);
lv_obj_set_width(wrapper, LV_PCT(100));
lv_obj_t * inner = lv_obj_create(wrapper);
lv_obj_set_size(inner, inner_sizes[i], LV_PCT(100));
}
TEST_ASSERT_EQUAL_SCREENSHOT("scrollbar_horizontal.png");
}
#endif