aboutsummaryrefslogtreecommitdiff
path: root/game/addons/zylann.hterrain/tools/minimap/ratio_container.gd
blob: 1bd6acac39f5313acd3da96acfe411addafc8273 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Simple container keeping its children under the same aspect ratio

@tool
extends Container


@export var ratio := 1.0


func _notification(what: int):
   if what == NOTIFICATION_SORT_CHILDREN:
      _sort_children2()


# TODO Function with ugly name to workaround a Godot 3.1 issue
# See https://github.com/godotengine/godot/pull/38396
func _sort_children2():
   for i in get_child_count():
      var child = get_child(i)
      if not (child is Control):
         continue
      var w := size.x
      var h := size.x / ratio
      
      if h > size.y:
         h = size.y
         w = h * ratio

      var rect := Rect2(0, 0, w, h)
      
      fit_child_in_rect(child, rect)