From 22e4eb0bd466072eb8b40061e7715e4ecea7af3e Mon Sep 17 00:00:00 2001 From: Hermann Vincent Date: Sun, 28 Dec 2025 04:50:42 +0100 Subject: [PATCH 1/3] fix --- .../SceneView/SceneViewportWidget.Sizing.cs | 77 +++++++++++++++---- 1 file changed, 61 insertions(+), 16 deletions(-) diff --git a/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs b/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs index 3e266012f..691932b8e 100644 --- a/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs +++ b/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs @@ -15,6 +15,7 @@ public partial class SceneViewportWidget /// public void SetDefaultSize() { + Log.Info("SetDefaultSize"); ForcedSize = null; ForcedAspectRatio = null; @@ -24,13 +25,25 @@ public void SetDefaultSize() SetSizeMode( SizeMode.CanGrow, SizeMode.CanGrow ); } - + /// /// Set the viewport to a specific aspect ratio /// /// public void SetAspectRatio( float aspectRatio ) { + Log.Info("SetAspectRatio"); + + MinimumSize = Vector2.Zero; + MaximumSize = QT_MAX_SIZE; + FixedSize = QT_MAX_SIZE; + + // Don't update if the aspect ratio hasn't changed + if ( ForcedAspectRatio.HasValue && ForcedAspectRatio.Value.AlmostEqual( aspectRatio ) && !ForcedSize.HasValue ) + { + return; + } + ForcedAspectRatio = aspectRatio; ForcedSize = null; @@ -51,58 +64,90 @@ public void SetResolution( Vector2 resolution ) private void UpdateSizeConstraints() { + Log.Info("UpdateSizeConstraints"); if ( ForcedSize.HasValue ) { var size = ForcedSize.Value; - // For fixed resolution, use exact size constraints MaximumSize = size; FixedSize = size; } + else if ( ForcedAspectRatio.HasValue ) + { + if ( Parent != null ) + { + Log.Info($"CurrentSize: x{Size.x} y{Size.y}"); + var contentRect = Parent.ContentRect; + var parentSize = new Vector2( contentRect.Width, contentRect.Height ); + MaximumSize = parentSize; + Log.Info($"MaximumSize: x{MaximumSize.x} y{MaximumSize.y}"); + } + else + { + MaximumSize = new Vector2( QT_MAX_SIZE, QT_MAX_SIZE ); + } + FixedSize = QT_MAX_SIZE; + Log.Info($"FixedSize: x{FixedSize.x} y{FixedSize.y}"); + } else { - // For aspect ratio mode or free, don't lock the size - let it be dynamic MaximumSize = new Vector2( QT_MAX_SIZE, QT_MAX_SIZE ); FixedSize = QT_MAX_SIZE; } Layout.SizeConstraint = SizeConstraint.SetDefaultConstraint; SetSizeMode( SizeMode.Expand, SizeMode.Expand ); - - UpdateGeometry(); - AdjustSize(); } + Vector2? defaultSize; + protected override Vector2 SizeHint() { - // Exact size, easy if ( ForcedSize.HasValue ) { return ForcedSize.Value; } - // Free if ( !ForcedAspectRatio.HasValue ) { return base.SizeHint(); } - // Dynamically calculate size based on current parent size - var parentSize = Parent?.Size ?? base.SizeHint(); - var parentAspect = parentSize.x / parentSize.y; + if ( defaultSize == null ) + { + defaultSize = Size; + } + + var availableSize = defaultSize.Value; + if ( availableSize.x <= 0 || availableSize.y <= 0 ) + { + return base.SizeHint(); + } + var aspectRatio = ForcedAspectRatio.Value; + Log.Info( $"Aspect ratio: {aspectRatio}" ); + + if ( aspectRatio <= 0 || float.IsNaN( aspectRatio ) || float.IsInfinity( aspectRatio ) ) + { + return availableSize; + } - if ( aspectRatio > parentAspect ) + var availableAspect = availableSize.x / availableSize.y; + Vector2 result; + if ( aspectRatio > availableAspect ) { - // Fit to width - return new Vector2( parentSize.x, parentSize.x / aspectRatio ); + result = new Vector2( availableSize.x, availableSize.x / aspectRatio ); } else { - // Fit to height - return new Vector2( parentSize.y * aspectRatio, parentSize.y ); + result = new Vector2( availableSize.y * aspectRatio, availableSize.y ); } + if ( MaximumSize.x > 0 && MaximumSize.y > 0 ) + { + result = new Vector2( MathF.Min( result.x, MaximumSize.x ), MathF.Min( result.y, MaximumSize.y ) ); + } + return result; } } From 310286eb25a598ae482ac57cee33c7b070632d6c Mon Sep 17 00:00:00 2001 From: Hermann Vincent Date: Sun, 28 Dec 2025 04:59:12 +0100 Subject: [PATCH 2/3] remove comments --- .../Code/Scene/SceneView/SceneViewportWidget.Sizing.cs | 7 ------- 1 file changed, 7 deletions(-) diff --git a/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs b/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs index 691932b8e..9c2f2a5a8 100644 --- a/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs +++ b/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs @@ -15,7 +15,6 @@ public partial class SceneViewportWidget /// public void SetDefaultSize() { - Log.Info("SetDefaultSize"); ForcedSize = null; ForcedAspectRatio = null; @@ -32,7 +31,6 @@ public void SetDefaultSize() /// public void SetAspectRatio( float aspectRatio ) { - Log.Info("SetAspectRatio"); MinimumSize = Vector2.Zero; MaximumSize = QT_MAX_SIZE; @@ -64,7 +62,6 @@ public void SetResolution( Vector2 resolution ) private void UpdateSizeConstraints() { - Log.Info("UpdateSizeConstraints"); if ( ForcedSize.HasValue ) { var size = ForcedSize.Value; @@ -76,18 +73,15 @@ private void UpdateSizeConstraints() { if ( Parent != null ) { - Log.Info($"CurrentSize: x{Size.x} y{Size.y}"); var contentRect = Parent.ContentRect; var parentSize = new Vector2( contentRect.Width, contentRect.Height ); MaximumSize = parentSize; - Log.Info($"MaximumSize: x{MaximumSize.x} y{MaximumSize.y}"); } else { MaximumSize = new Vector2( QT_MAX_SIZE, QT_MAX_SIZE ); } FixedSize = QT_MAX_SIZE; - Log.Info($"FixedSize: x{FixedSize.x} y{FixedSize.y}"); } else { @@ -125,7 +119,6 @@ protected override Vector2 SizeHint() } var aspectRatio = ForcedAspectRatio.Value; - Log.Info( $"Aspect ratio: {aspectRatio}" ); if ( aspectRatio <= 0 || float.IsNaN( aspectRatio ) || float.IsInfinity( aspectRatio ) ) { From 8aa9716c19a7e63f2a8dfbc5cbff1e3b00a7920c Mon Sep 17 00:00:00 2001 From: Hermann Vincent Date: Sun, 28 Dec 2025 06:39:53 +0100 Subject: [PATCH 3/3] fix format --- .../Code/Scene/SceneView/SceneViewportWidget.Sizing.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs b/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs index 9c2f2a5a8..f2a118f7a 100644 --- a/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs +++ b/game/addons/tools/Code/Scene/SceneView/SceneViewportWidget.Sizing.cs @@ -24,18 +24,18 @@ public void SetDefaultSize() SetSizeMode( SizeMode.CanGrow, SizeMode.CanGrow ); } - + /// /// Set the viewport to a specific aspect ratio /// /// public void SetAspectRatio( float aspectRatio ) { - + MinimumSize = Vector2.Zero; MaximumSize = QT_MAX_SIZE; FixedSize = QT_MAX_SIZE; - + // Don't update if the aspect ratio hasn't changed if ( ForcedAspectRatio.HasValue && ForcedAspectRatio.Value.AlmostEqual( aspectRatio ) && !ForcedSize.HasValue ) { @@ -66,6 +66,7 @@ private void UpdateSizeConstraints() { var size = ForcedSize.Value; + // For fixed resolution, use exact size constraints MaximumSize = size; FixedSize = size; } @@ -85,6 +86,7 @@ private void UpdateSizeConstraints() } else { + // For aspect ratio mode or free, don't lock the size - let it be dynamic MaximumSize = new Vector2( QT_MAX_SIZE, QT_MAX_SIZE ); FixedSize = QT_MAX_SIZE; } @@ -129,10 +131,12 @@ protected override Vector2 SizeHint() Vector2 result; if ( aspectRatio > availableAspect ) { + // Fit to width result = new Vector2( availableSize.x, availableSize.x / aspectRatio ); } else { + // Fit to height result = new Vector2( availableSize.y * aspectRatio, availableSize.y ); }