mirror of
https://github.com/lvgl/lvgl.git
synced 2026-08-20 22:45:14 +08:00
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 that lv_conf_internal.h matches repository state / verify-conf-internal (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
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
Hardware Performance Test / Hardware Performance Benchmark (push) Has been cancelled
Hardware Performance Test / HW Benchmark - Save PR Number (push) Has been cancelled
Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
106 lines
3.5 KiB
C
106 lines
3.5 KiB
C
#include "../lv_examples.h"
|
|
#if LV_BUILD_EXAMPLES && LV_USE_FLEX
|
|
|
|
static lv_obj_t * high_label;
|
|
static lv_obj_t * low_label;
|
|
static int32_t top_num;
|
|
static int32_t bottom_num;
|
|
static bool update_running = false;
|
|
|
|
static lv_obj_t * load_item(lv_obj_t * parent, int32_t num)
|
|
{
|
|
lv_obj_t * obj = lv_obj_create(parent);
|
|
lv_obj_set_size(obj, LV_PCT(100), LV_SIZE_CONTENT);
|
|
lv_obj_t * label = lv_label_create(obj);
|
|
lv_label_set_text_fmt(label, "%" LV_PRId32, num);
|
|
return obj;
|
|
}
|
|
|
|
static void update_scroll(lv_obj_t * obj)
|
|
{
|
|
/* Re-entrancy guard: lv_obj_scroll_by below re-triggers LV_EVENT_SCROLL. */
|
|
if(update_running) return;
|
|
update_running = true;
|
|
|
|
int32_t top_before = top_num;
|
|
int32_t bottom_before_num = bottom_num;
|
|
|
|
/* Append items as the bottom edge gets close. */
|
|
while(bottom_num > -30 && lv_obj_get_scroll_bottom(obj) < 200) {
|
|
bottom_num -= 1;
|
|
load_item(obj, bottom_num);
|
|
lv_obj_update_layout(obj);
|
|
}
|
|
/* Prepend items as the top edge gets close, compensating the scroll. */
|
|
while(top_num < 30 && lv_obj_get_scroll_top(obj) < 200) {
|
|
top_num += 1;
|
|
int32_t bottom_before = lv_obj_get_scroll_bottom(obj);
|
|
lv_obj_t * item = load_item(obj, top_num);
|
|
lv_obj_move_to_index(item, 0);
|
|
lv_obj_update_layout(obj);
|
|
lv_obj_scroll_by(obj, 0, bottom_before - lv_obj_get_scroll_bottom(obj), LV_ANIM_OFF);
|
|
}
|
|
|
|
/* Drop items that scrolled far out of view. */
|
|
while(lv_obj_get_scroll_bottom(obj) > 600) {
|
|
bottom_num += 1;
|
|
lv_obj_delete(lv_obj_get_child(obj, -1));
|
|
lv_obj_update_layout(obj);
|
|
}
|
|
while(lv_obj_get_scroll_top(obj) > 600) {
|
|
top_num -= 1;
|
|
int32_t bottom_before = lv_obj_get_scroll_bottom(obj);
|
|
lv_obj_delete(lv_obj_get_child(obj, 0));
|
|
lv_obj_update_layout(obj);
|
|
lv_obj_scroll_by(obj, 0, bottom_before - lv_obj_get_scroll_bottom(obj), LV_ANIM_OFF);
|
|
}
|
|
|
|
if(top_num != top_before) lv_label_set_text_fmt(high_label, "largest:\n%" LV_PRId32, top_num);
|
|
if(bottom_num != bottom_before_num) lv_label_set_text_fmt(low_label, "smallest:\n%" LV_PRId32, bottom_num);
|
|
|
|
update_running = false;
|
|
}
|
|
|
|
static void scroll_cb(lv_event_t * e)
|
|
{
|
|
update_scroll(lv_event_get_target_obj(e));
|
|
}
|
|
|
|
/**
|
|
* @title Infinite (virtualized) scrolling
|
|
* @brief Create rows on demand and delete far-off ones while a column scrolls.
|
|
*
|
|
* A column tracks the highest and lowest loaded numbers. The
|
|
* `LV_EVENT_SCROLL` callback appends or prepends rows while either edge
|
|
* is within 200 px of content end, and deletes rows once they are more
|
|
* than 600 px away, compensating each change with `lv_obj_scroll_by` so
|
|
* the view stays steady. This keeps the element count bounded no matter
|
|
* how far the user scrolls.
|
|
*/
|
|
void lv_example_scroll_infinite(void)
|
|
{
|
|
lv_obj_t * scr = lv_screen_active();
|
|
|
|
high_label = lv_label_create(scr);
|
|
lv_label_set_text(high_label, "largest:");
|
|
lv_obj_align(high_label, LV_ALIGN_TOP_LEFT, 10, 10);
|
|
|
|
low_label = lv_label_create(scr);
|
|
lv_label_set_text(low_label, "smallest:");
|
|
lv_obj_align(low_label, LV_ALIGN_BOTTOM_LEFT, 10, -10);
|
|
|
|
lv_obj_t * obj = lv_obj_create(scr);
|
|
lv_obj_set_size(obj, 160, 220);
|
|
lv_obj_align(obj, LV_ALIGN_RIGHT_MID, -10, 0);
|
|
lv_obj_set_flex_flow(obj, LV_FLEX_FLOW_COLUMN);
|
|
|
|
load_item(obj, 3);
|
|
top_num = 3;
|
|
bottom_num = 3;
|
|
|
|
lv_obj_update_layout(obj);
|
|
update_scroll(obj);
|
|
lv_obj_add_event_cb(obj, scroll_cb, LV_EVENT_SCROLL, NULL);
|
|
}
|
|
|
|
#endif |