Grid container don't shrink content

Godot Version

Godot Engine v4.2.2

Question

Hi, I’m trying to make a small game of life where the player can select the size of the grid.

My cells are TextureButtons that use a 56*56px image. To make the grid, I tried to use a GridContainer. When there are only a few cells, they are upscaled to fill the container size. However, when there are so much that they should shrink to less than 56px to fit in the container, the container goes bigger instead.

Is there a way to make the content shrink instead of the container to go bigger?

i believe you can set the item in grid container to be shrink center, but that means each item will need to have custom minimize size to hold their expected size

I tried to set Layout/Container Sizing/Horizontal and Vertical to Shrink Center and the container keeps getting bigger. Then I switched Layout/Custom Minimum Size/x and y from 0 to 1 in case 0 was some kind of special value. And it didn’t work either.

For each TextureButton enable ignore_texture_size (so it can shrink below its original size) and the stretch_mode to either “Scale” (if you want to fill out all available space and don’t mind distorting the texture) or “Keep Aspect Centered”. Lastly, enable the expand flags for both horizontal and vertical container sizing on each button.

ignore_texture_size whas what I was missing. Setting this to true and Stretch mode to Keep Aspect Centered did exactly what I needed.

Thanks !

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.