2018-04-13 17:19:50 +08:00
|
|
|
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
2018-11-06 17:14:46 +08:00
|
|
|
namespace osu.Game.Screens.Edit.Components.RadioButtons
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
public class RadioButtonCollection : CompositeDrawable
|
|
|
|
{
|
|
|
|
private IReadOnlyList<RadioButton> items;
|
|
|
|
public IReadOnlyList<RadioButton> Items
|
|
|
|
{
|
|
|
|
get { return items; }
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(items, value))
|
|
|
|
return;
|
|
|
|
items = value;
|
|
|
|
|
|
|
|
buttonContainer.Clear();
|
|
|
|
items.ForEach(addButton);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private readonly FlowContainer<DrawableRadioButton> buttonContainer;
|
|
|
|
|
|
|
|
public RadioButtonCollection()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
InternalChild = buttonContainer = new FillFlowContainer<DrawableRadioButton>
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
Spacing = new Vector2(0, 5)
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private RadioButton currentlySelected;
|
|
|
|
private void addButton(RadioButton button)
|
|
|
|
{
|
|
|
|
button.Selected.ValueChanged += v =>
|
|
|
|
{
|
|
|
|
if (v)
|
|
|
|
{
|
|
|
|
currentlySelected?.Deselect();
|
|
|
|
currentlySelected = button;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
currentlySelected = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
buttonContainer.Add(new DrawableRadioButton(button));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|