Skip to content

Commit

Permalink
save original window size during Populate operation
Browse files Browse the repository at this point in the history
  • Loading branch information
CzBuCHi committed Jul 27, 2024
1 parent f93b309 commit 616eb80
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions CarInspectorResizer/Behaviors/CarInspectorAutoHeightBehavior.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public sealed class CarInspectorAutoHeightBehavior : MonoBehaviour {
private readonly Dictionary<string, float> _TabExpansions = new();
private readonly Dictionary<AutoEngineerMode, float> _OrdersExpansions = new();

private static Vector2? _OriginalWindowSize;

public float MinHeight { get; set; } = 330;

public void Awake() {
Expand All @@ -38,6 +40,8 @@ internal void Populate(Car car) {

_Car = car;

_OriginalWindowSize ??= _Window.GetContentSize();

foreach (var observer in _Observers) {
observer.Dispose();
}
Expand All @@ -64,15 +68,15 @@ public void ExpandOrders(AutoEngineerMode mode, float height) {
}

public void UpdateWindowHeight() {
if (_Car == null) {
if (_Car == null || _OriginalWindowSize == null) {
return;
}

var persistence = new AutoEngineerPersistence(_Car.KeyValueObject!);
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);
Expand All @@ -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)));
}

}

0 comments on commit 616eb80

Please sign in to comment.