mirror of
https://github.com/SK-la/osu-framework.git
synced 2026-03-15 03:20:30 +00:00
Remove everything related to item labels
This commit is contained in:
@@ -138,9 +138,9 @@ namespace osu.Framework.Tests.Visual
|
||||
},
|
||||
};
|
||||
|
||||
colourModeDropdown.Items = Enum.GetNames(typeof(BlendingMode)).Select(n => new KeyValuePair<string, BlendingMode>(n, (BlendingMode)Enum.Parse(typeof(BlendingMode), n)));
|
||||
colourEquation.Items = Enum.GetNames(typeof(BlendingEquation)).Select(n => new KeyValuePair<string, BlendingEquation>(n, (BlendingEquation)Enum.Parse(typeof(BlendingEquation), n)));
|
||||
alphaEquation.Items = Enum.GetNames(typeof(BlendingEquation)).Select(n => new KeyValuePair<string, BlendingEquation>(n, (BlendingEquation)Enum.Parse(typeof(BlendingEquation), n)));
|
||||
colourModeDropdown.Items = (BlendingMode[])Enum.GetValues(typeof(BlendingMode));
|
||||
colourEquation.Items = (BlendingEquation[])Enum.GetValues(typeof(BlendingEquation));
|
||||
alphaEquation.Items = (BlendingEquation[])Enum.GetValues(typeof(BlendingEquation));
|
||||
|
||||
colourModeDropdown.Current.Value = foregroundContainer.Blending.Mode;
|
||||
colourEquation.Current.Value = foregroundContainer.Blending.RGBEquation;
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace osu.Framework.Tests.Visual
|
||||
}
|
||||
};
|
||||
|
||||
typeDropdown.Items = Enum.GetNames(typeof(CountType)).Select(n => new KeyValuePair<string, CountType>(n, (CountType)Enum.Parse(typeof(CountType), n)));
|
||||
typeDropdown.Items = (CountType[])Enum.GetValues(typeof(CountType));
|
||||
countType.BindTo(typeDropdown.Current);
|
||||
countType.ValueChanged += v => beginStep(lastStep)();
|
||||
|
||||
|
||||
@@ -31,15 +31,14 @@ namespace osu.Framework.Tests.Visual
|
||||
{
|
||||
Width = 150,
|
||||
Position = new Vector2(200, 70),
|
||||
Items = testItems.Select(item => new KeyValuePair<string, string>(item, item)),
|
||||
FallbackText = "Fallback text here"
|
||||
Items = testItems
|
||||
});
|
||||
|
||||
Add(styledDropdownMenu2 = new StyledDropdown
|
||||
{
|
||||
Width = 150,
|
||||
Position = new Vector2(400, 70),
|
||||
Items = testItems.Select(item => new KeyValuePair<string, string>(item, item))
|
||||
Items = testItems
|
||||
});
|
||||
}
|
||||
|
||||
@@ -51,16 +50,16 @@ namespace osu.Framework.Tests.Visual
|
||||
AddStep("click dropdown1", () => toggleDropdownViaClick(styledDropdown));
|
||||
AddAssert("dropdown is open", () => styledDropdown.Menu.State == MenuState.Open);
|
||||
|
||||
AddRepeatStep("add item", () => styledDropdown.AddDropdownItem(@"test " + i, @"test " + i++), items_to_add);
|
||||
AddRepeatStep("add item", () => styledDropdown.AddDropdownItem("test " + i++), items_to_add);
|
||||
AddAssert("item count is correct", () => styledDropdown.Items.Count() == items_to_add * 2);
|
||||
|
||||
AddStep("click item 13", () => styledDropdown.SelectItem(styledDropdown.Menu.Items[13]));
|
||||
|
||||
AddAssert("dropdown1 is closed", () => styledDropdown.Menu.State == MenuState.Closed);
|
||||
AddAssert("item 13 is selected", () => styledDropdown.Current == styledDropdown.Items.ElementAt(13).Value);
|
||||
AddAssert("item 13 is selected", () => styledDropdown.Current == styledDropdown.Items.ElementAt(13));
|
||||
|
||||
AddStep("select item 15", () => styledDropdown.Current.Value = styledDropdown.Items.ElementAt(15).Value);
|
||||
AddAssert("item 15 is selected", () => styledDropdown.Current == styledDropdown.Items.ElementAt(15).Value);
|
||||
AddStep("select item 15", () => styledDropdown.Current.Value = styledDropdown.Items.ElementAt(15));
|
||||
AddAssert("item 15 is selected", () => styledDropdown.Current == styledDropdown.Items.ElementAt(15));
|
||||
|
||||
AddStep("click dropdown1", () => toggleDropdownViaClick(styledDropdown));
|
||||
AddAssert("dropdown1 is open", () => styledDropdown.Menu.State == MenuState.Open);
|
||||
@@ -73,18 +72,10 @@ namespace osu.Framework.Tests.Visual
|
||||
AddStep("select 'invalid'", () => styledDropdown.Current.Value = "invalid");
|
||||
|
||||
AddAssert("'invalid' is selected", () => styledDropdown.Current == "invalid");
|
||||
AddAssert("label shows fallback text", () => styledDropdown.Header.Label == "Fallback text here");
|
||||
AddAssert("label shows 'invalid'", () => styledDropdown.Header.Label == "invalid");
|
||||
|
||||
AddStep("select item 2", () => styledDropdown.Current.Value = styledDropdown.Items.ElementAt(2).Value);
|
||||
AddAssert("item 2 is selected", () => styledDropdown.Current == styledDropdown.Items.ElementAt(2).Value);
|
||||
|
||||
AddStep("select 'invalid'", () => styledDropdownMenu2.Current.Value = "invalid");
|
||||
|
||||
AddAssert("'invalid' is selected", () => styledDropdownMenu2.Current == "invalid");
|
||||
AddAssert("label shows 'invalid'", () => styledDropdownMenu2.Header.Label == "invalid");
|
||||
|
||||
AddStep("select item 5", () => styledDropdownMenu2.Current.Value = styledDropdown.Items.ElementAt(5).Value);
|
||||
AddAssert("item 5 is selected", () => styledDropdownMenu2.Current == styledDropdown.Items.ElementAt(5).Value);
|
||||
AddStep("select item 2", () => styledDropdown.Current.Value = styledDropdown.Items.ElementAt(2));
|
||||
AddAssert("item 2 is selected", () => styledDropdown.Current == styledDropdown.Items.ElementAt(2));
|
||||
}
|
||||
|
||||
private void toggleDropdownViaClick(StyledDropdown dropdown)
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu-framework/master/LICENCE
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using osu.Framework.Graphics;
|
||||
@@ -62,8 +61,7 @@ namespace osu.Framework.Tests.Visual
|
||||
selectionDropdown = new FillDirectionDropdown
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Items = Enum.GetValues(typeof(FlowTestCase)).Cast<FlowTestCase>()
|
||||
.Select(value => new KeyValuePair<string, FlowTestCase>(value.ToString(), value)),
|
||||
Items = (FlowTestCase[])Enum.GetValues(typeof(FlowTestCase)),
|
||||
},
|
||||
new SpriteText { Text = @"Child anchor" },
|
||||
anchorDropdown = new AnchorDropdown
|
||||
@@ -80,7 +78,7 @@ namespace osu.Framework.Tests.Visual
|
||||
Anchor.BottomLeft,
|
||||
Anchor.BottomCentre,
|
||||
Anchor.BottomRight,
|
||||
}.Select(anchor => new KeyValuePair<string, Anchor>(anchor.ToString(), anchor)),
|
||||
},
|
||||
},
|
||||
new SpriteText { Text = @"Child origin" },
|
||||
originDropdown = new AnchorDropdown
|
||||
@@ -97,7 +95,7 @@ namespace osu.Framework.Tests.Visual
|
||||
Anchor.BottomLeft,
|
||||
Anchor.BottomCentre,
|
||||
Anchor.BottomRight,
|
||||
}.Select(anchor => new KeyValuePair<string, Anchor>(anchor.ToString(), anchor)),
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
{
|
||||
protected internal DropdownHeader Header;
|
||||
protected internal DropdownMenu Menu;
|
||||
protected internal DropdownMenuItem<T> FallbackItem;
|
||||
|
||||
/// <summary>
|
||||
/// Creates the header part of the control.
|
||||
@@ -36,21 +35,19 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
protected IEnumerable<DropdownMenuItem<T>> MenuItems => itemMap.Values;
|
||||
|
||||
/// <summary>
|
||||
/// Generate menu items by <see cref="KeyValuePair{TKey, TValue}"/>.
|
||||
/// The <see cref="KeyValuePair{TKey, TValue}.Key"/> part will become <see cref="MenuItem.Text"/>,
|
||||
/// the <see cref="KeyValuePair{TKey, TValue}.Value"/> part will become <see cref="DropdownMenuItem{T}.Value"/>.
|
||||
/// Enumerate all values in the dropdown.
|
||||
/// </summary>
|
||||
public IEnumerable<KeyValuePair<string, T>> Items
|
||||
public IEnumerable<T> Items
|
||||
{
|
||||
get => MenuItems.Select(i => new KeyValuePair<string, T>(i.Text, i.Value));
|
||||
get => MenuItems.Select(i => i.Value);
|
||||
set
|
||||
{
|
||||
ClearItems();
|
||||
if (value == null)
|
||||
return;
|
||||
|
||||
foreach (var entry in value)
|
||||
AddDropdownItem(entry.Key, entry.Value);
|
||||
foreach (var item in value)
|
||||
AddDropdownItem(item);
|
||||
|
||||
if (Current.Value == null || !itemMap.Keys.Contains(Current.Value))
|
||||
Current.Value = itemMap.Keys.FirstOrDefault();
|
||||
@@ -59,19 +56,26 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Generate menu items by <see cref="KeyValuePair{TKey, TValue}"/>.
|
||||
/// The <see cref="KeyValuePair{TKey, TValue}.Key"/> part will become <see cref="MenuItem.Text"/>,
|
||||
/// the <see cref="KeyValuePair{TKey, TValue}.Value"/> part will become <see cref="DropdownMenuItem{T}.Value"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<KeyValuePair<string, T>> Entries => MenuItems.Select(i => new KeyValuePair<string, T>(i.Text, i.Value));
|
||||
|
||||
/// <summary>
|
||||
/// Add a menu item directly.
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display on the menu item.</param>
|
||||
/// <param name="text">Value selected by the menu item.</param>
|
||||
/// <param name="value">Value selected by the menu item.</param>
|
||||
public void AddDropdownItem(string text, T value)
|
||||
protected void AddDropdownItem(string text, T value)
|
||||
{
|
||||
if (itemMap.ContainsKey(value))
|
||||
if(itemMap.ContainsKey(value))
|
||||
throw new ArgumentException($"The item {value} already exists in this {nameof(Dropdown<T>)}.");
|
||||
|
||||
var newItem = new DropdownMenuItem<T>(text, value, () =>
|
||||
{
|
||||
if (!Current.Disabled)
|
||||
if(!Current.Disabled)
|
||||
Current.Value = value;
|
||||
|
||||
Menu.State = MenuState.Closed;
|
||||
@@ -117,19 +121,6 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
private string fallbackText;
|
||||
|
||||
public string FallbackText
|
||||
{
|
||||
get => fallbackText;
|
||||
set
|
||||
{
|
||||
fallbackText = value;
|
||||
if(FallbackItem != null)
|
||||
FallbackItem.Text.Value = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Bindable<T> Current { get; } = new Bindable<T>();
|
||||
|
||||
private DropdownMenuItem<T> selectedItem;
|
||||
@@ -176,13 +167,9 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
if ((SelectedItem == null || !EqualityComparer<T>.Default.Equals(SelectedItem.Value, newSelection))
|
||||
&& newSelection != null)
|
||||
{
|
||||
if (itemMap.TryGetValue(newSelection, out selectedItem))
|
||||
if (!itemMap.TryGetValue(newSelection, out selectedItem))
|
||||
{
|
||||
FallbackItem = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
FallbackItem = selectedItem = new DropdownMenuItem<T>(fallbackText ?? GenerateItemText(newSelection), newSelection);
|
||||
selectedItem = new DropdownMenuItem<T>(GenerateItemText(newSelection), newSelection);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
/// <summary>
|
||||
/// A list of items currently in the tab control in the order they are dispalyed.
|
||||
/// </summary>
|
||||
public IEnumerable<T> Items => TabContainer.TabItems.Select(t => t.Value).Concat(Dropdown.Items.Select(kvp => kvp.Value)).Distinct();
|
||||
public IEnumerable<T> Items => TabContainer.TabItems.Select(t => t.Value).Concat(Dropdown.Items).Distinct();
|
||||
|
||||
public IEnumerable<T> VisibleItems => TabContainer.TabItems.Select(t => t.Value).Distinct();
|
||||
|
||||
@@ -90,7 +90,7 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
Trace.Assert(!Dropdown.Header.RelativeSizeAxes.HasFlag(Axes.X), $@"The {nameof(Dropdown)} implementation's header should have a specific size.");
|
||||
|
||||
// create tab items for already existing items in dropdown (if any).
|
||||
tabMap = Dropdown.Items.ToDictionary(item => item.Value, item => addTab(item.Value, false));
|
||||
tabMap = Dropdown.Items.ToDictionary(item => item, item => addTab(item, false));
|
||||
}
|
||||
else
|
||||
tabMap = new Dictionary<T, TabItem<T>>();
|
||||
@@ -201,7 +201,7 @@ namespace osu.Framework.Graphics.UserInterface
|
||||
|
||||
tabMap[tab.Value] = tab;
|
||||
if (addToDropdown)
|
||||
Dropdown?.AddDropdownItem((tab.Value as Enum)?.GetDescription() ?? tab.Value.ToString(), tab.Value);
|
||||
Dropdown?.AddDropdownItem(tab.Value);
|
||||
TabContainer.Add(tab);
|
||||
}
|
||||
|
||||
|
||||
10
osu.Framework/Testing/Drawables/AssemblyDropdown.cs
Normal file
10
osu.Framework/Testing/Drawables/AssemblyDropdown.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
using System.Reflection;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
|
||||
namespace osu.Framework.Testing.Drawables
|
||||
{
|
||||
class AssemblyDropdown : BasicDropdown<Assembly>
|
||||
{
|
||||
public void AddAssembly(string name, Assembly assembly) => AddDropdownItem(name, assembly);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace osu.Framework.Testing.Drawables.Sections
|
||||
{
|
||||
public class ToolbarAssemblySection : ToolbarSection
|
||||
{
|
||||
private BasicDropdown<Assembly> assemblyDropdown;
|
||||
private AssemblyDropdown assemblyDropdown;
|
||||
|
||||
public ToolbarAssemblySection()
|
||||
{
|
||||
@@ -40,7 +40,7 @@ namespace osu.Framework.Testing.Drawables.Sections
|
||||
Padding = new MarginPadding(5),
|
||||
Text = "Assembly:"
|
||||
},
|
||||
assemblyDropdown = new BasicDropdown<Assembly>
|
||||
assemblyDropdown = new AssemblyDropdown
|
||||
{
|
||||
Width = 250,
|
||||
},
|
||||
@@ -63,8 +63,8 @@ namespace osu.Framework.Testing.Drawables.Sections
|
||||
public void AddAssembly(string name, Assembly assembly)
|
||||
{
|
||||
const string dynamic_assembly_identifier = "dynamic";
|
||||
assemblyDropdown.RemoveDropdownItem(assemblyDropdown.Items.LastOrDefault(i => i.Key.Contains(dynamic_assembly_identifier)).Value);
|
||||
assemblyDropdown.AddDropdownItem(name, assembly);
|
||||
assemblyDropdown.RemoveDropdownItem(assemblyDropdown.Entries.LastOrDefault(i => i.Key.Contains(dynamic_assembly_identifier)).Value);
|
||||
assemblyDropdown.AddAssembly(name, assembly);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user