mirror of
https://github.com/osukey/osukey.git
synced 2025-07-01 16:29:58 +09:00
Add footer support.
This commit is contained in:
@ -15,7 +15,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class SectionsContainer : Container
|
public class SectionsContainer : Container
|
||||||
{
|
{
|
||||||
private Drawable expandableHeader, fixedHeader;
|
private Drawable expandableHeader, fixedHeader, footer;
|
||||||
public readonly ScrollContainer ScrollContainer;
|
public readonly ScrollContainer ScrollContainer;
|
||||||
private readonly Container<Drawable> sectionsContainer;
|
private readonly Container<Drawable> sectionsContainer;
|
||||||
|
|
||||||
@ -31,7 +31,6 @@ namespace osu.Game.Graphics.Containers
|
|||||||
expandableHeader = value;
|
expandableHeader = value;
|
||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
|
|
||||||
expandableHeader.Depth = float.MinValue;
|
|
||||||
Add(expandableHeader);
|
Add(expandableHeader);
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = float.NaN;
|
||||||
}
|
}
|
||||||
@ -49,12 +48,30 @@ namespace osu.Game.Graphics.Containers
|
|||||||
fixedHeader = value;
|
fixedHeader = value;
|
||||||
if (value == null) return;
|
if (value == null) return;
|
||||||
|
|
||||||
fixedHeader.Depth = float.MinValue / 2;
|
|
||||||
Add(fixedHeader);
|
Add(fixedHeader);
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = float.NaN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Drawable Footer
|
||||||
|
{
|
||||||
|
get { return footer; }
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == footer) return;
|
||||||
|
|
||||||
|
if (footer != null)
|
||||||
|
ScrollContainer.Remove(footer);
|
||||||
|
footer = value;
|
||||||
|
if (value == null) return;
|
||||||
|
|
||||||
|
footer.Anchor |= Anchor.y2;
|
||||||
|
footer.Origin |= Anchor.y2;
|
||||||
|
ScrollContainer.Add(footer);
|
||||||
|
lastKnownScroll = float.NaN;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public Bindable<Drawable> SelectedSection { get; } = new Bindable<Drawable>();
|
public Bindable<Drawable> SelectedSection { get; } = new Bindable<Drawable>();
|
||||||
|
|
||||||
protected virtual Container<Drawable> CreateScrollContentContainer()
|
protected virtual Container<Drawable> CreateScrollContentContainer()
|
||||||
@ -78,23 +95,23 @@ namespace osu.Game.Graphics.Containers
|
|||||||
sections = value.ToList();
|
sections = value.ToList();
|
||||||
if (sections.Count == 0) return;
|
if (sections.Count == 0) return;
|
||||||
|
|
||||||
originalSectionMargin = sections[0].Margin;
|
|
||||||
sectionsContainer.Add(sections);
|
sectionsContainer.Add(sections);
|
||||||
SelectedSection.Value = sections[0];
|
SelectedSection.Value = sections[0];
|
||||||
lastKnownScroll = float.NaN;
|
lastKnownScroll = float.NaN;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
float headerHeight;
|
private float headerHeight, footerHeight;
|
||||||
private MarginPadding originalSectionMargin;
|
private MarginPadding originalSectionsMargin;
|
||||||
private void updateSectionMargin()
|
private void updateSectionsMargin()
|
||||||
{
|
{
|
||||||
if (sections.Count == 0) return;
|
if (sections.Count == 0) return;
|
||||||
|
|
||||||
var newMargin = originalSectionMargin;
|
var newMargin = originalSectionsMargin;
|
||||||
newMargin.Top += headerHeight;
|
newMargin.Top += headerHeight;
|
||||||
|
newMargin.Bottom += footerHeight;
|
||||||
|
|
||||||
sections[0].Margin = newMargin;
|
sectionsContainer.Margin = newMargin;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SectionsContainer()
|
public SectionsContainer()
|
||||||
@ -105,6 +122,7 @@ namespace osu.Game.Graphics.Containers
|
|||||||
Masking = false,
|
Masking = false,
|
||||||
Children = new Drawable[] { sectionsContainer = CreateScrollContentContainer() }
|
Children = new Drawable[] { sectionsContainer = CreateScrollContentContainer() }
|
||||||
});
|
});
|
||||||
|
originalSectionsMargin = sectionsContainer.Margin;
|
||||||
}
|
}
|
||||||
|
|
||||||
float lastKnownScroll;
|
float lastKnownScroll;
|
||||||
@ -112,11 +130,13 @@ namespace osu.Game.Graphics.Containers
|
|||||||
{
|
{
|
||||||
base.UpdateAfterChildren();
|
base.UpdateAfterChildren();
|
||||||
|
|
||||||
float height = (ExpandableHeader?.Height ?? 0) + (FixedHeader?.Height ?? 0);
|
float headerHeight = (ExpandableHeader?.Height ?? 0) + (FixedHeader?.Height ?? 0);
|
||||||
if (height != headerHeight)
|
float footerHeight = Footer?.Height ?? 0;
|
||||||
|
if (headerHeight != this.headerHeight || footerHeight != this.footerHeight)
|
||||||
{
|
{
|
||||||
headerHeight = height;
|
this.headerHeight = headerHeight;
|
||||||
updateSectionMargin();
|
this.footerHeight = footerHeight;
|
||||||
|
updateSectionsMargin();
|
||||||
}
|
}
|
||||||
|
|
||||||
float currentScroll = ScrollContainer.Current;
|
float currentScroll = ScrollContainer.Current;
|
||||||
|
Reference in New Issue
Block a user