From 616eb80a4a8c5d63f25a1ed8d3070e263a5da0e2 Mon Sep 17 00:00:00 2001 From: Marek Buchar Date: Sun, 28 Jul 2024 00:44:43 +0200 Subject: [PATCH] save original window size during Populate operation --- .../Behaviors/CarInspectorAutoHeightBehavior.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/CarInspectorResizer/Behaviors/CarInspectorAutoHeightBehavior.cs b/CarInspectorResizer/Behaviors/CarInspectorAutoHeightBehavior.cs index 9d3cabd..31573ff 100644 --- a/CarInspectorResizer/Behaviors/CarInspectorAutoHeightBehavior.cs +++ b/CarInspectorResizer/Behaviors/CarInspectorAutoHeightBehavior.cs @@ -24,6 +24,8 @@ public sealed class CarInspectorAutoHeightBehavior : MonoBehaviour { private readonly Dictionary _TabExpansions = new(); private readonly Dictionary _OrdersExpansions = new(); + private static Vector2? _OriginalWindowSize; + public float MinHeight { get; set; } = 330; public void Awake() { @@ -38,6 +40,8 @@ internal void Populate(Car car) { _Car = car; + _OriginalWindowSize ??= _Window.GetContentSize(); + foreach (var observer in _Observers) { observer.Dispose(); } @@ -64,7 +68,7 @@ public void ExpandOrders(AutoEngineerMode mode, float height) { } public void UpdateWindowHeight() { - if (_Car == null) { + if (_Car == null || _OriginalWindowSize == null) { return; } @@ -72,7 +76,7 @@ public void UpdateWindowHeight() { var helper = new AutoEngineerOrdersHelper(_Car, persistence); var mode = helper.Mode(); - var height = MinHeight + _ExpandAlways; + var height = _OriginalWindowSize.Value.y + _ExpandAlways; if (SelectedTabState.Value != null) { _TabExpansions.TryGetValue(SelectedTabState.Value, out var tabExpansion); @@ -88,12 +92,11 @@ public void UpdateWindowHeight() { } if (persistence.ContextualOrders!.Count > 0) { - height += 40; + height += 30; } } - var size = _Window.GetContentSize(); - _Window.SetContentSize(new Vector2(size.x - 2, Mathf.Max(MinHeight, height))); + _Window.SetContentSize(new Vector2(_OriginalWindowSize.Value.x, Mathf.Max(MinHeight, height))); } } \ No newline at end of file