Skip to content

A custom Container node for Godot Engine 4, to limit the size of children nodes

License

Notifications You must be signed in to change notification settings

brombres/Godot-MaxSizeContainer

 
 

Repository files navigation

MaxSizeContainer for Godot 4.x

A custom Container node for Godot Egine 4.x which limits the size of child nodes. All Control nodes have a rect_min_size property, but they lack rect_max_size. MaxSizeContainer addresses this issue.

DemoGif

DemoGif

About Current Release
Version 1.3
Date August 9, 2023
Platform Godot 4.x (tested on 4.2-dev2)
License MIT License
Authors Matthieu Huvé (Godot 3.x original)
Benedikt Wicklein (Godot 4 Beta)
Brom Bresenham (Godot 4.x)

Installation

  • Copy addons/MaxSizeContainer into your project (final path should be res://addons/MaxSizeContainer).

FileSystem

  • In the Godot Editor, go to Project Settings > Plugins and enable the MaxSizeContainer plugin.

PluginMenu

Usage

To be limited in size, a Control node must be child of a MaxSizeContainer.

  • From the editor, press Add a new node, and select MaxSizeContainer

AddNewNodeMenu

Note: to add the Container from script, you must use this code:

var MaxSizeContainer = preload("res://addons/MaxSizeContainer/max_size_container.gd")

add_child(MaxSizeContainer.new())
  • Add any Control node as a child of MaxSizeContainer.

Note: only one child is supported

  • Select the mode, the limit (pixel size or aspect ratio, depending on the mode), and how you want the child node aligned when it reaches the maximum size. Properties Properties (In Pixel Size mode, -1 means no limit)

Examples

(Screenshots from older version)

  • Let's start from this scene.
SceneTree SmallWindow LargeWindow
Scene tree Small window Large window

When the window is enlarged, the main scene takes all the available space, as it is set as Expand.

  • To prevent that and make the text more readable, let's add a MaxSizeContainer, child of MainScreen (ScrollContainer) and parent of VBoxContainer:
SceneTree Parameters LargeWindow
Scene tree Parameters Large window
  • You can also nest different MaxSizeContainers together, and have fun:
SceneTreeAndParameters LargeWindow
Scene tree and parameters Large window

Troubleshooting

If the container doesn't work, try these solutions:

  • Make sure there is only one child node, and it inherits from Control
  • Make sure the child node's size flag are set to Fill vertically and horizontally.
  • Make sure max_size is bigger than the minimum possible size of the child.

License

See License file This README page was greatly inspired by jmb462.

About

A custom Container node for Godot Engine 4, to limit the size of children nodes

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • GDScript 100.0%