2017-05-20 04:41:06 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.Containers
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// A container that can scroll to each section inside it.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public class SectionsContainer : Container
|
|
|
|
|
{
|
|
|
|
|
private Drawable expandableHeader, fixedHeader;
|
|
|
|
|
private ScrollContainer scrollContainer;
|
|
|
|
|
|
|
|
|
|
public Drawable ExpandableHeader
|
|
|
|
|
{
|
|
|
|
|
get { return expandableHeader; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == expandableHeader) return;
|
|
|
|
|
|
2017-05-20 05:48:40 +08:00
|
|
|
|
Remove(expandableHeader);
|
2017-05-20 04:41:06 +08:00
|
|
|
|
expandableHeader = value;
|
|
|
|
|
expandableHeader.Depth = float.MinValue;
|
2017-05-20 05:48:40 +08:00
|
|
|
|
Add(expandableHeader);
|
|
|
|
|
updateSectionMargin();
|
2017-05-20 04:41:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Drawable FixedHeader
|
|
|
|
|
{
|
|
|
|
|
get { return fixedHeader; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == fixedHeader) return;
|
|
|
|
|
|
2017-05-20 05:48:40 +08:00
|
|
|
|
Remove(fixedHeader);
|
2017-05-20 04:41:06 +08:00
|
|
|
|
fixedHeader = value;
|
|
|
|
|
fixedHeader.Depth = float.MinValue / 2;
|
2017-05-20 05:48:40 +08:00
|
|
|
|
Add(fixedHeader);
|
|
|
|
|
updateSectionMargin();
|
2017-05-20 04:41:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private List<Drawable> sections = new List<Drawable>();
|
|
|
|
|
public IEnumerable<Drawable> Sections
|
|
|
|
|
{
|
|
|
|
|
get { return sections; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
if (value == sections) return;
|
|
|
|
|
|
|
|
|
|
foreach (var section in sections)
|
|
|
|
|
scrollContainer.Remove(section);
|
|
|
|
|
|
|
|
|
|
sections = value.ToList();
|
2017-05-20 05:48:40 +08:00
|
|
|
|
if (sections.Count == 0) return;
|
|
|
|
|
|
|
|
|
|
originalSectionMargin = sections[0].Margin;
|
|
|
|
|
updateSectionMargin();
|
|
|
|
|
scrollContainer.Add(sections);
|
2017-05-20 04:41:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 05:48:40 +08:00
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2017-05-20 04:41:06 +08:00
|
|
|
|
public SectionsContainer()
|
|
|
|
|
{
|
|
|
|
|
Add(scrollContainer = new ScrollContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
});
|
|
|
|
|
}
|
2017-05-20 05:48:40 +08:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2017-05-20 04:41:06 +08:00
|
|
|
|
}
|
|
|
|
|
}
|