1
0
Fork 0
mirror of https://github.com/Ellpeck/MLEM.git synced 2024-12-26 02:09:24 +01:00

Fixed auto-sized elements sometimes updating their location based on outdated parent positions

This commit is contained in:
Ell 2024-06-09 20:22:24 +02:00
parent d7cda0d39b
commit 6a5e9a77ea
2 changed files with 12 additions and 9 deletions

View file

@ -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

View file

@ -683,20 +683,22 @@ namespace MLEM.Ui.Elements {
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:
@ -822,9 +824,9 @@ namespace MLEM.Ui.Elements {
}
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