mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 14:12:56 +08:00
Fix margin and offset calculating.
This commit is contained in:
parent
ecc222c043
commit
da47b0a260
@ -29,9 +29,10 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (expandableHeader != null)
|
if (expandableHeader != null)
|
||||||
Remove(expandableHeader);
|
Remove(expandableHeader);
|
||||||
expandableHeader = value;
|
expandableHeader = value;
|
||||||
|
if (value == null) return;
|
||||||
|
|
||||||
expandableHeader.Depth = float.MinValue;
|
expandableHeader.Depth = float.MinValue;
|
||||||
Add(expandableHeader);
|
Add(expandableHeader);
|
||||||
updateSectionMargin();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,9 +46,10 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (fixedHeader != null)
|
if (fixedHeader != null)
|
||||||
Remove(fixedHeader);
|
Remove(fixedHeader);
|
||||||
fixedHeader = value;
|
fixedHeader = value;
|
||||||
|
if (value == null) return;
|
||||||
|
|
||||||
fixedHeader.Depth = float.MinValue / 2;
|
fixedHeader.Depth = float.MinValue / 2;
|
||||||
Add(fixedHeader);
|
Add(fixedHeader);
|
||||||
updateSectionMargin();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,19 +78,19 @@ namespace osu.Game.Graphics.Containers
|
|||||||
if (sections.Count == 0) return;
|
if (sections.Count == 0) return;
|
||||||
|
|
||||||
originalSectionMargin = sections[0].Margin;
|
originalSectionMargin = sections[0].Margin;
|
||||||
updateSectionMargin();
|
|
||||||
sectionsContainer.Add(sections);
|
sectionsContainer.Add(sections);
|
||||||
SelectedSection.Value = sections[0];
|
SelectedSection.Value = sections[0];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float headerHeight;
|
||||||
private MarginPadding originalSectionMargin;
|
private MarginPadding originalSectionMargin;
|
||||||
private void updateSectionMargin()
|
private void updateSectionMargin()
|
||||||
{
|
{
|
||||||
if (sections.Count == 0) return;
|
if (sections.Count == 0) return;
|
||||||
|
|
||||||
var newMargin = originalSectionMargin;
|
var newMargin = originalSectionMargin;
|
||||||
newMargin.Top += ExpandableHeader?.Height ?? 0 + FixedHeader?.Height ?? 0;
|
newMargin.Top += headerHeight;
|
||||||
|
|
||||||
sections[0].Margin = newMargin;
|
sections[0].Margin = newMargin;
|
||||||
}
|
}
|
||||||
@ -102,23 +104,33 @@ namespace osu.Game.Graphics.Containers
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
float lastKnownScroll;
|
float lastKnownScroll = float.NaN;
|
||||||
protected override void UpdateAfterChildren()
|
protected override void UpdateAfterChildren()
|
||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
|
|
||||||
|
float height = (ExpandableHeader?.Height ?? 0) + (FixedHeader?.Height ?? 0);
|
||||||
|
if (height != headerHeight)
|
||||||
|
{
|
||||||
|
headerHeight = height;
|
||||||
|
updateSectionMargin();
|
||||||
|
}
|
||||||
|
|
||||||
if (expandableHeader == null) return;
|
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;
|
float currentScroll = scrollContainer.Current;
|
||||||
if (currentScroll != lastKnownScroll)
|
if (currentScroll != lastKnownScroll)
|
||||||
{
|
{
|
||||||
lastKnownScroll = currentScroll;
|
lastKnownScroll = currentScroll;
|
||||||
|
|
||||||
|
if (expandableHeader != null)
|
||||||
|
{
|
||||||
|
float offset = Math.Min(expandableHeader.Height, currentScroll);
|
||||||
|
|
||||||
|
expandableHeader.Y = -offset;
|
||||||
|
fixedHeader.Y = -offset + expandableHeader.Height;
|
||||||
|
}
|
||||||
|
|
||||||
Drawable bestMatch = null;
|
Drawable bestMatch = null;
|
||||||
float minDiff = float.MaxValue;
|
float minDiff = float.MaxValue;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user