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
Fix issue 1199 sitrep list lacks scroll bar for last item. #1356
Conversation
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.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space b4 =
There was a problem hiding this comment.
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.*/ |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
GG/src/ListBox.cpp
Outdated
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
prefer single space after .
GG/src/ListBox.cpp
Outdated
// 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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
space after ,
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
GG/src/ListBox.cpp
Outdated
Pt ListBox::ClientSizeExcludingScrolls() const | ||
{ | ||
// this client area calculation disregards the thickness of scrolls | ||
Pt cl_sz = (LowerRight() - Pt(X(BORDER_THICK), Y(BORDER_THICK))) - |
There was a problem hiding this comment.
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 ,
There was a problem hiding this comment.
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.
GG/src/ListBox.cpp
Outdated
void ListBox::AdjustScrolls(bool adjust_for_resize) | ||
Pt ListBox::ClientSizeExcludingScrolls() const | ||
{ | ||
// this client area calculation disregards the thickness of scrolls |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this 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.*/ |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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.
GG/src/ListBox.cpp
Outdated
void ListBox::AdjustScrolls(bool adjust_for_resize) | ||
Pt ListBox::ClientSizeExcludingScrolls() const | ||
{ | ||
// this client area calculation disregards the thickness of scrolls |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I clarified the comment.
GG/src/ListBox.cpp
Outdated
Pt ListBox::ClientSizeExcludingScrolls() const | ||
{ | ||
// this client area calculation disregards the thickness of scrolls | ||
Pt cl_sz = (LowerRight() - Pt(X(BORDER_THICK), Y(BORDER_THICK))) - |
There was a problem hiding this comment.
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.
GG/src/ListBox.cpp
Outdated
// 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}) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
GG/src/ListBox.cpp
Outdated
|
||
// Perform a cycle of adjust scrolls and prerendering rows and return if sizes changed. | ||
auto check_adjust_scroll_size_change = | ||
[this] |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved.
GG/src/ListBox.cpp
Outdated
auto check_adjust_scroll_size_change = | ||
[this](std::pair<bool, bool> force_scrolls = {false, false}) | ||
{ | ||
// This adjust scrolls may add or remove scrolls |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
…orion#1356. 1. Improved threading of partial results through the components. 2. Improved commenting of code.
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.