Skip to content

Fix grid item width and height calculation for correct spacing #82

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

Merged
merged 1 commit into from
Jun 1, 2024

Conversation

gitryder
Copy link
Contributor

This PR

Problem:

The current formula used to calculate grid item width and height is incorrect:

  • Width: (width - (gap + 1) times cols) / cols
  • Height: (height - (gap + 1) times rows) / rows
    This formula mistakenly assumes the total width or height occupied by gaps is (gap + 1) times cols for width and (gap + 1) times rows for height, which is incorrect. The correct formula should consider the total number of gaps, which is (cols + 1) for width and (rows + 1) for height.


Solution:

The formulas have been updated to correctly calculate the width and height of grid items:

  • Corrected Width: (width - (cols + 1) times gap) / cols
  • Corrected Height: (height - (rows + 1) times gap) / rows

- Correct the formula for calculating grid item width to account for total gaps:
  (width - (_cols + 1) * gap) / _cols
- Correct the formula for calculating grid item height to account for total gaps:
  (height - (_rows + 1) * gap) / _rows

This fixes the issue where extra space appears on the right and bottom sides
of the grid when grid cols or grid rows values differ from the grid gap value,
ensuring even spacing throughout the grid.
Copy link

vercel bot commented May 30, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
svelte-grid-extended-bwyl ✅ Ready (Inspect) Visit Preview 💬 Add feedback May 30, 2024 7:07pm

@cuire cuire merged commit 0d31f75 into cuire:main Jun 1, 2024
4 checks passed
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.

[Bug] Extra space on right end of grid when grid cols differs from grid gap
2 participants