1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 12:07:23 +08:00

Fix margin and offset calculating.

This commit is contained in:
Huo Yaoyuan 2017-05-21 02:11:55 +08:00
parent ecc222c043
commit da47b0a260

View File

@ -29,9 +29,10 @@ namespace osu.Game.Graphics.Containers
if (expandableHeader != null)
Remove(expandableHeader);
expandableHeader = value;
if (value == null) return;
expandableHeader.Depth = float.MinValue;
Add(expandableHeader);
updateSectionMargin();
}
}
@ -45,9 +46,10 @@ namespace osu.Game.Graphics.Containers
if (fixedHeader != null)
Remove(fixedHeader);
fixedHeader = value;
if (value == null) return;
fixedHeader.Depth = float.MinValue / 2;
Add(fixedHeader);
updateSectionMargin();
}
}
@ -76,19 +78,19 @@ namespace osu.Game.Graphics.Containers
if (sections.Count == 0) return;
originalSectionMargin = sections[0].Margin;
updateSectionMargin();
sectionsContainer.Add(sections);
SelectedSection.Value = sections[0];
}
}
float headerHeight;
private MarginPadding originalSectionMargin;
private void updateSectionMargin()
{
if (sections.Count == 0) return;
var newMargin = originalSectionMargin;
newMargin.Top += ExpandableHeader?.Height ?? 0 + FixedHeader?.Height ?? 0;
newMargin.Top += headerHeight;
sections[0].Margin = newMargin;
}
@ -102,23 +104,33 @@ namespace osu.Game.Graphics.Containers
});
}
float lastKnownScroll;
float lastKnownScroll = float.NaN;
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
float height = (ExpandableHeader?.Height ?? 0) + (FixedHeader?.Height ?? 0);
if (height != headerHeight)
{
headerHeight = height;
updateSectionMargin();
}
if (expandableHeader == null) return;
float position = scrollContainer.Current;
float offset = Math.Max(expandableHeader.Height, position);
expandableHeader.Y = -offset;
fixedHeader.Y = -offset + expandableHeader.Height;
float currentScroll = scrollContainer.Current;
if (currentScroll != lastKnownScroll)
{
lastKnownScroll = currentScroll;
if (expandableHeader != null)
{
float offset = Math.Min(expandableHeader.Height, currentScroll);
expandableHeader.Y = -offset;
fixedHeader.Y = -offset + expandableHeader.Height;
}
Drawable bestMatch = null;
float minDiff = float.MaxValue;