2019-01-24 16:43:03 +08:00
|
|
|
|
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
|
|
|
// See the LICENCE file in the repository root for full licence text.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.SearchableList
|
|
|
|
|
{
|
|
|
|
|
public class DisplayStyleControl<T> : Container
|
|
|
|
|
{
|
|
|
|
|
public readonly SlimEnumDropdown<T> Dropdown;
|
|
|
|
|
public readonly Bindable<PanelDisplayStyle> DisplayStyle = new Bindable<PanelDisplayStyle>();
|
|
|
|
|
|
|
|
|
|
public DisplayStyleControl()
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Spacing = new Vector2(10f, 0f),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Spacing = new Vector2(5f, 0f),
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new DisplayStyleToggleButton(FontAwesome.fa_th_large, PanelDisplayStyle.Grid, DisplayStyle),
|
|
|
|
|
new DisplayStyleToggleButton(FontAwesome.fa_list_ul, PanelDisplayStyle.List, DisplayStyle),
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
Dropdown = new SlimEnumDropdown<T>
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.None,
|
|
|
|
|
Width = 160f,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
DisplayStyle.Value = PanelDisplayStyle.Grid;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private class DisplayStyleToggleButton : OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly SpriteIcon icon;
|
|
|
|
|
private readonly PanelDisplayStyle style;
|
|
|
|
|
private readonly Bindable<PanelDisplayStyle> bindable;
|
|
|
|
|
|
|
|
|
|
public DisplayStyleToggleButton(FontAwesome icon, PanelDisplayStyle style, Bindable<PanelDisplayStyle> bindable)
|
|
|
|
|
{
|
|
|
|
|
this.bindable = bindable;
|
|
|
|
|
this.style = style;
|
|
|
|
|
Size = new Vector2(25f);
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
this.icon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Icon = icon,
|
|
|
|
|
Size = new Vector2(18),
|
|
|
|
|
Alpha = 0.5f,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
bindable.ValueChanged += Bindable_ValueChanged;
|
2019-02-21 17:56:34 +08:00
|
|
|
|
Bindable_ValueChanged(new ValueChangedEvent<PanelDisplayStyle>(bindable.Value, bindable.Value));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Action = () => bindable.Value = this.style;
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
|
private void Bindable_ValueChanged(ValueChangedEvent<PanelDisplayStyle> e)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2019-02-21 17:56:34 +08:00
|
|
|
|
icon.FadeTo(e.NewValue == style ? 1.0f : 0.5f, 100);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
bindable.ValueChanged -= Bindable_ValueChanged;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum PanelDisplayStyle
|
|
|
|
|
{
|
|
|
|
|
Grid,
|
|
|
|
|
List,
|
|
|
|
|
}
|
|
|
|
|
}
|