Skip to content

Fix SVG alignment and click box#273

Merged
AndreasArvidsson merged 2 commits intomainfrom
fix-svg-alignment-and-click-box
Sep 11, 2021
Merged

Fix SVG alignment and click box#273
AndreasArvidsson merged 2 commits intomainfrom
fix-svg-alignment-and-click-box

Conversation

@pokey
Copy link
Copy Markdown
Member

@pokey pokey commented Sep 11, 2021

I adjusted the measurements to fix the math bug for my setup, but unfortunately different users will be affected proportional to the square of the ratio of their character width to the ceiling of the width, so they'll unfortunately need to do their own tweaking if they've adjusted their defaults

image

Note that the hats have moved up very slightly, but it is minor, and we will tweak these heights in #269 anyway

Fixes #110
Fixes #92

And possibly #78

Comment thread src/core/Decorations.ts
Comment on lines +166 to +167
margin: `-${svgHeightPx}px -${svgWidthPx}px 0 0`,
width: `${svgWidthPx}px`,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

No need to play games with span width anymore because we now align to the left side of the char

Comment thread src/core/Decorations.ts
Comment on lines -278 to -280
((originalViewBoxWidth / hatWidthToCharacterWidthRatio) *
fontMeasurements.characterWidth) /
svgWidthPx;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was the dumb mistake. We need to adjust from char width to svg width, not the other way around 😅

Comment thread src/core/Decorations.ts
Comment on lines +277 to +278
const newViewBoxX =
(-(characterWidth - hatWidthPx) * (newViewBoxWidth / svgWidthPx)) / 2;
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Since we're left-aligned, we basically need to shift right by (characterWidth - hatWidthPx) / 2, translated to svg view box space (newViewBoxWidth / svgWidthPx)

@pokey pokey marked this pull request as ready for review September 11, 2021 17:02
@AndreasArvidsson AndreasArvidsson merged commit 1848837 into main Sep 11, 2021
@AndreasArvidsson AndreasArvidsson deleted the fix-svg-alignment-and-click-box branch September 11, 2021 17:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SVG hat obstructs click target area Fix decoration appearing after GitLens Current Line Blame

2 participants