mirror of
https://github.com/lvgl/lvgl.git
synced 2025-01-28 07:03:00 +08:00
fix(scroll) fix scroll_area_into_view with objects larger than the parent
This commit is contained in:
parent
d089b364e7
commit
5240fdda5c
@ -21,7 +21,7 @@ static void radio_event_handler(lv_event_t * e)
|
||||
|
||||
*active_id = lv_obj_get_index(act_cb);
|
||||
|
||||
LV_LOG_USER("Selected radio buttons: %d, %d\n", active_index_1, active_index_2);
|
||||
LV_LOG_USER("Selected radio buttons: %d, %d", active_index_1, active_index_2);
|
||||
}
|
||||
|
||||
|
||||
@ -42,7 +42,7 @@ void lv_example_checkbox_2(void)
|
||||
/* The idea is to enable `LV_OBJ_FLAG_EVENT_BUBBLE` on checkboxes and process the
|
||||
* `LV_EVENT_CLICKED` on the container.
|
||||
* A variable is passed as event user data where the index of the active
|
||||
* redio butto nis saved */
|
||||
* radiobutton is saved */
|
||||
|
||||
|
||||
lv_style_init(&style_radio);
|
||||
@ -59,7 +59,7 @@ void lv_example_checkbox_2(void)
|
||||
lv_obj_set_size(cont1, lv_pct(40), lv_pct(80));
|
||||
lv_obj_add_event_cb(cont1, radio_event_handler, LV_EVENT_CLICKED, &active_index_1);
|
||||
|
||||
for (i = 0;i < 5;i++) {
|
||||
for (i = 0;i < 1;i++) {
|
||||
lv_snprintf(buf, sizeof(buf), "A %d", i + 1);
|
||||
radiobutton_create(cont1, buf);
|
||||
|
||||
|
@ -656,12 +656,13 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p
|
||||
if(snap_y != LV_SCROLL_SNAP_NONE) area_tmp = &child->coords;
|
||||
else area_tmp = area;
|
||||
|
||||
lv_coord_t ptop = lv_obj_get_style_pad_top(parent, LV_PART_MAIN);
|
||||
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(parent, LV_PART_MAIN);
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(parent, LV_PART_MAIN);
|
||||
lv_coord_t ptop = lv_obj_get_style_pad_top(parent, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t pbottom = lv_obj_get_style_pad_bottom(parent, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t top_diff = parent->coords.y1 + ptop - area_tmp->y1 - scroll_value->y;
|
||||
lv_coord_t bottom_diff = -(parent->coords.y2 - pbottom - area_tmp->y2 - scroll_value->y);
|
||||
lv_coord_t parent_h = lv_obj_get_height(parent) - ptop - pbottom;
|
||||
if((top_diff > 0 && bottom_diff > 0)) y_scroll = 0;
|
||||
if((top_diff >= 0 && bottom_diff >= 0)) y_scroll = 0;
|
||||
else if(top_diff > 0) {
|
||||
y_scroll = top_diff;
|
||||
/*Do not let scrolling in*/
|
||||
@ -698,11 +699,11 @@ static void scroll_area_into_view(const lv_area_t * area, lv_obj_t * child, lv_p
|
||||
if(snap_x != LV_SCROLL_SNAP_NONE) area_tmp = &child->coords;
|
||||
else area_tmp = area;
|
||||
|
||||
lv_coord_t pleft = lv_obj_get_style_pad_left(parent, LV_PART_MAIN);
|
||||
lv_coord_t pright = lv_obj_get_style_pad_right(parent, LV_PART_MAIN);
|
||||
lv_coord_t pleft = lv_obj_get_style_pad_left(parent, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t pright = lv_obj_get_style_pad_right(parent, LV_PART_MAIN) + border_width;
|
||||
lv_coord_t left_diff = parent->coords.x1 + pleft - area_tmp->x1 - scroll_value->x;
|
||||
lv_coord_t right_diff = -(parent->coords.x2 - pright - area_tmp->x2 - scroll_value->x);
|
||||
if((left_diff > 0 && right_diff > 0)) x_scroll = 0;
|
||||
if((left_diff >= 0 && right_diff >= 0)) x_scroll = 0;
|
||||
else if(left_diff > 0) {
|
||||
x_scroll = left_diff;
|
||||
/*Do not let scrolling in*/
|
||||
|
@ -226,11 +226,11 @@ static void flex_update(lv_obj_t * cont, void * user_data)
|
||||
lv_coord_t item_gap = f.row ? lv_obj_get_style_pad_column(cont, LV_PART_MAIN) : lv_obj_get_style_pad_row(cont,
|
||||
LV_PART_MAIN);
|
||||
lv_coord_t max_main_size = (f.row ? lv_obj_get_content_width(cont) : lv_obj_get_content_height(cont));
|
||||
lv_coord_t border_widt = lv_obj_get_style_border_width(cont, LV_PART_MAIN);
|
||||
lv_coord_t border_width = lv_obj_get_style_border_width(cont, LV_PART_MAIN);
|
||||
lv_coord_t abs_y = cont->coords.y1 + lv_obj_get_style_pad_top(cont,
|
||||
LV_PART_MAIN) + border_widt - lv_obj_get_scroll_y(cont);
|
||||
LV_PART_MAIN) + border_width - lv_obj_get_scroll_y(cont);
|
||||
lv_coord_t abs_x = cont->coords.x1 + lv_obj_get_style_pad_left(cont,
|
||||
LV_PART_MAIN) + border_widt - lv_obj_get_scroll_x(cont);
|
||||
LV_PART_MAIN) + border_width - lv_obj_get_scroll_x(cont);
|
||||
|
||||
lv_flex_align_t track_cross_place = f.track_place;
|
||||
lv_coord_t * cross_pos = (f.row ? &abs_y : &abs_x);
|
||||
|
Loading…
x
Reference in New Issue
Block a user