Skip to content

Commit

Permalink
Improved the calculation of the maximum scrolling value for vertical …
Browse files Browse the repository at this point in the history
…and horizontal list widgets. (#93)
  • Loading branch information
ting-ms authored Dec 19, 2023
1 parent 8b84f44 commit 56baeb4
Show file tree
Hide file tree
Showing 11 changed files with 1,034 additions and 117 deletions.
35 changes: 28 additions & 7 deletions common/src/gx_horizontal_list_scroll_info_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* FUNCTION RELEASE */
/* */
/* _gx_horizontal_list_scroll_info_get PORTABLE C */
/* 6.1 */
/* 6.x */
/* AUTHOR */
/* */
/* Kenneth Maxwell, Microsoft Corporation */
Expand Down Expand Up @@ -69,18 +69,39 @@
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */
/* resulting in version 6.1 */
/* xx-xx-xxxx Ting Zhu Modified comments(s), */
/* improved the calculation of */
/* the maximum scrolling value.*/
/* resulting in version 6.x */
/* */
/**************************************************************************/
VOID _gx_horizontal_list_scroll_info_get(GX_WINDOW *win, ULONG style, GX_SCROLL_INFO *info)
{
INT value;
GX_WIDGET *topchild;

GX_WIDGET *child;
GX_HORIZONTAL_LIST *list = (GX_HORIZONTAL_LIST *)win;
GX_VALUE width;


GX_PARAMETER_NOT_USED(style);

info -> gx_scroll_maximum = (list -> gx_horizontal_list_total_columns * list -> gx_horizontal_list_child_width - 1);
if (list -> gx_horizontal_list_callback)
{
/* If list callback is set, children winthin the list should share the same width. */
info -> gx_scroll_maximum = (list -> gx_horizontal_list_total_columns * list -> gx_horizontal_list_child_width - 1);
}
else
{
info -> gx_scroll_maximum = 0;

child = _gx_widget_first_client_child_get((GX_WIDGET*)list);
while (child)
{
_gx_widget_width_get(child, &width);
info -> gx_scroll_maximum += width;
child = _gx_widget_next_client_child_get(child);
}
}
info -> gx_scroll_minimum = 0;
info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_right - list -> gx_window_client.gx_rectangle_left + 1);

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

if (list -> gx_horizontal_list_top_index >= 0)
{
topchild = _gx_widget_first_client_child_get((GX_WIDGET *)win);
child = _gx_widget_first_client_child_get((GX_WIDGET *)win);

if (topchild)
if (child)
{
value += win -> gx_window_client.gx_rectangle_left - topchild -> gx_widget_size.gx_rectangle_left;
value += win -> gx_window_client.gx_rectangle_left - child -> gx_widget_size.gx_rectangle_left;
}
}

Expand Down
38 changes: 30 additions & 8 deletions common/src/gx_vertical_list_scroll_info_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
/* FUNCTION RELEASE */
/* */
/* _gx_vertical_list_scroll_info_get PORTABLE C */
/* 6.1 */
/* 6.x */
/* AUTHOR */
/* */
/* Kenneth Maxwell, Microsoft Corporation */
Expand Down Expand Up @@ -69,18 +69,40 @@
/* 05-19-2020 Kenneth Maxwell Initial Version 6.0 */
/* 09-30-2020 Kenneth Maxwell Modified comment(s), */
/* resulting in version 6.1 */
/* xx-xx-xxxx Ting Zhu Modified comments(s), */
/* improved the calculation of */
/* the maximum scrolling value.*/
/* resulting in version 6.x */
/* */
/**************************************************************************/
VOID _gx_vertical_list_scroll_info_get(GX_VERTICAL_LIST *list, ULONG style, GX_SCROLL_INFO *info)
{
INT value;
GX_WIDGET *topchild;

GX_WINDOW *win = (GX_WINDOW *)list;
GX_VALUE height;
GX_WIDGET *child;

GX_PARAMETER_NOT_USED(style);

info -> gx_scroll_maximum = (list -> gx_vertical_list_total_rows * list -> gx_vertical_list_child_height - 1);
if (list -> gx_vertical_list_callback)
{
/* If list callback is set, children winthin the list should share the same height. */
info -> gx_scroll_maximum = (list->gx_vertical_list_total_rows * list -> gx_vertical_list_child_height - 1);
}
else
{
info -> gx_scroll_maximum = 0;

child = _gx_widget_first_client_child_get((GX_WIDGET *)list);

while (child)
{
_gx_widget_height_get(child, &height);

info -> gx_scroll_maximum += height;

child = _gx_widget_next_client_child_get(child);
}
}
info -> gx_scroll_minimum = 0;
info -> gx_scroll_visible = (GX_VALUE)(list -> gx_window_client.gx_rectangle_bottom - list -> gx_window_client.gx_rectangle_top + 1);

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

if (list -> gx_vertical_list_top_index >= 0)
{
topchild = _gx_widget_first_client_child_get((GX_WIDGET *)win);
child = _gx_widget_first_client_child_get((GX_WIDGET *)list);

if (topchild)
if (child)
{
value += win -> gx_window_client.gx_rectangle_top - topchild -> gx_widget_size.gx_rectangle_top;
value += list -> gx_window_client.gx_rectangle_top - child -> gx_widget_size.gx_rectangle_top;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ VOID demo_thread_entry(ULONG thread_input)
LANGUAGE_ENGLISH, DISPLAY_1_THEME_1, &root);

/* create the button screen */
gx_studio_named_widget_create("window", (GX_WIDGET *) root, (GX_WIDGET **) &pMainScreen);
gx_studio_named_widget_create("window", (GX_WIDGET*)root, (GX_WIDGET **) &pMainScreen);
gx_studio_named_widget_create("list_child_height_test_screen", GX_NULL, GX_NULL);

/* Create list children. */
vertical_list_children_create(pMainScreen);
Expand Down
Loading

0 comments on commit 56baeb4

Please sign in to comment.