From 09964df198f43e4bea3ece4d4ea16a5f4488edfe Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 24 Oct 2025 16:19:33 -0500 Subject: [PATCH 1/3] Removing moving the control when trying to resize it. --- Source/Editor/Gizmo/UIEditorGizmo.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index 765893bed..66bcd7634 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -398,7 +398,6 @@ namespace FlaxEditor var moveLocation = _mouseMovesPos + delta; var control = _activeWidget.UIControl.Control; var uiControlDelta = GetControlDelta(control, ref _mouseMovesPos, ref moveLocation); - control.LocalLocation += uiControlDelta * resizeAxisNeg; control.Size += uiControlDelta * resizeAxisPos - uiControlDelta * resizeAxisNeg; // Don't move if layout doesn't allow it From ab22b88a53acf7dec3830967b47abe485d017af1 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 29 Nov 2025 15:57:35 -0600 Subject: [PATCH 2/3] Better calculation for moving ui by the widgets. --- Source/Editor/Gizmo/UIEditorGizmo.cs | 39 ++++++++++++++++++++++++---- 1 file changed, 34 insertions(+), 5 deletions(-) diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index 66bcd7634..45a44d572 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -387,18 +387,47 @@ namespace FlaxEditor if (_mouseMovesWidget && _activeWidget.UIControl) { // Calculate transform delta - var resizeAxisAbs = _activeWidget.ResizeAxis.Absolute; - var resizeAxisPos = Float2.Clamp(_activeWidget.ResizeAxis, Float2.Zero, Float2.One); - var resizeAxisNeg = Float2.Clamp(-_activeWidget.ResizeAxis, Float2.Zero, Float2.One); var delta = location - _mouseMovesPos; // TODO: scale/size snapping? - delta *= resizeAxisAbs; // Resize control via widget var moveLocation = _mouseMovesPos + delta; var control = _activeWidget.UIControl.Control; var uiControlDelta = GetControlDelta(control, ref _mouseMovesPos, ref moveLocation); - control.Size += uiControlDelta * resizeAxisPos - uiControlDelta * resizeAxisNeg; + + // Transform delta to control local space + var rotation = control.Rotation * Mathf.DegreesToRadians; // TODO: use total parent rotation + var cos = Mathf.Cos(rotation); + var sin = Mathf.Sin(rotation); + var localDeltaX = uiControlDelta.X * cos + uiControlDelta.Y * sin; + var localDeltaY = uiControlDelta.Y * cos - uiControlDelta.X * sin; + var localDelta = new Float2(localDeltaX, localDeltaY); + localDelta *= _activeWidget.ResizeAxis.Absolute; + + // Calculate size change + var resizeAxisPos = Float2.Clamp(_activeWidget.ResizeAxis, Float2.Zero, Float2.One); + var resizeAxisNeg = Float2.Clamp(-_activeWidget.ResizeAxis, Float2.Zero, Float2.One); + var dSizeScaled = localDelta * resizeAxisPos - localDelta * resizeAxisNeg; + var scale = control.Scale; + var dSize = new Float2( + Mathf.Abs(scale.X) > Mathf.Epsilon ? dSizeScaled.X / scale.X : 0, + Mathf.Abs(scale.Y) > Mathf.Epsilon ? dSizeScaled.Y / scale.Y : 0); + + // Calculate pivot offset to keep the opposite edge stationary + var pivotOffset = Float2.Zero; + if (Mathf.Abs(dSizeScaled.X) > Mathf.Epsilon) + pivotOffset.X = (_activeWidget.ResizeAxis.X < 0 ? control.Pivot.X - 1.0f : control.Pivot.X) * dSizeScaled.X; + if (Mathf.Abs(dSizeScaled.Y) > Mathf.Epsilon) + pivotOffset.Y = (_activeWidget.ResizeAxis.Y < 0 ? control.Pivot.Y - 1.0f : control.Pivot.Y) * dSizeScaled.Y; + + // Transform pivot offset back to parent space + var dLocationX = pivotOffset.X * cos - pivotOffset.Y * sin; + var dLocationY = pivotOffset.X * sin + pivotOffset.Y * cos; + var dLocation = new Float2(dLocationX, dLocationY); + + // Apply changes + control.Size += dSize; + control.LocalLocation += dLocation; // Don't move if layout doesn't allow it if (control.Parent != null) From bbaa2dfc73ec5cecd2625a0059d4e9b7bac41ad1 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sat, 29 Nov 2025 16:13:46 -0600 Subject: [PATCH 3/3] Fix pibot relative movement. --- Source/Editor/Gizmo/UIEditorGizmo.cs | 34 ++++++++++++++++------------ 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index 45a44d572..7ae34f590 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -413,21 +413,27 @@ namespace FlaxEditor Mathf.Abs(scale.X) > Mathf.Epsilon ? dSizeScaled.X / scale.X : 0, Mathf.Abs(scale.Y) > Mathf.Epsilon ? dSizeScaled.Y / scale.Y : 0); - // Calculate pivot offset to keep the opposite edge stationary - var pivotOffset = Float2.Zero; - if (Mathf.Abs(dSizeScaled.X) > Mathf.Epsilon) - pivotOffset.X = (_activeWidget.ResizeAxis.X < 0 ? control.Pivot.X - 1.0f : control.Pivot.X) * dSizeScaled.X; - if (Mathf.Abs(dSizeScaled.Y) > Mathf.Epsilon) - pivotOffset.Y = (_activeWidget.ResizeAxis.Y < 0 ? control.Pivot.Y - 1.0f : control.Pivot.Y) * dSizeScaled.Y; - - // Transform pivot offset back to parent space - var dLocationX = pivotOffset.X * cos - pivotOffset.Y * sin; - var dLocationY = pivotOffset.X * sin + pivotOffset.Y * cos; - var dLocation = new Float2(dLocationX, dLocationY); - - // Apply changes + // Apply size change control.Size += dSize; - control.LocalLocation += dLocation; + + // Calculate location offset to keep the opposite edge stationary + // When PivotRelative is false, resizing keeps Top-Left (Location) constant, + // so we only need to slide back if we are resizing Left or Top edges. + if (!control.PivotRelative) + { + var pivotOffset = Float2.Zero; + if (_activeWidget.ResizeAxis.X < 0 && Mathf.Abs(dSize.X) > Mathf.Epsilon) + pivotOffset.X = -dSize.X * scale.X; + if (_activeWidget.ResizeAxis.Y < 0 && Mathf.Abs(dSize.Y) > Mathf.Epsilon) + pivotOffset.Y = -dSize.Y * scale.Y; + + // Transform offset back to parent space and apply + var dLocationX = pivotOffset.X * cos - pivotOffset.Y * sin; + var dLocationY = pivotOffset.X * sin + pivotOffset.Y * cos; + var dLocation = new Float2(dLocationX, dLocationY); + + control.LocalLocation += dLocation; + } // Don't move if layout doesn't allow it if (control.Parent != null)