Change arrow positioning logic for ArrowPositionRules.ALIGN_ANCHOR #560
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.
minPosition and maxPosition are randomly chosen so they don't always give correct results. Here we tried to solve on edge case as noted in issue: #413
PR help needed
Hello I am Nika, I have been using this library for quite some time, I wanted to help in some way.
This is my first PR to public repo, I am new to Open source contribution, please feel free to provide any criticism that can improve this PR or my abilities, thank you.
🎯 Goal
Goal of this PR is to solve arrow positioning issues such as #413
🛠 Implementation details
For now only a certain edge case that was in issue#413 has been fixed. Logic seems to be quite complicated. We will have to calculate size of the balloon, size of the anchor, their positioning relative to each other and also size of the arrow.
As mentioned above minPosition and maxPosition are random numbers based on arrow size, some multiplying factor and padding.
private fun getMinArrowPosition(): Float { return (builder.arrowSize.toFloat() * builder.arrowAlignAnchorPaddingRatio) + builder.arrowAlignAnchorPadding }
Code in this PR return 0 for position if arrow position is below the x position of balloon. On the other hand if anchor is within the borders of ballon the code returns arrow position with balloon position substracted, since arrow is already positioned relative to balloon.
val tipArrowPosition = anchorX + (anchor.width) * builder.arrowPosition if ((tipArrowPosition - builder.arrowHalfSize) <= balloonX) { return 0.0f // + builder.cornerRadius } if ((tipArrowPosition - builder.arrowHalfSize) > balloonX) { if (anchor.width <= getMeasuredWidth() - builder.marginRight - builder.marginLeft) { return tipArrowPosition - builder.arrowHalfSize - balloonX } }
Further feedback is required
This code is not enough to fix all the edge cases, some further changes depend on the preferences of developer, such as how to calculate min and max positions.