Important: unclear posts may not receive useful answers.
Before posting
- Get familiar with Markdown to format and structure your post
- Be sure to update lvgl from the latest version from the
master
branch.- Be sure you have checked the FAQ and read the relevant part of the documentation.
- If applicable use the Simulator to eliminate hardware related issues.
Delete this section if you read and applied the mentioned points.
Description
What MCU/Processor/Board and compiler are you using?
BES2700BP
What LVGL version are you using?
v8.3
What do you want to achieve?
When the page scrolls to the top or bottom, it will stop after continuing to scroll a certain distance to prevent the content from scrolling out of the screen.
What have you tried so far?
Analyze the implementation of the elastic_diff
and scroll_limit_diff
function.
Code to reproduce
#define LV_HOR_RES_MAX 466
#define LV_VER_RES_MAX 466
void CreateControlMenu(lv_obj_t *parent)
{
auto m_menu_container = lv_obj_create(parent);
lv_obj_remove_style_all(m_menu_container);
lv_obj_set_size(m_menu_container, LV_HOR_RES_MAX, LV_HOR_RES_MAX);
lv_obj_set_scroll_snap_y(m_menu_container, LV_SCROLL_SNAP_CENTER);
lv_obj_set_flex_flow(m_menu_container, LV_FLEX_FLOW_COLUMN);
lv_obj_align(m_menu_container, LV_ALIGN_TOP_MID, 0, 12);
lv_obj_set_style_bg_opa(m_menu_container, LV_OPA_0, LV_PART_MAIN);
lv_obj_set_style_rotary_sensitivity(m_menu_container, 64, 0);
lv_obj_set_scroll_dir(m_menu_container, LV_DIR_VER);
lv_obj_align(m_menu_container, LV_ALIGN_TOP_MID, 0, 0);
for (int8_t i = 0; i < 10; ++i)
{
lv_obj_t *obj;
lv_obj_t *label;
/*Add items to the column*/
obj = lv_obj_create(m_menu_container);
lv_obj_set_size(obj, LV_PCT(100), 100);
lv_obj_set_style_bg_opa(obj, 255, LV_PART_MAIN);
lv_obj_set_style_bg_color(obj, lv_color_hex(0x3FBFF5), LV_PART_MAIN);
label = lv_label_create(obj);
lv_label_set_text_fmt(label, "Item: %" LV_PRIu32, i);
lv_obj_set_style_bg_opa(label, 255, LV_PART_MAIN);
lv_obj_set_style_bg_color(label, lv_color_hex(0x3FF07F), LV_PART_MAIN);
lv_obj_center(label);
}
}
void CreateControlView(lv_obj_t *parent)
{
auto m_control_container = lv_obj_create(parent);
lv_obj_set_size(m_control_container, LV_HOR_RES_MAX, LV_VER_RES_MAX);
lv_obj_align(m_control_container, LV_ALIGN_TOP_MID, 0, 0);
lv_obj_set_style_bg_opa(m_control_container, 0, 0);
lv_obj_set_style_bg_opa(m_control_container, LV_OPA_0, LV_PART_SCROLLBAR | LV_STATE_DEFAULT);
lv_obj_set_style_bg_opa(m_control_container, LV_OPA_0, LV_PART_SCROLLBAR | LV_STATE_SCROLLED);
lv_obj_clear_flag(m_control_container, LV_OBJ_FLAG_SCROLL_MOMENTUM);
lv_obj_clear_flag(m_control_container, LV_OBJ_FLAG_SCROLL_ELASTIC);
CreateControlMenu(m_control_container);
lv_obj_scroll_to_y(m_control_container, 0, LV_ANIM_OFF);
}
Screenshot and/or video
scrolling up
Stop scrolling when reaching approximately one-third down the screen to prevent scrolling off the screen.