osu/osu.Game/Overlays/SearchableList/DisplayStyleControl.cs

85 lines
2.8 KiB
C#
Raw Normal View History

// 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 09:19:50 +00:00
2019-02-21 10:04:31 +00:00
using osu.Framework.Bindables;
2018-11-20 07:51:59 +00:00
using osuTK;
2018-04-13 09:19:50 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
2018-04-13 09:19:50 +00:00
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.SearchableList
{
public class DisplayStyleControl : CompositeDrawable
2018-04-13 09:19:50 +00:00
{
public readonly Bindable<PanelDisplayStyle> DisplayStyle = new Bindable<PanelDisplayStyle>();
public DisplayStyleControl()
{
AutoSizeAxes = Axes.Both;
InternalChild = new FillFlowContainer
2018-04-13 09:19:50 +00:00
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(5f, 0f),
Direction = FillDirection.Horizontal,
Children = new[]
2018-04-13 09:19:50 +00:00
{
new DisplayStyleToggleButton(FontAwesome.Solid.ThLarge, PanelDisplayStyle.Grid, DisplayStyle),
new DisplayStyleToggleButton(FontAwesome.Solid.ListUl, PanelDisplayStyle.List, DisplayStyle),
2018-04-13 09:19:50 +00:00
},
};
DisplayStyle.Value = PanelDisplayStyle.Grid;
}
private class DisplayStyleToggleButton : OsuClickableContainer
{
private readonly SpriteIcon icon;
private readonly PanelDisplayStyle style;
private readonly Bindable<PanelDisplayStyle> bindable;
public DisplayStyleToggleButton(IconUsage icon, PanelDisplayStyle style, Bindable<PanelDisplayStyle> bindable)
2018-04-13 09:19:50 +00:00
{
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 09:56:34 +00:00
Bindable_ValueChanged(new ValueChangedEvent<PanelDisplayStyle>(bindable.Value, bindable.Value));
2018-04-13 09:19:50 +00:00
Action = () => bindable.Value = this.style;
}
2019-02-21 09:56:34 +00:00
private void Bindable_ValueChanged(ValueChangedEvent<PanelDisplayStyle> e)
2018-04-13 09:19:50 +00:00
{
2019-02-21 09:56:34 +00:00
icon.FadeTo(e.NewValue == style ? 1.0f : 0.5f, 100);
2018-04-13 09:19:50 +00:00
}
protected override void Dispose(bool isDisposing)
{
2020-05-04 09:20:20 +00:00
base.Dispose(isDisposing);
2018-04-13 09:19:50 +00:00
bindable.ValueChanged -= Bindable_ValueChanged;
}
}
}
public enum PanelDisplayStyle
{
Grid,
List,
}
}