diff --git a/scripts/dashboard_grid.gd b/scripts/dashboard_grid.gd index 09ebc2f..0768972 100644 --- a/scripts/dashboard_grid.gd +++ b/scripts/dashboard_grid.gd @@ -30,11 +30,14 @@ var _cell_styles: Dictionary = {} # cell -> StyleBoxFlat func _ready() -> void: + mouse_filter = Control.MOUSE_FILTER_STOP resized.connect(_rebuild_grid) - _rebuild_grid() + gui_input.connect(_on_gui_input) + # Defer initial build so layout is resolved and size is valid + call_deferred("_rebuild_grid") -func _gui_input(event: InputEvent) -> void: +func _on_gui_input(event: InputEvent) -> void: if event is InputEventMouseButton: var mb: InputEventMouseButton = event if mb.button_index == MOUSE_BUTTON_LEFT and not mb.double_click: @@ -124,8 +127,14 @@ func _begin_drag(mouse_pos: Vector2) -> void: _drag_source_col = col _drag_source_row = row + + # Calculate where the module sits in grid coordinates before reparenting. + # module.position is relative to the cell; cell.position is relative to us (the grid). + var cell: PanelContainer = _cells[row][col] + var module_origin_in_grid := cell.position + module.position + _drag_mouse_offset = mouse_pos - module_origin_in_grid + _drag_module = _take_module_from_cell(col, row) - _drag_mouse_offset = mouse_pos - _drag_module.position _is_dragging = true # Reparent to grid so it renders above all cells