Scrolling support for SectionsContainer.

This commit is contained in:
Huo Yaoyuan 2017-05-20 05:48:40 +08:00
parent 24a813e907
commit 058c5e18a4

View File

@ -4,8 +4,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text;
using System.Threading.Tasks;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -26,10 +24,11 @@ namespace osu.Game.Graphics.Containers
{ {
if (value == expandableHeader) return; if (value == expandableHeader) return;
scrollContainer.Remove(expandableHeader); Remove(expandableHeader);
expandableHeader = value; expandableHeader = value;
expandableHeader.Depth = float.MinValue; expandableHeader.Depth = float.MinValue;
scrollContainer.Add(expandableHeader); Add(expandableHeader);
updateSectionMargin();
} }
} }
@ -40,10 +39,11 @@ namespace osu.Game.Graphics.Containers
{ {
if (value == fixedHeader) return; if (value == fixedHeader) return;
scrollContainer.Remove(fixedHeader); Remove(fixedHeader);
fixedHeader = value; fixedHeader = value;
fixedHeader.Depth = float.MinValue / 2; fixedHeader.Depth = float.MinValue / 2;
scrollContainer.Add(fixedHeader); Add(fixedHeader);
updateSectionMargin();
} }
} }
@ -59,10 +59,25 @@ namespace osu.Game.Graphics.Containers
scrollContainer.Remove(section); scrollContainer.Remove(section);
sections = value.ToList(); sections = value.ToList();
scrollContainer.Add(value); if (sections.Count == 0) return;
originalSectionMargin = sections[0].Margin;
updateSectionMargin();
scrollContainer.Add(sections);
} }
} }
private MarginPadding originalSectionMargin;
private void updateSectionMargin()
{
if (sections.Count == 0) return;
var newMargin = originalSectionMargin;
newMargin.Top += ExpandableHeader?.Height ?? 0 + FixedHeader?.Height ?? 0;
sections[0].Margin = newMargin;
}
public SectionsContainer() public SectionsContainer()
{ {
Add(scrollContainer = new ScrollContainer Add(scrollContainer = new ScrollContainer
@ -70,5 +85,17 @@ namespace osu.Game.Graphics.Containers
RelativeSizeAxes = Axes.Both RelativeSizeAxes = Axes.Both
}); });
} }
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
if (expandableHeader == null) return;
float position = scrollContainer.Current;
float offset = Math.Max(expandableHeader.Height, position);
expandableHeader.Y = -offset;
fixedHeader.Y = -offset + expandableHeader.Height;
}
} }
} }