PerfectUIGridLayout – Responsive Grid Layout Module

Features:

:heavy_check_mark: Automatic Cell Size Adjustment – Dynamically increases CellSize to maximize horizontal spacing, not wasting space with huge undesired paddings (you can still have UIPadding, if you don’t want the cells to fully touch the sides).
:heavy_check_mark: Equal Cell Padding (Scaled) – Adjusts the Y padding to match the X scale, ensuring proportional spacing.
:heavy_check_mark: Live Updates – Automatically updates when the container’s size changes or when cells are added/removed in-game.


How to Use:

  1. Download this model.
  2. Insert it into your game.
  3. Place the ModuleScript in ReplicatedStorage (or another location, but update the reference in the LocalScript).
  4. Move PerfectUIGridLayout_Local (found inside the ModuleScript) into the UIGridLayout you want to adjust.
  5. Adjust X_PADDING_SCALE in the LocalScript to set the desired spacing between cells.
  6. Set the CellSize (can be in Scale, Offset, or a mix of both), which will define the minimum size of your cells.
  7. Adjust FillDirectionMaxCells to set the maximum number of cells per row.

Important Notes:

:warning: If you’re using UIAspectRatioConstraint or UISizeConstraint, only apply it to the UIGridLayout, not to individual frames, otherwise it won’t work properly.
:warning: Ensure CanvasSize is set to {0, 0}, {0, 0}.


Example Setup:

Configuration

  • Minimum Cell Size: {0.149, 0}, {0.2, 0}
  • Max Cells per Row: FillDirectionMaxCells = 3

  • In the LocalScript, I set X_PADDING_SCALE = **0.035**

Result

  • Final CellPadding: {0.035, 0}, {0.066, 0} → Equal horizontal & vertical spacing
  • Final CellSize: {0.309, 0}, {0.36, 0} (increased from {0.149, 0}, {0.2, 0}) to fully utilize the frame’s width
:bulb: Tip: Normally, I would use a UIAspectRatioConstraint to maintain the cell ratio, but I left it out in this example for clarity.
:bulb: Tip 2: You can use a UIPadding, but sometimes, it is buggy, I need to figure out why

Feel free to ask questions! :blush:

Also, I haven’t tested it thoroughly, so it might have bugs.
5 Likes