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

Remove margin from body on mobile #950

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

sftrabbit
Copy link
Contributor

@sftrabbit sftrabbit commented Dec 22, 2022

By default, most browsers apply a default margin of 8px to the body element. On mobile, PuzzleScript applies the following style the body element:

        var style = {
            height: "100%",
            overflow: "hidden",
            position: "fixed",
            width: "100%"
        }

The position: "fixed" creates a new document flow root, which means that any children with position: absolute are going to be positioned with the 8px offset, including the game canvas.

This can be seen by simulating a mobile device (or using a real mobile device) and inspecting the body and game canvas elements (note the orange margin at the top and left):

Screenshot 2022-12-22 at 23 13 42

Here's another example where I've set the viewport size so that the game should fit perfectly on the screen, but you can see everything is offset slightly:

Screenshot 2022-12-22 at 23 38 42

This caused two issues:

  • The game canvas is slightly outside the viewport.
  • Touch coordinates computed by relMouseCoords in inputoutput.js were offset by 8px. This was most noticeable when using the PuzzleScript Plus fork with support for touch controls.

The fix is just to set the body margin to 0 and make sure the mobile pull-out menu is still positioned correctly. After the fix, the above game fits on screen as expected:

Screenshot 2022-12-22 at 23 40 34

Most browsers have a default margin of 8px on the `body` element, which was
offsetting the `canvas` element. This was not only pushing the canvas slightly
off screen, but was also affecting the calculation of touch coordinates (which
was most noticable with the PuzzleScript Plus fork because it supports touch
controls).
@sftrabbit
Copy link
Contributor Author

I do also have code that I think makes relMouseCoords more robust, even if the margin remains, but a) it's not necessary if we just remove the margin, and b) I don't have 100% confidence that it works in all cases and on all devices.

Auroriax added a commit to Auroriax/PuzzleScriptPlus that referenced this pull request Dec 23, 2022
Copy link

@cwboden cwboden left a comment

Choose a reason for hiding this comment

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

Looks good to me, pending a question.

@@ -161,7 +161,7 @@
}

.tab-icon {
left: -0.5em;
Copy link

Choose a reason for hiding this comment

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

What's the intent behind this change? To account for the slight shift in the margin?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's right! The tab icon was being positioned relative to the inside of the margin, so to make up for the 8px margin, it was being shifted back 8px (0.5em is equivalent in most browsers by default if you don't change the font size). So now that the margin is gone, it doesn't need to be shifted. Without this, the little pull out tab thing doesn't stick out enough.

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.

None yet

2 participants