2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-11-06 09:14:46 +00:00
|
|
|
namespace osu.Game.Screens.Edit.Components.RadioButtons
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
public class RadioButtonCollection : CompositeDrawable
|
|
|
|
{
|
|
|
|
private IReadOnlyList<RadioButton> items;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
public IReadOnlyList<RadioButton> Items
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
get => items;
|
2018-04-13 09:19:50 +00:00
|
|
|
set
|
|
|
|
{
|
|
|
|
if (ReferenceEquals(items, value))
|
|
|
|
return;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
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;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-04-13 09:19:50 +00:00
|
|
|
private void addButton(RadioButton button)
|
|
|
|
{
|
2019-02-22 08:51:39 +00:00
|
|
|
button.Selected.ValueChanged += selected =>
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
2019-02-22 08:51:39 +00:00
|
|
|
if (selected.NewValue)
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
currentlySelected?.Deselect();
|
|
|
|
currentlySelected = button;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
currentlySelected = null;
|
|
|
|
};
|
|
|
|
|
|
|
|
buttonContainer.Add(new DrawableRadioButton(button));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|