-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
fix: keep logo & text alignments consistent #11284
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
base: master
Are you sure you want to change the base?
Conversation
|
🚀 Updated review app: https://pr-11284-badges-shields.fly.dev |
jNullj
left a comment
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.
It's a bit hard to see that changes, i might pick some pixel art editor to try comparing them.
But i do have some feedback about the code, see my changes suggestion.
Regarding the fix, Could you present what exactly is inconsistent here before the change and how this solves the issue?
|
I've attached two 5x zoom level images with measurements to the PR description. It appears that the logo-only in-for-the-badge style still has an alignment issue. I will look into it. |
|
I've fixed the style of the for-the-badge. I also updated its 5x preview image. The 1x preview may require your deployment to update. |
jNullj
left a comment
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.
Sorry for the late response.
This review I set some time to try and understand the existing and proposed logic here
badge-maker/lib/badge-renderers.js
Outdated
| messageRectWidth = | ||
| 2 * TEXT_MARGIN + logoWidth + gutter + messageTextWidth - 1 | ||
| if (noText) { | ||
| messageRectWidth += 5 // Compensate for the extra padding |
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 tried to warp my head around this one.
If you look closely the original logic seems to say, if we have a logo add the logo width and a separator (gutter) to separate logo and message text, otherwise, only use message text. ofc we add text margin in both sides as well.
You seem to increase our LOGO_MARGIN then add some compensation.
I wonder if we shouldn't add this logic to the gutter to begin with at line 808
const gutter = noText ? LOGO_TEXT_GUTTER - LOGO_MARGIN : LOGO_TEXT_GUTTER
But as i was thinking that i noticed, we get a negative gutter, which hardly makes sense as it should, if im not wrong, be never negative, as it represent a size to space out elements.
in that case, maybe presenting abs would fix our problems and remove the need for the -1 and additional compensation. Even more so that the mentioned line to set gutter already takes into account the noText logic!
please let me know what you think.
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.
Thanks for looking so deep. I've made a commit to make these logics cleaner.
You will notice that now some values have base value now:
let labelTextMinX = TEXT_MARGIN
let labelRectWidth = 2 * TEXT_MARGIN
let messageTextMinX = TEXT_MARGIN
let messageRectWidth = 2 * TEXT_MARGIN + messageTextWidthI also removed the LOGO_MARGIN since its has the same value as TEXT_MARGIN. And the LOGO_MARGIN meaningless because we should actual use TEXT_MARGIN to caculate its size.
I now have a clear idea of how to calculate the size of the badge, and I should be able to optimize the calculation logic of other badges in the same way in the future.
Looking forward to your another review. ✌️
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.
@jNullj would be great if you could take another look at this one :)
| const gutter = noText ? LOGO_TEXT_GUTTER - LOGO_MARGIN : LOGO_TEXT_GUTTER | ||
| let logoMinX, labelTextMinX | ||
| let labelTextMinX = TEXT_MARGIN | ||
| let labelRectWidth = 2 * TEXT_MARGIN |
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.
Fixes issue where we add empty space after the badge when there is no label/logo-in-label
| let labelRectWidth = 2 * TEXT_MARGIN | |
| let labelRectWidth = needsLabelRect ? 2 * TEXT_MARGIN : undefined |
| labelTextMinX = logoMinX + logoWidth + gutter | ||
| } else { | ||
| labelTextMinX = TEXT_MARGIN | ||
| if (labelColor) labelRectWidth += logoWidth |
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.
| if (labelColor) labelRectWidth += logoWidth | |
| if (labelColor || needsLabelRect) labelRectWidth += logoWidth |
| } | ||
| messageTextMinX = labelRectWidth + TEXT_MARGIN | ||
| messageRectWidth = 2 * TEXT_MARGIN + messageTextWidth | ||
| if (hasLabel) labelRectWidth += labelTextMinX + labelTextWidth |
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.
| if (hasLabel) labelRectWidth += labelTextMinX + labelTextWidth | |
| if (hasLabel) labelRectWidth += labelTextWidth |
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 added a few fixes, there was issues in forTheBadge style with label rect growing outside rendered area, creating empty space.
That also added space to the label area itself.
You can easily apply the fixes if you don't find anything i missed there.
as a side note, i used your html examples but added another case, for labelColor, as it exists in the edited code.
http://localhost:8080/badge/--000?logo=npm&style=for-the-badge&labelColor=blue
Some of our current badges have some inconsistent spacing. Especially the logo-only badge. I've fixed/changed them to be consistent.
I've attached the 5x zoom level preview image with measurements. As you can see, some badges don't have consistent left-right padding. But if the numbers differ by only 1, it can be ignored.
I didn't change the style of the social badge since its design is a bit special. I think the padding is fine. Please let me know if you want the social badge to be changed as well.
The measurement tool I use: PixelSnap 2.
img.shields.io
pr-11284-badges-shields.fly.dev
localhost:8080
GitHub cannot display localhost assets since they have Camo for caching resources. But these links might be helpful for you to review.
Markdown
HTML