From 058c5e18a424fcdbc5b29741ac198c1cfc17cfb3 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sat, 20 May 2017 05:48:40 +0800 Subject: [PATCH] Scrolling support for SectionsContainer. --- .../Graphics/Containers/SectionsContainer.cs | 41 +++++++++++++++---- 1 file changed, 34 insertions(+), 7 deletions(-) diff --git a/osu.Game/Graphics/Containers/SectionsContainer.cs b/osu.Game/Graphics/Containers/SectionsContainer.cs index 9c2485c49c..3557a09622 100644 --- a/osu.Game/Graphics/Containers/SectionsContainer.cs +++ b/osu.Game/Graphics/Containers/SectionsContainer.cs @@ -4,8 +4,6 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -26,10 +24,11 @@ namespace osu.Game.Graphics.Containers { if (value == expandableHeader) return; - scrollContainer.Remove(expandableHeader); + Remove(expandableHeader); expandableHeader = value; expandableHeader.Depth = float.MinValue; - scrollContainer.Add(expandableHeader); + Add(expandableHeader); + updateSectionMargin(); } } @@ -40,10 +39,11 @@ namespace osu.Game.Graphics.Containers { if (value == fixedHeader) return; - scrollContainer.Remove(fixedHeader); + Remove(fixedHeader); fixedHeader = value; fixedHeader.Depth = float.MinValue / 2; - scrollContainer.Add(fixedHeader); + Add(fixedHeader); + updateSectionMargin(); } } @@ -59,10 +59,25 @@ namespace osu.Game.Graphics.Containers scrollContainer.Remove(section); 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() { Add(scrollContainer = new ScrollContainer @@ -70,5 +85,17 @@ namespace osu.Game.Graphics.Containers 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; + } } }