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 scale bar text being cut #1716

Merged
merged 17 commits into from
Oct 3, 2022
Merged

Fix scale bar text being cut #1716

merged 17 commits into from
Oct 3, 2022

Conversation

jush
Copy link
Member

@jush jush commented Oct 3, 2022

Summary of changes

Fixes rendering issues where the scale bar text was being cut on the sides:

Before:

After:

Also added a new example activity to showcase scale bar customization.

User impact (optional)

Pull request checklist:

  • Briefly describe the changes in this PR.
  • Include before/after visuals or gifs if this PR includes visual changes.
  • Write tests for all new functionality. If tests were not written, please explain why.
  • Optimize code for java consumption (@JvmOverloads, @file:JvmName, etc).
  • Add example if relevant.
  • Document any changes to public APIs.
  • Run make update-api to update generated api files, if there's public API changes, otherwise the verify-api-* CI steps might fail.
  • Update CHANGELOG.md or use the label 'skip changelog', otherwise check changelog CI step will fail.
  • If this PR is a v10.[version] release branch fix / enhancement, merge it to main firstly and then port to v10.[version] release branch.

Fixes: < Link to related issues that will be fixed by this pull request, if they exist >

PRs must be submitted under the terms of our Contributor License Agreement CLA.

@jush jush requested a review from a team as a code owner October 3, 2022 10:35
@jush jush added the bug 🪲 Something isn't working label Oct 3, 2022
@jush jush changed the title Fixed scale bar text being cut Fix scale bar text being cut Oct 3, 2022
@jush jush force-pushed the rs-scale-bar-text-cut-MAPSAND-497 branch from 015e5c4 to 9a457fb Compare October 3, 2022 10:41
@jush jush requested a review from kiryldz October 3, 2022 10:42
@paulrenn67
Copy link
Contributor

Fix looks good, but wondering about the alignment of the start/end labels, at least the "100m" seems to be differently aligned than in the original screenshot. Should we try to centrally align the labels above the start/end of the scalebar? In this case, the "0" should be more slightly to the left (does not look correctly aligned even in the original) and the "100m" should be more to the right. The "50m" label seems to be correctly centred.

@jush
Copy link
Member Author

jush commented Oct 3, 2022

Fix looks good, but wondering about the alignment of the start/end labels, at least the "100m" seems to be differently aligned than in the original screenshot. Should we try to centrally align the labels above the start/end of the scalebar? In this case,

The alignment has not changed, but in order for the text to fix we need to "move" it away from the margins. See this video of the behaviour:

scale_bar.mp4

The scale bar layout has a defined width that we should honour. Therefore, the only way I could think to easily fix it is to move the label. If we want a more advanced solution we could try to figure out if the labels fit and if not then reduce the amount of unit bars we show. We will probably need to do that to fix the issue where the labels overlap each other. But that I'd say is for another PR.

the "0" should be more slightly to the left (does not look correctly aligned even in the original) and the "100m" should be more to the right. The "50m" label seems to be correctly centred.

The "0" is left aligned but given the horizontal bearing it renders it a bit to the right. (See https://stackoverflow.com/a/7579469)

Co-authored-by: Kiryl Dzehtsiarenka <kiryl.dzehtsiarenka@mapbox.com>
}

// Check if it goes beyond the left margin of the view
if (x - strokePaint.strokeWidth / 2 < 0) {
Copy link
Contributor

Choose a reason for hiding this comment

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

is it ok that we check x here but operate with safeX below?

Copy link
Member Author

Choose a reason for hiding this comment

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

You're right. It's better to use safeX.

Copy link
Contributor

Choose a reason for hiding this comment

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

and also for better readability I'd use if (x < trokePaint.strokeWidth / 2) similar to L316

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmmm I personally think that:

if (x < trokePaint.strokeWidth / 2)

it's a bit obscure.
I need to think more to figure out why we're comparing a position (x or safeX) with a width (strokeWidth). Somehow, to me, mine reads easier: to position safeX I remove a width and then check if it goes beyond the left minimum position (0).

But happy to change it to your proposal if others also prefer it.

@jush jush requested review from yunikkk and kiryldz October 3, 2022 12:12
CHANGELOG.md Show resolved Hide resolved
/**
* Activity to showcase scale bar custom configuration using xml attributes.
*/
class ScaleBarActivity : AppCompatActivity() {
Copy link
Contributor

Choose a reason for hiding this comment

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

should we create similar activity on iOS for parity and making sure that our scalebar customizations are aligned? @mapbox/maps-ios

Copy link
Contributor

@kiryldz kiryldz left a comment

Choose a reason for hiding this comment

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

Would be nice to have dedicated pixel match as the tailwork, otherwise LGTM

@jush jush force-pushed the rs-scale-bar-text-cut-MAPSAND-497 branch from 5e38872 to f97571a Compare October 3, 2022 13:01
@jush jush force-pushed the rs-scale-bar-text-cut-MAPSAND-497 branch from 7c69dc9 to d0adea0 Compare October 3, 2022 13:55
@jush jush merged commit fb11e98 into main Oct 3, 2022
@jush jush deleted the rs-scale-bar-text-cut-MAPSAND-497 branch October 3, 2022 14:22
jush added a commit that referenced this pull request Oct 4, 2022
jush added a commit that referenced this pull request Oct 4, 2022
mapbox-github-ci-writer-public-1 bot pushed a commit that referenced this pull request May 17, 2023
* Improve performance of setting puck style properties

* fix test

* fix more tests
kiryldz added a commit that referenced this pull request Aug 2, 2023
* Improve performance of setting puck style properties

* fix test

* fix more tests
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🪲 Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants