Skip to content

Commit 56baeb4

Browse files
author
Ting Zhu
authored
Improved the calculation of the maximum scrolling value for vertical and horizontal list widgets. (#93)
1 parent 8b84f44 commit 56baeb4

11 files changed

Lines changed: 1034 additions & 117 deletions

common/src/gx_horizontal_list_scroll_info_get.c

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/* FUNCTION RELEASE */
3636
/* */
3737
/* _gx_horizontal_list_scroll_info_get PORTABLE C */
38-
/* 6.1 */
38+
/* 6.x */
3939
/* AUTHOR */
4040
/* */
4141
/* Kenneth Maxwell, Microsoft Corporation */
@@ -69,18 +69,39 @@
6969
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
7070
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */
7171
/* resulting in version 6.1 */
72+
/* xx-xx-xxxx Ting Zhu Modified comments(s), */
73+
/* improved the calculation of */
74+
/* the maximum scrolling value.*/
75+
/* resulting in version 6.x */
7276
/* */
7377
/**************************************************************************/
7478
VOID _gx_horizontal_list_scroll_info_get(GX_WINDOW *win, ULONG style, GX_SCROLL_INFO *info)
7579
{
7680
INT value;
77-
GX_WIDGET *topchild;
78-
81+
GX_WIDGET *child;
7982
GX_HORIZONTAL_LIST *list = (GX_HORIZONTAL_LIST *)win;
83+
GX_VALUE width;
84+
8085

8186
GX_PARAMETER_NOT_USED(style);
8287

83-
info -> gx_scroll_maximum = (list -> gx_horizontal_list_total_columns * list -> gx_horizontal_list_child_width - 1);
88+
if (list -> gx_horizontal_list_callback)
89+
{
90+
/* If list callback is set, children winthin the list should share the same width. */
91+
info -> gx_scroll_maximum = (list -> gx_horizontal_list_total_columns * list -> gx_horizontal_list_child_width - 1);
92+
}
93+
else
94+
{
95+
info -> gx_scroll_maximum = 0;
96+
97+
child = _gx_widget_first_client_child_get((GX_WIDGET*)list);
98+
while (child)
99+
{
100+
_gx_widget_width_get(child, &width);
101+
info -> gx_scroll_maximum += width;
102+
child = _gx_widget_next_client_child_get(child);
103+
}
104+
}
84105
info -> gx_scroll_minimum = 0;
85106
info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_right - list -> gx_window_client.gx_rectangle_left + 1);
86107

@@ -96,11 +117,11 @@ GX_HORIZONTAL_LIST *list = (GX_HORIZONTAL_LIST *)win;
96117

97118
if (list -> gx_horizontal_list_top_index >= 0)
98119
{
99-
topchild = _gx_widget_first_client_child_get((GX_WIDGET *)win);
120+
child = _gx_widget_first_client_child_get((GX_WIDGET *)win);
100121

101-
if (topchild)
122+
if (child)
102123
{
103-
value += win -> gx_window_client.gx_rectangle_left - topchild -> gx_widget_size.gx_rectangle_left;
124+
value += win -> gx_window_client.gx_rectangle_left - child -> gx_widget_size.gx_rectangle_left;
104125
}
105126
}
106127

common/src/gx_vertical_list_scroll_info_get.c

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
/* FUNCTION RELEASE */
3636
/* */
3737
/* _gx_vertical_list_scroll_info_get PORTABLE C */
38-
/* 6.1 */
38+
/* 6.x */
3939
/* AUTHOR */
4040
/* */
4141
/* Kenneth Maxwell, Microsoft Corporation */
@@ -69,18 +69,40 @@
6969
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
7070
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */
7171
/* resulting in version 6.1 */
72+
/* xx-xx-xxxx Ting Zhu Modified comments(s), */
73+
/* improved the calculation of */
74+
/* the maximum scrolling value.*/
75+
/* resulting in version 6.x */
7276
/* */
7377
/**************************************************************************/
7478
VOID _gx_vertical_list_scroll_info_get(GX_VERTICAL_LIST *list, ULONG style, GX_SCROLL_INFO *info)
7579
{
7680
INT value;
77-
GX_WIDGET *topchild;
78-
79-
GX_WINDOW *win = (GX_WINDOW *)list;
81+
GX_VALUE height;
82+
GX_WIDGET *child;
8083

8184
GX_PARAMETER_NOT_USED(style);
8285

83-
info -> gx_scroll_maximum = (list -> gx_vertical_list_total_rows * list -> gx_vertical_list_child_height - 1);
86+
if (list -> gx_vertical_list_callback)
87+
{
88+
/* If list callback is set, children winthin the list should share the same height. */
89+
info -> gx_scroll_maximum = (list->gx_vertical_list_total_rows * list -> gx_vertical_list_child_height - 1);
90+
}
91+
else
92+
{
93+
info -> gx_scroll_maximum = 0;
94+
95+
child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
96+
97+
while (child)
98+
{
99+
_gx_widget_height_get(child, &height);
100+
101+
info -> gx_scroll_maximum += height;
102+
103+
child = _gx_widget_next_client_child_get(child);
104+
}
105+
}
84106
info -> gx_scroll_minimum = 0;
85107
info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_bottom - list -> gx_window_client.gx_rectangle_top + 1);
86108

@@ -96,11 +118,11 @@ GX_WINDOW *win = (GX_WINDOW *)list;
96118

97119
if (list -> gx_vertical_list_top_index >= 0)
98120
{
99-
topchild = _gx_widget_first_client_child_get((GX_WIDGET *)win);
121+
child = _gx_widget_first_client_child_get((GX_WIDGET *)list);
100122

101-
if (topchild)
123+
if (child)
102124
{
103-
value += win -> gx_window_client.gx_rectangle_top - topchild -> gx_widget_size.gx_rectangle_top;
125+
value += list -> gx_window_client.gx_rectangle_top - child -> gx_widget_size.gx_rectangle_top;
104126
}
105127
}
106128

test/example_internal/vertical_list_32bpp/demo_guix_vertical_list_32bpp.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,8 @@ VOID demo_thread_entry(ULONG thread_input)
6161
LANGUAGE_ENGLISH, DISPLAY_1_THEME_1, &root);
6262

6363
/* create the button screen */
64-
gx_studio_named_widget_create("window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainScreen);
64+
gx_studio_named_widget_create("window", (GX_WIDGET*)root, (GX_WIDGET **) &pMainScreen);
65+
gx_studio_named_widget_create("list_child_height_test_screen", GX_NULL, GX_NULL);
6566

6667
/* Create list children. */
6768
vertical_list_children_create(pMainScreen);

0 commit comments

Comments
 (0)