Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow AsyncLoadContainer's content to be a Drawable. #620

Merged
merged 4 commits into from
Apr 2, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions osu.Framework.VisualTests/Tests/TestCaseOnlineTextures.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public override void Reset()
Size = new Vector2(128),
Children = new Drawable[]
{
new DelayedLoadContainer(new Container
new DelayedLoadWrapper(new Container
{
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d =>
Expand All @@ -73,7 +73,7 @@ public override void Reset()
}
});

var childrenWithAvatarsLoaded = flow.Children.Where(c => c.Children.OfType<DelayedLoadContainer>().First().Children.FirstOrDefault()?.IsLoaded ?? false);
var childrenWithAvatarsLoaded = flow.Children.Where(c => c.Children.OfType<DelayedLoadWrapper>().First().Children.FirstOrDefault()?.IsLoaded ?? false);

AddWaitStep(10);
AddStep("scroll down", () => scroll.ScrollToEnd());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,31 @@
namespace osu.Framework.Graphics.Containers
{
/// <summary>
/// A container which asynchronously loads its children.
/// A container which asynchronously loads specified content.
/// </summary>
public class AsyncLoadContainer : Container
public class AsyncLoadWrapper : Container
{
/// <param name="content">The content which should be asynchronously loaded. Note that the <see cref="Drawable.RelativeSizeAxes"/> and <see cref="Container{T}.AutoSizeAxes"/> of this container
/// will be transferred as the default for this <see cref="AsyncLoadContainer"/>.</param>
public AsyncLoadContainer(Container content)
/// will be transferred as the default for this <see cref="AsyncLoadWrapper"/>.</param>
public AsyncLoadWrapper(Drawable content)
{
if (content == null)
throw new ArgumentNullException(nameof(content), $@"{nameof(AsyncLoadContainer)} required non-null {nameof(content)}.");
throw new ArgumentNullException(nameof(content), $@"{nameof(AsyncLoadWrapper)} required non-null {nameof(content)}.");

this.content = content;

RelativeSizeAxes = content.RelativeSizeAxes;
AutoSizeAxes = content.AutoSizeAxes;
AutoSizeAxes = (content as IContainer)?.AutoSizeAxes ?? AutoSizeAxes;
}

private readonly Container content;
protected sealed override Container<Drawable> Content => base.Content;

public override void Add(Drawable drawable)
{
throw new InvalidOperationException($@"{nameof(AsyncLoadWrapper)} doesn't support manually adding children. Please specify loadable conetnt in the constructor.");
}

private readonly Drawable content;

protected virtual bool ShouldLoadContent => true;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
namespace osu.Framework.Graphics.Containers
{
/// <summary>
/// A container which delays the loading of children until we have been on-screen for a specified duration.
/// A wrapper which delays the loading of children until we have been on-screen for a specified duration.
/// In order to benefit from delayed load, we must be inside a <see cref="ScrollContainer"/>.
/// </summary>
public class DelayedLoadContainer : AsyncLoadContainer
public class DelayedLoadWrapper : AsyncLoadWrapper
{
public DelayedLoadContainer(Container content)
public DelayedLoadWrapper(Drawable content)
: base(content)
{
}
Expand Down
2 changes: 2 additions & 0 deletions osu.Framework/Graphics/Containers/IContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public interface IContainer : IDrawable
void InvalidateFromChild(Invalidation invalidation);

void Clear(bool dispose = true);

Axes AutoSizeAxes { get; set; }
}

public interface IContainerEnumerable<out T> : IContainer
Expand Down
2 changes: 1 addition & 1 deletion osu.Framework/Graphics/Containers/ScrollContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace osu.Framework.Graphics.Containers
{
public class ScrollContainer : Container, DelayedLoadContainer.IOnScreenOptimisingContainer
public class ScrollContainer : Container, DelayedLoadWrapper.IOnScreenOptimisingContainer
{
/// <summary>
/// Determines whether the scroll dragger appears on the left side. If not, then it always appears on the right side.
Expand Down
4 changes: 2 additions & 2 deletions osu.Framework/osu.Framework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@
<Compile Include="Extensions\ExtensionMethods.cs" />
<Compile Include="Extensions\IEnumerableExtensions\EnumerableExtensions.cs" />
<Compile Include="Extensions\TypeExtensions\TypeExtensions.cs" />
<Compile Include="Graphics\Containers\AsyncLoadContainer.cs" />
<Compile Include="Graphics\Containers\DelayedLoadContainer.cs" />
<Compile Include="Graphics\Containers\AsyncLoadWrapper.cs" />
<Compile Include="Graphics\Containers\DelayedLoadWrapper.cs" />
<Compile Include="Graphics\Containers\FillFlowContainer.cs" />
<Compile Include="Graphics\Containers\TabbableContainer.cs" />
<Compile Include="Graphics\UserInterface\BasicCheckbox.cs" />
Expand Down