Fix right padding calculation for horizontal centering #520
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The calculations for right padding on horizontal centering don't seem right:
If
availWidth
is 30, andrWidth
is 10, thenleftPaddingAmount
will be 10. From this,remainder
will be10
andrightPaddingAmount
will be 20, which is too large, giving a total width of 10 + 10 + 20 = 40.Similarly, if
availWidth
is 30 andrWidth
is 11, thenleftPaddingAmount
will be 8. From this,remainder
will be14
, andrPaddingAmount
will be 22, giving a total width of 8 + 11 + 22 = 41.This patch provides a new calculation for
rPaddingAmount
, which will be 10 and 12, respectively, both giving a resulting length of 30 which matchesavailWidth
.This does not produce any visible differences on rendering simple scenarios because
vty
will apply cropping to theImage
generated, but it may provide invalid width values for general calculations if there is aWidget
to the left or right of the centeredWidget
.It may be that
vCenterWith
has the same type of error; I did not investigate that function in detail.