Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue 1199 sitrep list lacks scroll bar for last item. #1356

Conversation

LGM-Doyle
Copy link
Contributor

This PR fixes issue #1199.

The problem was that the sitrep rows change their height in their prerender after the decision to add/remove the vertical scroll bar is made, because it changes the size of the client area.

In general this problem could be unstable. Every change to the scroll bars changes the client area, which changes the row sizes which changes the scroll bar requirements, closing the feedback loop.

The solution, I've employed is to try twice and then force the scroll bar to be added.

This fixes the following problem.

1. Some list rows can change size when prerendered.
2. Adding/removing scrolls can change the size of the list box client
area.

This can result in an unstable situation where the scrolls are added or
removed and the row size changes in a way that requires the opposite
change in the scrolls.

This commit basically tries twice and then forces the scrolls to be
added.
@LGM-Doyle LGM-Doyle added category:bug The Issue/PR describes or solves a perceived malfunction within the game. component:UI The Issue/PR deals with the game user interface, graphical or other. labels Feb 21, 2017
@LGM-Doyle LGM-Doyle added this to the v0.4.7 milestone Feb 21, 2017
GG/GG/ListBox.h Outdated
Pt ClientSizeExcludingScrolls() const;
/** Return a pair of dimensions of the scollable area if vscroll and/or hscroll is required.*/
std::pair<boost::optional<X>, boost::optional<Y>>
CheckIfScrollsRequired(const std::pair<bool, bool>& force_scrolls= {false, false}) const;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space b4 =

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

GG/GG/ListBox.h Outdated
@@ -569,6 +572,15 @@ class GG_API ListBox : public Control
/** Restore cached selected, clicked and last browsed rows.*/
void RestoreCachedSelections(const SelectionCache& cache);

/** Return the client size excluding the scroll bar sizes.*/
Pt ClientSizeExcludingScrolls() const;
/** Return a pair of dimensions of the scollable area if vscroll and/or hscroll is required.*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment is unclear to me

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded comment.

GG/GG/ListBox.h Outdated
CheckIfScrollsRequired(const std::pair<bool, bool>& force_scrolls= {false, false}) const;
/** Add vscroll and/or hscroll if \p required_total_extents x or y dimension exists. Return a
pair of bools indicating if added or removed vscroll or hscroll.*/
std::pair<bool, bool> AddOrRemoveScrolls(const std::pair<boost::optional<X>, boost::optional<Y>>& required_total_extents);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems like a rather odd function signature. why not take bools?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've expanded the descriptions in the functions which hopefully clarifies this.

The client size excludes the scroll bar because it is the size used to decide is scroll bars are needed.

The extent is the full size of the underlying list box, which will be larger than the client area unless the scrolls were force on.
The extent is only meaningfull if the scroll bar is to be added.

// Reset require prerender after call to adjust scrolls
Control::PreRender();
// Adding/removing scrolls and prerendering rows may change the row sizes and require a change
// in added/removed scrolls. This may not be stable. Perform two cycles and if it is not
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

prefer single space after .

// Perform a cycle of adjust scrolls and prerendering rows and return if sizes changed.
auto check_adjust_scroll_size_change =
[this]
(std::pair<bool,bool> force_scrolls = {false, false})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

space after ,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

