Files
lvgl/examples/scroll/lv_example_scroll_3.c
T
Mutahhar Mustafa Khan d76a346376 docs(examples): introduce summary and description to examples (#9968)
Co-authored-by: Gabor Kiss-Vamosi <kisvegabor@gmail.com>
2026-04-20 14:05:57 +02:00

59 lines
2.1 KiB
C

#include "../lv_examples.h"
#if LV_BUILD_EXAMPLES && LV_USE_LIST
static uint32_t btn_cnt = 1;
static void float_button_event_cb(lv_event_t * e)
{
lv_event_code_t code = lv_event_get_code(e);
lv_obj_t * float_btn = lv_event_get_target_obj(e);
if(code == LV_EVENT_CLICKED) {
lv_obj_t * list = (lv_obj_t *) lv_event_get_user_data(e);
char buf[32];
lv_snprintf(buf, sizeof(buf), "Track %d", (int)btn_cnt);
lv_obj_t * list_btn = lv_list_add_button(list, LV_SYMBOL_AUDIO, buf);
btn_cnt++;
/* Move the button to the foreground*/
lv_obj_move_to_index(float_btn, -1);
lv_obj_scroll_to_view(list_btn, LV_ANIM_ON);
}
}
/**
* @title Floating add button over list
* @brief Keep a circular plus button pinned to a scrollable list while it adds track entries.
*
* A 280x220 `lv_list` is seeded with two `LV_SYMBOL_AUDIO` track entries. A
* child button given `LV_OBJ_FLAG_FLOATING` and `LV_RADIUS_CIRCLE` is aligned
* to `LV_ALIGN_BOTTOM_RIGHT` so it stays over the list while it scrolls.
* Clicking the floating button appends a new "Track N" entry, moves itself
* back to the foreground with `lv_obj_move_to_index`, and calls
* `lv_obj_scroll_to_view` with `LV_ANIM_ON` to reveal the new row.
*/
void lv_example_scroll_3(void)
{
lv_obj_t * list = lv_list_create(lv_screen_active());
lv_obj_set_size(list, 280, 220);
lv_obj_center(list);
for(btn_cnt = 1; btn_cnt <= 2; btn_cnt++) {
char buf[32];
lv_snprintf(buf, sizeof(buf), "Track %d", (int)btn_cnt);
lv_list_add_button(list, LV_SYMBOL_AUDIO, buf);
}
lv_obj_t * float_btn = lv_button_create(list);
lv_obj_set_size(float_btn, 50, 50);
lv_obj_add_flag(float_btn, LV_OBJ_FLAG_FLOATING);
lv_obj_align(float_btn, LV_ALIGN_BOTTOM_RIGHT, 0, -lv_obj_get_style_pad_right(list, LV_PART_MAIN));
lv_obj_add_event_cb(float_btn, float_button_event_cb, LV_EVENT_ALL, list);
lv_obj_set_style_radius(float_btn, LV_RADIUS_CIRCLE, 0);
lv_obj_set_style_bg_image_src(float_btn, LV_SYMBOL_PLUS, 0);
lv_obj_set_style_text_font(float_btn, lv_theme_get_font_large(float_btn), 0);
}
#endif