Skip to content

Commit

Permalink
Fixed auto-sized elements sometimes updating their location based on …
Browse files Browse the repository at this point in the history
…outdated parent positions
  • Loading branch information
Ellpeck committed Jun 9, 2024
1 parent d7cda0d commit 6a5e9a7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Improvements
Fixes
- Fixed hidden scroll bars inhibiting scrolling on their parent panel
- Fixed scroll bars doing unnecessary calculations when hidden
- Fixed auto-sized elements sometimes updating their location based on outdated parent positions

## 6.3.1

Expand Down
20 changes: 11 additions & 9 deletions MLEM.Ui/Elements/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -683,20 +683,22 @@ public virtual void ForceUpdateArea() {
return;
this.stopwatch.Restart();

var parentArea = this.ParentArea;
var parentCenterX = parentArea.X + parentArea.Width / 2;
var parentCenterY = parentArea.Y + parentArea.Height / 2;
var actualSize = this.CalcActualSize(parentArea);

var recursion = 0;
UpdateDisplayArea(actualSize);
UpdateDisplayArea();

this.stopwatch.Stop();
this.System.Metrics.ForceAreaUpdateTime += this.stopwatch.Elapsed;
this.System.Metrics.ForceAreaUpdates++;

void UpdateDisplayArea(Vector2 newSize) {
void UpdateDisplayArea(Vector2? overrideSize = null) {
var parentArea = this.ParentArea;
var parentCenterX = parentArea.X + parentArea.Width / 2;
var parentCenterY = parentArea.Y + parentArea.Height / 2;

var intendedSize = this.CalcActualSize(parentArea);
var newSize = overrideSize ?? intendedSize;
var pos = new Vector2();

switch (this.anchor) {
case Anchor.TopLeft:
case Anchor.AutoLeft:
Expand Down Expand Up @@ -822,9 +824,9 @@ void UpdateDisplayArea(Vector2 newSize) {
}

if (this.TreatSizeAsMinimum) {
autoSize = Vector2.Max(autoSize, actualSize);
autoSize = Vector2.Max(autoSize, intendedSize);
} else if (this.TreatSizeAsMaximum) {
autoSize = Vector2.Min(autoSize, actualSize);
autoSize = Vector2.Min(autoSize, intendedSize);
}

// we want to leave some leeway to prevent float rounding causing an infinite loop
Expand Down

0 comments on commit 6a5e9a7

Please sign in to comment.