mirror of
https://github.com/ppy/osu
synced 2025-01-09 07:39:46 +00:00
Use existing GetStateFromSelection
helper function
This commit is contained in:
parent
f3b305bbe6
commit
01984de9c7
@ -108,17 +108,6 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a selection target and a function of truth, retrieve the correct ternary state for display.
|
||||
/// </summary>
|
||||
protected TernaryState GetStateFromSelection<T>(IEnumerable<T> selection, Func<T, bool> func)
|
||||
{
|
||||
if (selection.Any(func))
|
||||
return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate;
|
||||
|
||||
return TernaryState.False;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Ternary state changes
|
||||
|
@ -268,6 +268,17 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
DeleteSelected();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Given a selection target and a function of truth, retrieve the correct ternary state for display.
|
||||
/// </summary>
|
||||
protected static TernaryState GetStateFromSelection<TObject>(IEnumerable<TObject> selection, Func<TObject, bool> func)
|
||||
{
|
||||
if (selection.Any(func))
|
||||
return selection.All(func) ? TernaryState.True : TernaryState.Indeterminate;
|
||||
|
||||
return TernaryState.False;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called whenever the deletion of items has been requested.
|
||||
/// </summary>
|
||||
|
@ -53,21 +53,9 @@ namespace osu.Game.Skinning.Editor
|
||||
|
||||
return displayableAnchors.Select(a =>
|
||||
{
|
||||
var countExisting = selection.Count(b => ((Drawable)b.Item).Anchor == a);
|
||||
var countTotal = selection.Count();
|
||||
|
||||
TernaryState state;
|
||||
|
||||
if (countExisting == countTotal)
|
||||
state = TernaryState.True;
|
||||
else if (countExisting > 0)
|
||||
state = TernaryState.Indeterminate;
|
||||
else
|
||||
state = TernaryState.False;
|
||||
|
||||
return new AnchorMenuItem(a, selection, _ => applyAnchor(a))
|
||||
{
|
||||
State = { Value = state }
|
||||
State = { Value = GetStateFromSelection(selection, c => ((Drawable)c.Item).Anchor == a) }
|
||||
};
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user