Pt ListBox::ClientSizeExcludingScrolls() const
{
// this client area calculation disregards the thickness of scrolls
Pt cl_sz = (LowerRight() - Pt(X(BORDER_THICK), Y(BORDER_THICK))) -
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the way the lines are broken here is confusing. prefer keeping a single expression together with linebreaks after a ,

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried a different parsing so that each Pt starts its own line in the summation.

void ListBox::AdjustScrolls(bool adjust_for_resize)
Pt ListBox::ClientSizeExcludingScrolls() const
{
// this client area calculation disregards the thickness of scrolls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

meaning of "disregards" is unclear. is the area smaller than the total client area by the scroll area? or is the presence or absence of scrolls irrelevant to the calculation?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clarified the comment.

…orion#1356.

1. Improved threading of partial results through the components.
2. Improved commenting of code.
Copy link
Contributor Author

@LGM-Doyle LGM-Doyle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These changes were more than just addressing the concerns. I changed/fixed how the partial results were threaded through the AdjustScrolls() function.

GG/GG/ListBox.h Outdated
@@ -569,6 +572,15 @@ class GG_API ListBox : public Control
/** Restore cached selected, clicked and last browsed rows.*/
void RestoreCachedSelections(const SelectionCache& cache);

/** Return the client size excluding the scroll bar sizes.*/
Pt ClientSizeExcludingScrolls() const;
/** Return a pair of dimensions of the scollable area if vscroll and/or hscroll is required.*/
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expanded comment.

GG/GG/ListBox.h Outdated
Pt ClientSizeExcludingScrolls() const;
/** Return a pair of dimensions of the scollable area if vscroll and/or hscroll is required.*/
std::pair<boost::optional<X>, boost::optional<Y>>
CheckIfScrollsRequired(const std::pair<bool, bool>& force_scrolls= {false, false}) const;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

GG/GG/ListBox.h Outdated
CheckIfScrollsRequired(const std::pair<bool, bool>& force_scrolls= {false, false}) const;
/** Add vscroll and/or hscroll if \p required_total_extents x or y dimension exists. Return a
pair of bools indicating if added or removed vscroll or hscroll.*/
std::pair<bool, bool> AddOrRemoveScrolls(const std::pair<boost::optional<X>, boost::optional<Y>>& required_total_extents);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've expanded the descriptions in the functions which hopefully clarifies this.

The client size excludes the scroll bar because it is the size used to decide is scroll bars are needed.

The extent is the full size of the underlying list box, which will be larger than the client area unless the scrolls were force on.
The extent is only meaningfull if the scroll bar is to be added.

void ListBox::AdjustScrolls(bool adjust_for_resize)
Pt ListBox::ClientSizeExcludingScrolls() const
{
// this client area calculation disregards the thickness of scrolls
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I clarified the comment.

Pt ListBox::ClientSizeExcludingScrolls() const
{
// this client area calculation disregards the thickness of scrolls
Pt cl_sz = (LowerRight() - Pt(X(BORDER_THICK), Y(BORDER_THICK))) -
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've tried a different parsing so that each Pt starts its own line in the summation.

// Perform a cycle of adjust scrolls and prerendering rows and return if sizes changed.
auto check_adjust_scroll_size_change =
[this]
(std::pair<bool,bool> force_scrolls = {false, false})
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.


// Perform a cycle of adjust scrolls and prerendering rows and return if sizes changed.
auto check_adjust_scroll_size_change =
[this]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please put the capture in front of the parameter list.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved.

auto check_adjust_scroll_size_change =
[this](std::pair<bool, bool> force_scrolls = {false, false})
{
// This adjust scrolls may add or remove scrolls
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like unnecessary double indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am unsure of your meaning. What I see is,

auto variable_name =
    []()  // this line is indented because it is a continued line of code
    {
        AdjustScrolls()  //this  line is indented because it is the first line of code within the braced compond statement '{'
        ...
    };  // end of continue line of code.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would de-indent everything from the { to the } line (inclusive). Right now, the actual function body is double-indented from the surrounding scope.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've changed the indenting.

@geoffthemedio geoffthemedio merged commit 9499a52 into freeorion:master Feb 26, 2017
@Vezzra Vezzra added the status:merged All relevant commits of this PR were merged into the master development branch. label Feb 26, 2017
MatGB pushed a commit to MatGB/freeorion that referenced this pull request Feb 28, 2017
…orion#1356.

1. Improved threading of partial results through the components.
2. Improved commenting of code.
MatGB pushed a commit to MatGB/freeorion that referenced this pull request Feb 28, 2017
MatGB pushed a commit to MatGB/freeorion that referenced this pull request Feb 28, 2017
@LGM-Doyle LGM-Doyle deleted the fix_issue_1199_sitrep_list_lacks_scroll_bar_for_last_item branch March 11, 2017 14:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
category:bug The Issue/PR describes or solves a perceived malfunction within the game. component:UI The Issue/PR deals with the game user interface, graphical or other. status:merged All relevant commits of this PR were merged into the master development branch.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants