Added a dynamic layout system where UI elements can be moved about on a tiled grid.

This commit is contained in:
RedNicStone committed 2026-11-09 18:14:52 +01:00
1 parent ea6ba54666
commit 26c29df4ad
34 files changed
+1269

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
@tool
extends Control
const EMBEDDED_PANEL = preload("res://themes/layout_embedded_panel.tres")
@export var panel_id := "panel"
@export var element_type := ""
@export var cell_rect := Rect2i(0, 0, 6, 4)
@export var minimum_cells := Vector2i(4, 3)
@export var reference_size := Vector2(600, 440)
@export var fill_allocation := false
@export var padding := 8.0
@export_node_path("Control") var background_path := NodePath("")
func _ready() -> void:
clip_contents = true
resized.connect(arrange_content)
if has_node("Content") and $Content is PanelContainer:
$Content.add_theme_stylebox_override("panel", EMBEDDED_PANEL)
if not background_path.is_empty():
var background := get_node_or_null(background_path) as Control
if background != null:
background.add_theme_stylebox_override("panel", EMBEDDED_PANEL)
arrange_content.call_deferred()
func arrange_content() -> void:
if not has_node("Content"):
return
var content: Control = $Content
var available := (size - Vector2.ONE * padding * 2).max(Vector2.ZERO)
$Background.position = Vector2.ONE * padding
$Background.size = available
content.set_anchors_and_offsets_preset(Control.PRESET_TOP_LEFT)
if fill_allocation:
content.scale = Vector2.ONE
content.position = Vector2.ONE * padding
content.size = available
else:
content.size = reference_size
var factor := maxf(0.01, minf(available.x / reference_size.x, available.y / reference_size.y))
content.scale = Vector2.ONE * factor
content.position = (size - reference_size * factor) / 2